This is very confusing. I'm working on a simple app for a class and followed the examples but the damn Bean property just won't set. Code follows:
Bean code:
import java.io.Serializable;
import javax.faces.bean.*;
import javax.faces.event.*;
#ManagedBean(name="dist") // or #Named("dist")
#SessionScoped
public class DistanceConvertBean implements Serializable{
private static final double MILESTOKM = 1.609344;
private static final double KMTOMILES = 0.62137;
private double input;
private String convertTo;
private String outputString;
Eclipse generated getters and setters
Index.xhtml code:
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html">
<h:body>
<h:panelGrid columns="3">
<h:outputText value="Distance:"/>
<h:inputText id="inDist" value="#{dist.input}" required="true">
<f:convertNumber maxFractionDigits="2"/>
<f:validateDoubleRange maximum="10000"/>
</h:inputText>
<h:message for="inDist"/>
<h:outputText value="Convert To:"/>
<h:form>
<h:selectOneRadio value="#{dist.convertTo}" required="true">
<f:selectItem itemValue="km" itemLabel="Kilometer"/>
<f:selectItem itemValue="miles" itemLabel="Miles"/>
</h:selectOneRadio>
</h:form>
<h:form>
<h:commandButton value="Convert" action="blah"/>
</h:form>
</h:panelGrid>
</h:body>
</html>
Blah.xhtml code:
<h:body>
<h:outputText value="#{dist.input}"/>
</h:body>
So I put in 10 in the InputText field in Index.xhtml and press the command button to go to blah.xhtml. The value in blah is still 0.0.
I'm using Tomcat 7 and Eclipse Heilos and created a dynamic web project. I do have all the JSF jars in WEB-INF/libs. I don't understand why the bean properties are not being set. This look exactly like those newbie codes you find in COREJSF examples. Web.xml is using 2.5 for servlet so I shouldn't need a face-config.xml.
Your <h:inputText> is not inside a <h:form> element.
Put the <h:inputText> inside the same <h:form> as the command button:
<h:form>
<h:inputText id="inDist" value="#{dist.input}" required="true">
<f:convertNumber maxFractionDigits="2"/>
<f:validateDoubleRange maximum="10000"/>
</h:inputText>
<h:message for="inDist"/>
<h:commandButton value="Convert" action="blah"/>
</h:form>
The same applies to your <h:selectOneRadio>. Put it inside the <h:form> where the commandButton is.
Related
it's a bit similar to this problem https://issues.jboss.org/browse/RF-11469
I have a template containing a composite defined like this:
<h:form id="transfer_list">
<ccs:criteriaPanel header="Critère de recherche"
filterAction="#{controller.filter()}">
<form:criteriaForm bean="#{controller.transferCriteria}"
rendered="#{! empty controller.transferSearchForm}"
mode="UPDATE"
controller="#{controller}" />
</ccs:criteriaPanel>
</h:form>
Controller is defined with a ui:param in the template child.
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
template="/pages/transfer/transferList.xhtml">
<ui:param name="controller" value="#{transferListOpenController}" />
</ui:composition>
Here is the composite impl (criteriaPanel):
<cc:interface>
<cc:attribute name="header" default="#{i18n['HEADER_SEARCH_CRITERIA']}" />
<cc:attribute name="filterAction" method-signature="java.lang.Object filter()" />
<cc:attribute name="update" default="#(.ui-datatable)" />
</cc:interface>
<cc:implementation>
<div id="#{cc.clientId}">
<p:panel header="#{cc.attrs.header}" toggleable="true">
<cc:insertChildren />
<f:facet name="footer">
<p:commandButton id="search_btn"
value="#{i18n['BUTTON_FILTER']}"
action="#{cc.attrs.filterAction}"
icon="ui-icon-search"
update="#{cc.attrs.update}" />
<p:commandButton value="#{i18n['BUTTON_CLEAR_FILTER']}"
action="#{cc.attrs.filterAction}"
process="#this"
immediate="true"
update="#{cc.attrs.update}">
<p:ajax update="#form" resetValues="true" />
</p:commandButton>
</f:facet>
<p:defaultCommand target="search_btn" />
</p:panel>
</div>
</cc:implementation>
Clicking on the button "filterAction" result into this:
javax.faces.FacesException: #{cc.attrs.filterAction}:
javax.el.PropertyNotFoundException: Target Unreachable, identifier
[controller] resolved to null at
com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:118)
at
org.primefaces.application.DialogActionListener.processAction(DialogActionListener.java:45)
at javax.faces.component.UICommand.broadcast(UICommand.java:315)
I use Tomcat 8.5 for this and Mojarra 2.2.13. It works if I don't put the whole thing in a composite component (criteriaPanel)
UPDATE
Sample available here: https://github.com/Rapster/primefaces-test/tree/issue-sof-45834296
Works fine with MyFaces 2.2.11 and Mojarra 2.2.8-23 and 2.3.2 (I don't know how impactful upgrading to 2.3 can be though...) From what I read here https://stackoverflow.com/a/42656386/4605161, Mojarra 2.2.8 is aimed for WebLogic but it seems I will need this one (and i'm running on Tomcat)
WORKAROUND
Writing this make it work (but that's a workaround i'd rather use template):
<ui:composition xmlns="http://www.w3.org/1999/xhtml">
<ui:param name="controller" value="#{testView}" />
<ui:decorate template="/template.xhtml">
</ui:decorate>
</ui:composition>
Funny thing is if I put ui:param inside ui:decorate I'll end up with the same exception
Should be fixed in 2.2.15, see github.com/javaserverfaces/mojarra/issues/4271
i use jsf2.0. my code look like this:
<h:form id="form">
<h:commandButton value="testbutton" action="#{Bean.test}">
<f:ajax render="msg"/>
</h:commandButton>
<h:outputText value="#{Bean.outmsg}" id="msg"/>
</h:form>
it's working well.
but if i change h:commandbutton to h:commandlink,
code look like this:
<h:form id="form">
<h:commandLink value="testbutton" action="#{Bean.test}">
<f:ajax render="msg"/>
</h:commandLink>
<h:outputText value="#{Bean.outmsg}" id="msg"/>
</h:form>
then my code can't work.
i need help,thanks guys.
use this code.
<f:ajax event="click" render="msg" listener="#{Bean.test}"/>
should be your java bean side like this.
public void test(AjaxBehaviorEvent event) { }
PF 3.5.10, Mojara 2.1.21, Omnifaces 1.5
I have Facelet-Template with p:menu and p:include for dialog
mytemplate.xhtml:
<h:form> ... <p:menubar>
<p:menuitem value="Start Dialog" oncomplete="mydialogwidget.show()"/>
<p:menuitem value="open another page" action="/app/mypage.xhtml?faces-redirect=true"/>
</p:menubar> ... </h:form>
<ui:insert name="content" />
<ui:include="/app/mydialog.xhtml" />
mydialog.xhtml:
<ui:composition>
<p:dialog widgetVar="mydialogwidget" ...>
<h:form>
<p:datatable binding="#{mybean.table}">
<p:column id="col_first"> ... </p:column>
...
<p:column id="col_last"> ... </p:colum>
</p:datatable>
</h:form>
</p:dialog>
</ui:composition>
mypage.xhtml:
<ui:composition template="/app/mytemplate.xhtml">
<ui:define name="content">
<h:form> ... </h:form>
</ui:define>
</ui:composition>
If I start mypage.xhtml form menue, I become JSF1007 error (Duplicate ids) The component tree will be written to my console. The simplified component tree output:
+id: mydialog
+id: mytable
+id: col_first <<=============
....
+id: col_last
+id:col_first <<========
The mydialog.xhtml will be included only once. The answer to question JSF with Primefaces Menu duplicate Id error? doesn't help me.
How can I aviod this error ? Where comes this error from ?
The prolbem was binding attribute on datatable. See also: Binding attribute causes duplicate component ID found in the view
SessionScoped component was used in multiple views.
I've used EL-table binding and then the problem was disappeared.
Good evening from Sweden!
I try to get a primefaces datatable to refresh. I tried various hints and solutions but nothing is working.
The button triggers a search in the DB and if I refresh the paga manually or if I use the tables sorting-function the result is shown.
Means the code in the backing bean works. But no automatic refresh directly after the button is clicked..
The bean scope is Session.
Here is the page
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui">
<h:head>
</h:head>
<h:body>
<ui:composition template="/templates/BasicTemplate.xhtml">
<ui:define name="content">
<h:form id="src_res">
<h2>Sök klass,undervisningsgrupp eller individ</h2>
<b>Sökord</b>: <h:inputText id="sw" value="#{smsb.searchword}"/>
<p:outputLabel value="Lärare"></p:outputLabel>
<h:selectOneListbox size="1" id="teacher" value="#{smsb.searchteacher}" >
<f:selectItems value="#{smsb.teachers}"/>
</h:selectOneListbox>
<p:commandButton action="#{smsb.searchgrp_user}" value="Sök!" update="src_list"/>
<p:dataTable id="src_list" value="#{smsb.searchresult}" var="obj" >
<p:column width="20%" sortBy="#{obj.groupname}">
<f:facet name="header" >
<h:outputText value="Beteckning"/>
</f:facet>
<h:outputText value="#{obj.groupname}"/>
</p:column>
<p:column width="10%">
<f:facet name="header" >
<h:outputText value="typ"/>
</f:facet>
<h:outputText value="#{obj.klass}"/>
</p:column>
<p:column width="10%" sortBy="#{obj.teacher}">
<f:facet name="header" >
<h:outputText value="lärare"/>
</f:facet>
<h:outputText value="#{obj.teacher}"/>
</p:column>
</p:dataTable>
</h:form>
</ui:define>
</ui:composition>
</h:body>
</html>
Any help or hints?
With regards
Ralf
EDIT
Hello and thanx for the offer to help!
As you guessed searchresult is a list and the Getter is defined by
List<sbasUserList> searchresult;
public List<sbasUserList> getSearchresult() {
return searchresult;
}
search_grp is a method of the backing bean:
public String searchgrp_user(){
//FacesContext context = FacesContext.getCurrentInstance();
ObjectContainer db = this.connBD("sms");
ObjectSet<sbasUserList> res;
this.searchresult = new ArrayList<sbasUserList>() ;
Query query=db.query();
query.constrain(sbasUserList.class);
query.descend("groupname").constrain(this.searchword).like();
query.descend("type").constrain('P').or(query.descend("type").constrain('M'));
query.descend("teacher").constrain(searchteacher).contains();
res = query.execute();
this.searchresult.addAll(res);
System.out.println(this.searchresult.size());
db.close();
return "";
}
The table is filled with the right dat if i update manually the browser. (F5) but certainly would like to have this done automatically.
Sorry folks! The glassfish server I was using wasn't setup right. It showed not all of the errors in the log file. I did a complete new setup of the whole IDE (new Eclipse, new glassfish server, thanx BalusC for the incredible tutorial!!!) and I found all errors. Now it works like it should!
Regards
Ralf
I am new to Java Web. I am using netbeans 7.0.1 and glassfish 3 to develop a web application. I am almost through with all data input and Now I want to create reports & graph. Requirement is to create charts (pie/bar/line based on user selection) with dynamic data (from database / datatable user can apply filters on data). I tried using Primefaces but it gives below error with simple example given in primeface show case:
javax.faces.event.AbortProcessingException:
/pages/analyst/analyse.xhtml #65,151
actionListener="#{analysis.bar()}": java.lang.NoClassDefFoundError:
org/primefaces/component/chart/series/ChartSeries
I have a jsf page that holds datatable backed by managedbean of viewscope. below is my code:
page
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.org/ui"
xmlns:f="http://java.sun.com/jsf/core">
<body>
<ui:composition template="./../../WEB-INF/Templates/VUTemplate.xhtml">
<ui:define name="menu">
<h:form id="home">
<p:menu>
<p:menuitem value="Home Page" url="../home.xhtml" />
</p:menu>
</h:form>
</ui:define>
<ui:define name="content">
<h:form id="form" prependId="false">
<p:growl id="growl" showDetail="true"/>
<p:barChart id="basic" value="#{analysis.categoryModel}" legendPosition="ne"
title="Basic Bar Chart" min="0" max="200" style="height:300px"/>
<p:dataTable id="table" var="var" widgetVar="wbTable"
value="#{analysis.list}"
paginator="true" rows="10"
paginatorPosition="bottom"
emptyMessage="No data found with given criteria"
>
<f:facet name="header">
World Bank Open Data Analysis
</f:facet>
<p:column filterBy="#{var.regionFullName}" sortBy="#{var.regionFullName}"
headerText="Region" footerText="Enter starting characters" >
<h:outputText value="#{var.regionFullName}" />
</p:column>
<p:column filterBy="#{var.countryFullName}" sortBy ="#{var.countryFullName}"
headerText="Country" footerText="Enter starting characters" >
<h:outputText value="#{var.countryFullName}" />
</p:column>
<p:column filterBy="#{var.indcatorTypeName}" sortBy ="#{var.indcatorTypeName}"
headerText="Indicator Type" footerText="Enter starting characters" >
<h:outputText value="#{var.indcatorTypeName}" />
</p:column>
<p:column filterBy="#{var.indicatorName}" sortBy ="#{var.indicatorName}"
headerText="Indicator" footerText="contains" filterMatchMode="contains">
<h:outputText value="#{var.indicatorName}" />
</p:column>
<p:column filterBy="#{var.year}" sortBy ="#{var.year}"
headerText="Year" footerText="starts with">
<h:outputText value="#{var.year}" />
</p:column>
<p:column filterBy="#{var.dataValue}" sortBy ="#{var.dataValue}"
headerText="Data Value" footerText="starts with" >
<h:outputText value="#{var.dataValue}" />
</p:column>
</p:dataTable>
<h:panelGrid id="command" columns="6" cellpadding="4" >
<p:commandButton id="line" value="Line" actionListener="#{analysis.line()}" process="#this :form:table" update="result table" >
</p:commandButton>
<p:commandButton id="bar" value="Bar" actionListener="#{analysis.bar()}" process="#this :form:table" update="result table" >
</p:commandButton>
</h:panelGrid>
<p:messages id="result" showDetail="true" autoUpdate="true"/>
</h:form>
</ui:define>
</ui:composition>
</body>
</html>
backbean
import ejb.VwdataFacade;
import java.io.Serializable;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import model.Vwdata;
import org.primefaces.component.chart.series.ChartSeries;
import org.primefaces.model.chart.CartesianChartModel;
#ManagedBean
#ViewScoped
public class Analysis implements Serializable{
private List<Vwdata> list;
private #EJB VwdataFacade wsvc; //entity services
private CartesianChartModel categoryModel;
public Analysis() {
}
public CartesianChartModel getCategoryModel() {
return categoryModel;
}
#PostConstruct
public void init() {
list = wsvc.findAll();
}
public List<Vwdata> getList() {
// list = wsvc.findAll();
return list;
}
public void line(){
}
public void bar(){
createCategoryModel();
}
private void createCategoryModel() {
categoryModel = new CartesianChartModel();
ChartSeries yaxis = new ChartSeries();
yaxis.setLabel("Label");
yaxis.set("2004",120);
yaxis.set("2005",130);
yaxis.set("2006",140);
yaxis.set("2007",110);
categoryModel.addSeries(yaxis);
}
}
If I place call createCategoryModel in the constructor or init method, I cant even view the page which otherwise was working perfectly without chart code. Any help will be highly appreciated. Thanks
java.lang.NoClassDefFoundError: org/primefaces/component/chart/series/ChartSeries
The mentioned class was introduced in PrimeFaces 3.0 and was thus not available in PrimeFaces 2.x and older.
Given the fact that the PrimeFaces 3.0 specific XML namespace http://primefaces.org/ui and all the <p:xxx> tags in your code did apparently not result in a Facelets compile error, that can only mean that you've both PrimeFaces 2.x and 3.x libraries in your webapp's runtime classpath wherein the 2.x one got precedence in classloading.
Get rid of the offending old PrimeFaces 2.x library from your webapp's runtime classpath and this problem should then disappear.