I have the following p:datatable that hold two buttons that call the View and the Add dialogs.
The problem is with the Add dialog, that does not seem to be setting properties to any of the Entity objects.
When I put a break on the save() method inside ChildrenController.java all values a 'null'.
I am using:
PrimeFaces 5.1 |
Mojarra 2.2.7 |
Glassfish 4.1 |
ChildrenDataTable.xhtml
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui"
xmlns:ui="http://java.sun.com/jsf/facelets">
<h:form id="form1">
<p:dataTable var="child" value="#{childrenController.children}"
scrollable="true"
scrollHeight="500">
<p:column>
<f:facet name="header">First Name</f:facet>
<h:outputText value="#{child.firstName}" />
</p:column>
<p:column>
<f:facet name="header">Last Name</f:facet>
<h:outputText value="#{child.lastName}" />
</p:column>
<p:column>
<f:facet name="header">Parent Name</f:facet>
<h:outputText value="#{child.parent.firstName}" />
</p:column>
<p:column>
<f:facet name="header">Parent Last Name</f:facet>
<h:outputText value="#{child.parent.lastName}" />
</p:column>
<p:column style="width:32px;text-align: center">
<p:commandButton update=":mainForm:form1:childDetail"
oncomplete="PF('childDialog').show()"
process="#this"
icon="ui-icon-search"
title="View">
<f:setPropertyActionListener value="#{child}"
target="#{childrenController.selectedChild}" />
</p:commandButton>
</p:column>
<p:column style="width:32px;text-align: center">
<p:commandButton onclick="PF('childAddDialog').show()"
icon="ui-icon-person"
title="Add">
</p:commandButton>
</p:column>
</p:dataTable>
<!-- Dialog for the View button-->
<p:dialog header="Child Info"
widgetVar="childDialog"
modal="false"
showEffect="fade"
hideEffect="fade"
resizable="false">
<p:outputPanel id="childDetail" style="text-align:center;">
<p:panelGrid columns="2"
rendered="#{not empty childrenController.selectedChild}"
columnClasses="label,value">
<h:outputText value="First Name:" />
<h:outputText value="#{childrenController.selectedChild.firstName}" />
<h:outputText value="Last Name:" />
<h:outputText value="#{childrenController.selectedChild.lastName}" />
<h:outputText value="Birth Date:" />
<h:outputText value="#{childrenController.selectedChild.dateOfBirth}"/>
<h:outputText value="Medical Info:" />
<h:outputText value="#{childrenController.selectedChild.medicalInfo}" />
</p:panelGrid>
</p:outputPanel>
</p:dialog>
<!--Dialog for the Add button-->
<p:dialog header="Register Child"
widgetVar="childAddDialog"
modal="false"
showEffect="fade"
hideEffect="fade"
resizable="false">
<p:outputPanel id="childRegister" style="text-align:center;">
<p:panelGrid columns="2" >
<f:facet name="header">
Child info
</f:facet>
<h:outputText value="First Name:"/>
<h:inputText value="#{childrenController.child.firstName}"
required="true"/>
<h:outputText value="Last Name:"/>
<h:inputText value="#{childrenController.child.lastName}"
required="true"/>
<h:outputText value="Birth Date:"/>
<h:inputText value="#{childrenController.child.dateOfBirth}"
required="true"/>
<h:outputText value="Medical Info:"/>
<p:inputTextarea value="#{childrenController.child.medicalInfo}"
rows="5" cols="30" counter="display" maxlength="128"
counterTemplate="{0} characters remaining." autoResize="false"/>
<h:outputText id="display" />
</p:panelGrid>
<p:panelGrid columns="2" >
<f:facet name="header">
Parent info
</f:facet>
<h:outputText value="First Name:"/>
<h:inputText value="#{childrenController.parent.firstName}"
required="true"/>
<h:outputText value="Last Name:"/>
<h:inputText value="#{childrenController.parent.lastName}"
required="true"/>
<h:outputText value="Username:"/>
<h:inputText value="#{childrenController.user.username}"
required="true"/>
<h:outputText value="Password1:"/>
<p:password id="pwd1" value="#{childrenController.password1}"
match="pwd2"
required="true"/>
<h:outputText value="Password2:"/>
<p:password id="pwd2" value="#{childrenController.user.password}"
required="true"/>
<p:commandButton actionListener="#{childrenController.save()}"
value="Save"
process="#this"
oncomplete="childAddDialog.hide()">
</p:commandButton>
</p:panelGrid>
</p:outputPanel>
</p:dialog>
</h:form>
</ui:composition>
ChildrenController.java
#Named
#SessionScoped
public class ChildrenController implements Serializable{
// This final string will be used to set the loginn role to parent
private static final String parentRole = "parent";
private String password1;
#EJB
private ChildEJB childEJB;
private Child currentChild;
private Child child = new Child();
#EJB
private ParentEJB parentEJB;
private Parent parent = new Parent();
#EJB
private RoleEJB roleEJB;
private Role role = new Role(parentRole);
#EJB
private UserEJB userEJB;
private User user = new User();
public Child getCurrentChild() {
return currentChild;
}
public void setCurrentChild(Child currentChild) {
this.currentChild = currentChild;
}
public Child getChild() {
return child;
}
public void setChild(Child child) {
this.child = child;
}
public Parent getParent() {
return parent;
}
public void setParent(Parent parent) {
this.parent = parent;
}
public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
}
public Role getRole() {
return role;
}
public void setRole(Role role) {
this.role = role;
}
public Child getSelectedChild() {
return selectedChild;
}
public void setSelectedChild(Child selectedChild) {
this.selectedChild = selectedChild;
}
private Child selectedChild;
public List<Child> getChildren() {
return childEJB.findAll();
}
public String getPassword1() {
return password1;
}
public void setPassword1(String password1) {
this.password1 = password1;
}
public void save(){
// Map the parent to the child and vice verca
parent.addChild(child);
child.setParent(parent);
// Persist the Parent
parent = parentEJB.addNew(parent);
// Persist the Child
child = childEJB.addNew(child);
// This will set the username for the parent role
role.setUsername(user.getUsername());
// This will set the role for the new username
user.setRole(role);
// This will map that the login belongs to a Parent
user.setParent(parent);
// Persist the new User
user = userEJB.addNew(user);
}
}
Stack Trace
Warning: A system exception occurred during an invocation on EJB ParentEJB, method: public entity.Parent EJB.ParentEJB.addNew(entity.Parent)
Warning: javax.ejb.EJBException
at com.sun.ejb.containers.EJBContainerTransactionManager.processSystemException(EJBContainerTransactionManager.java:748)
at com.sun.ejb.containers.EJBContainerTransactionManager.completeNewTx(EJBContainerTransactionManager.java:698)
at com.sun.ejb.containers.EJBContainerTransactionManager.postInvokeTx(EJBContainerTransactionManager.java:503)
at com.sun.ejb.containers.BaseContainer.postInvokeTx(BaseContainer.java:4566)
at com.sun.ejb.containers.BaseContainer.postInvoke(BaseContainer.java:2074)
at com.sun.ejb.containers.BaseContainer.postInvoke(BaseContainer.java:2044)
at com.sun.ejb.containers.EJBLocalObjectInvocationHandler.invoke(EJBLocalObjectInvocationHandler.java:220)
at com.sun.ejb.containers.EJBLocalObjectInvocationHandlerDelegate.invoke(EJBLocalObjectInvocationHandlerDelegate.java:88)
at com.sun.proxy.$Proxy250.addNew(Unknown Source)
at EJB.__EJB31_Generated__ParentEJB__Intf____Bean__.addNew(Unknown Source)
at mb.ChildrenController.save(ChildrenController.java:110)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at javax.el.ELUtil.invokeMethod(ELUtil.java:332)
at javax.el.BeanELResolver.invoke(BeanELResolver.java:537)
at javax.el.CompositeELResolver.invoke(CompositeELResolver.java:256)
at com.sun.el.parser.AstValue.invoke(AstValue.java:283)
at com.sun.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:304)
at org.jboss.weld.util.el.ForwardingMethodExpression.invoke(ForwardingMethodExpression.java:40)
at org.jboss.weld.el.WeldMethodExpression.invoke(WeldMethodExpression.java:50)
at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105)
at javax.faces.event.MethodExpressionActionListener.processAction(MethodExpressionActionListener.java:147)
at javax.faces.event.ActionEvent.processListener(ActionEvent.java:88)
at javax.faces.component.UIComponentBase.broadcast(UIComponentBase.java:813)
at javax.faces.component.UICommand.broadcast(UICommand.java:300)
at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:790)
at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1282)
at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:198)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:646)
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1682)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:318)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:160)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:734)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:673)
at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:99)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:174)
at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:415)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:282)
at com.sun.enterprise.v3.services.impl.ContainerMapper$HttpHandlerCallable.call(ContainerMapper.java:459)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:167)
at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:201)
at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:175)
at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:235)
at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:284)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:201)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:133)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:112)
at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)
at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:561)
at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:112)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:117)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:56)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:137)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:565)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:545)
at java.lang.Thread.run(Thread.java:745)
Caused by: javax.validation.ConstraintViolationException: Validation failed for classes [entity.Parent] during persist time for groups [javax.validation.groups.Default, ]
List of constraint violations:[
ConstraintViolationImpl{interpolatedMessage='may not be null', propertyPath=lastName, rootBeanClass=class entity.Parent, messageTemplate='{javax.validation.constraints.NotNull.message}'}
ConstraintViolationImpl{interpolatedMessage='may not be null', propertyPath=firstName, rootBeanClass=class entity.Parent, messageTemplate='{javax.validation.constraints.NotNull.message}'}
]
at org.hibernate.cfg.beanvalidation.BeanValidationEventListener.validate(BeanValidationEventListener.java:160)
at org.hibernate.cfg.beanvalidation.BeanValidationEventListener.onPreInsert(BeanValidationEventListener.java:95)
at org.hibernate.action.internal.EntityIdentityInsertAction.preInsert(EntityIdentityInsertAction.java:202)
at org.hibernate.action.internal.EntityIdentityInsertAction.execute(EntityIdentityInsertAction.java:91)
at org.hibernate.engine.spi.ActionQueue.execute(ActionQueue.java:480)
at org.hibernate.engine.spi.ActionQueue.addResolvedEntityInsertAction(ActionQueue.java:191)
at org.hibernate.engine.spi.ActionQueue.addInsertAction(ActionQueue.java:175)
at org.hibernate.engine.spi.ActionQueue.addAction(ActionQueue.java:210)
at org.hibernate.event.internal.AbstractSaveEventListener.addInsertAction(AbstractSaveEventListener.java:324)
at org.hibernate.event.internal.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:288)
at org.hibernate.event.internal.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:194)
at org.hibernate.event.internal.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:125)
at org.hibernate.jpa.event.internal.core.JpaPersistEventListener.saveWithGeneratedId(JpaPersistEventListener.java:84)
at org.hibernate.event.internal.DefaultPersistEventListener.entityIsTransient(DefaultPersistEventListener.java:206)
at org.hibernate.event.internal.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:149)
at org.hibernate.event.internal.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:75)
at org.hibernate.internal.SessionImpl.firePersist(SessionImpl.java:807)
at org.hibernate.internal.SessionImpl.persist(SessionImpl.java:780)
at org.hibernate.internal.SessionImpl.persist(SessionImpl.java:785)
at org.hibernate.jpa.spi.AbstractEntityManagerImpl.persist(AbstractEntityManagerImpl.java:1181)
at com.sun.enterprise.container.common.impl.EntityManagerWrapper.persist(EntityManagerWrapper.java:287)
at EJB.ParentEJB.addNew(ParentEJB.java:31)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.glassfish.ejb.security.application.EJBSecurityManager.runMethod(EJBSecurityManager.java:1081)
at org.glassfish.ejb.security.application.EJBSecurityManager.invoke(EJBSecurityManager.java:1153)
at com.sun.ejb.containers.BaseContainer.invokeBeanMethod(BaseContainer.java:4786)
at com.sun.ejb.EjbInvocation.invokeBeanMethod(EjbInvocation.java:656)
at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:822)
at com.sun.ejb.EjbInvocation.proceed(EjbInvocation.java:608)
at org.jboss.weld.ejb.AbstractEJBRequestScopeActivationInterceptor.aroundInvoke(AbstractEJBRequestScopeActivationInterceptor.java:46)
at org.jboss.weld.ejb.SessionBeanInterceptor.aroundInvoke(SessionBeanInterceptor.java:52)
at sun.reflect.GeneratedMethodAccessor166.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at com.sun.ejb.containers.interceptors.AroundInvokeInterceptor.intercept(InterceptorManager.java:883)
at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:822)
at com.sun.ejb.EjbInvocation.proceed(EjbInvocation.java:608)
at com.sun.ejb.containers.interceptors.SystemInterceptorProxy.doCall(SystemInterceptorProxy.java:163)
at com.sun.ejb.containers.interceptors.SystemInterceptorProxy.aroundInvoke(SystemInterceptorProxy.java:140)
at sun.reflect.GeneratedMethodAccessor168.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at com.sun.ejb.containers.interceptors.AroundInvokeInterceptor.intercept(InterceptorManager.java:883)
at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:822)
at com.sun.ejb.containers.interceptors.InterceptorManager.intercept(InterceptorManager.java:369)
at com.sun.ejb.containers.BaseContainer.__intercept(BaseContainer.java:4758)
at com.sun.ejb.containers.BaseContainer.intercept(BaseContainer.java:4746)
at com.sun.ejb.containers.EJBLocalObjectInvocationHandler.invoke(EJBLocalObjectInvocationHandler.java:212)
... 54 more
You didn't process your components in your question's code. What you did there to fix the problem in your own answer is including your form in the list of UIComponents to process. That means that JSF will not look at all your input components in your form and that's why it will not retrieve any values you entered in those fields to set them in your backing bean.
To get a better understanding of what process means, you may look at this question.
Solved the problem by putting the p:commandButton inside the p:panelGrid of the dialog which makes absolutely no sense to me whatsovever ! Anyway here is how the dialog looks like:
<h:form id="formName">
<p:dialog>
<p:panelGrid>
<p:commandButton process="#this :formName" ajax="false" actionListener="#{bean.method()}"/>
</p:panelGrid>
</p:dialog>
</h:form>
EDIT: edited code to be more readable
Related
I have this JSF snippet which works fine. When the commandbutton is clicked it should reload the page by redirecting to itself.
<p:dataTable value="#{fileModel.files}"
var="file" scrollable="true" scrollHeight="400">
<p:column headerText="#{msgs.lbl_file}">
#{file.name}
</p:column>
<p:column width="150">
<p:commandButton value="#{msgs.lbl_import}"
actionListener="#{fileModel.importFile(file, module)}"
**action="mypage.jsf?faces-redirect=true"**/>
</p:column>
<p:column width="150">
<p:commandLink value="#{msgs.lbl_view}" target="_blank" ajax="false"
actionListener="#{fileModel.view(file)}"/>
</p:column>
</p:dataTable>
Because I want to reuse this in multiple pages I tried to make this JSF template and include it via ui:include. Only thing is that I need the action to be configurable depending on the page it is used in.
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:p="http://primefaces.org/ui">
<p:dataTable value="#{fileModel.files}"
var="file" scrollable="true" scrollHeight="400">
<p:column headerText="#{msgs.lbl_file}">
#{file.name}
</p:column>
<p:column width="150">
<p:commandButton value="#{msgs.lbl_import}"
actionListener="#{fileModel.importFile(file, module)}"
**action="#{redirectTo}"**/>
</p:column>
<p:column width="150">
<p:commandLink value="#{msgs.lbl_view}" target="_blank" ajax="false"
actionListener="#{fileModel.view(file)}"/>
</p:column>
</p:dataTable>
</ui:composition>
With the inclusion
<ui:include src="moduleSettingImportDialog.xhtml">
<ui:parameter name="redirectTo" value="mypage.jsf?faces-redirect=true"/>
</ui:include>
The error I get is something like
javax.el.ELException: Not a Valid Method Expression: #{redirectTo}
at
com.sun.el.lang.ExpressionBuilder.createMethodExpression(ExpressionBuilder.java:311)
at
com.sun.el.ExpressionFactoryImpl.createMethodExpression(ExpressionFactoryImpl.java:96)
at
org.jboss.weld.util.el.ForwardingExpressionFactory.createMethodExpression(ForwardingExpressionFactory.java:43)
at
org.jboss.weld.el.WeldExpressionFactory.createMethodExpression(WeldExpressionFactory.java:53)
at
com.sun.faces.facelets.tag.TagAttributeImpl.getMethodExpression(TagAttributeImpl.java:240)
at
com.sun.faces.facelets.tag.jsf.ActionSourceRule$ActionMapper2.applyMetadata(ActionSourceRule.java:107)
at
com.sun.faces.facelets.tag.MetadataImpl.applyMetadata(MetadataImpl.java:81)
A similar error I get when using JSF composite components.
<c:interface>
<c:attribute name="module"/>
<c:attribute name="redirectTo" type="java.lang.String"/>
</c:interface>
<c:implementation rendered="#{systemSettingModel.LOG_REASON_FOR_CHANGES_ISAKTIV}">
<p:dataTable value="#{fileModel.files}"
var="file" scrollable="true" scrollHeight="400">
<p:column headerText="#{msgs.lbl_file}">
#{file.name}
</p:column>
<p:column width="150">
<p:commandButton value="#{msgs.lbl_import}"
actionListener="#{fileModel.importFile(file, cc.attrs.module)}"
**action="#{cc.attrs.redirectTo}"**/>
</p:column>
<p:column width="150">
<p:commandLink value="#{msgs.lbl_view}" target="_blank" ajax="false"
actionListener="#{fileModel.view(file)}"/>
</p:column>
</p:dataTable>
</c:implementation>
#{cc.attrs.redirectTo}: javax.el.ELException:
java.lang.IllegalArgumentException: Cannot convert
multimodulesettings.jsf?faces-redirect=true&includeViewParams=true of
type class java.lang.String to class javax.el.MethodExpression
javax.faces.FacesException: #{cc.attrs.redirectTo}:
javax.el.ELException: java.lang.IllegalArgumentException: Cannot
convert
multimodulesettings.jsf?faces-redirect=true&includeViewParams=true of
type class java.lang.String to class javax.el.MethodExpression at
com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:118)
at javax.faces.component.UICommand.broadcast(UICommand.java:315) at
javax.faces.component.UIData.broadcast(UIData.java:1108) at
javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:790)
at
javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1282)
at
com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101) at
com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:198)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:646) at
org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1682)
at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:344)
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214)
at
org.primefaces.webapp.filter.FileUploadFilter.doFilter(FileUploadFilter.java:78)
at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256)
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214)
at
org.glassfish.tyrus.servlet.TyrusServletFilter.doFilter(TyrusServletFilter.java:295)
How to pass a fixed string to a JSF template or composite component that is used in the action attribute of a commandButton?
As a workaround I implemented a JSF bean method that just returns the passed in string like so.
public String echo(String s) {
return s;
}
Then instead of passing the fix string as a parameter to the component it is being passed by an EL expression.
<ui:include src="moduleSettingImportDialog.xhtml">
<ui:parameter name="redirectTo" value="#{jsfBean.echo('mypage.jsf?faces-redirect=true')}"/>
</ui:include>
How to resolve the jsf datatable java.lang.NumberFormatException: For input string, in bellow my code :
I have SelectItemDTO :
public class SelectItemDTO implements Serializable {
private static final long serialVersionUID = 1L;
private Object value;
private String label;
public SelectItemDTO() {
}
public SelectItemDTO(Object value, String label) {
this.value = value;
this.label = label;
}
public Object getValue() {
return value;
}
public void setValue(Object value) {
this.value = value;
}
public String getLabel() {
return label;
}
public void setLabel(String label) {
this.label = label;
}
}
in my dialog.xhtml i have :
<p:dialog id="#{cc.attrs.widgetVar}" widgetVar="#{cc.attrs.widgetVar}" resizable="true" responsive="true" modal="true" appendTo="#(body)" height="580" width="850" dynamic="true">
<h:form>
<p:fieldset>
<p:panel header="Ajout d'une nouvelle règle">
#{cc.attrs.value.parametres}
</p:panel>
</p:fieldset>
</h:form>
</p:dialog>
when i run my application i have the output in dialog.xhtml [com.sfr.medusa.dto.SelectItemDTO#1d591889, com.sfr.medusa.dto.SelectItemDTO#62e36383]
now when i change the dialog to :
<p:dialog id="#{cc.attrs.widgetVar}" widgetVar="#{cc.attrs.widgetVar}" resizable="true" responsive="true" modal="true" appendTo="#(body)" height="580" width="850" dynamic="true">
<h:form>
<p:fieldset>
<p:panel header="Ajout d'une nouvelle règle">
<p:dataTable value="#{cc.attrs.value.parametres}" var="par" emptyMessage="#{msg['datatable.msg.empty']}">
<p:column headerText="Param">
<h:outputText value="#{par.label}" />
</p:column>
<p:column headerText="Value">
<h:inputText value="#{par.value}" />
</p:column>
</p:dataTable>
</p:panel>
</p:fieldset>
</h:form>
</p:dialog>
I have a an exception:
java.lang.NumberFormatException: For input string: "parametres"
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
at java.lang.Integer.parseInt(Integer.java:580)
at java.lang.Integer.parseInt(Integer.java:615)
at javax.el.ListELResolver.coerce(ListELResolver.java:157)
at javax.el.ListELResolver.getValue(ListELResolver.java:70)
at com.sun.faces.el.DemuxCompositeELResolver._getValue(DemuxCompositeELResolver.java:176)
at com.sun.faces.el.DemuxCompositeELResolver.getValue(DemuxCompositeELResolver.java:203)
at org.apache.el.parser.AstValue.getValue(AstValue.java:169)
at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:184)
at com.sun.faces.facelets.el.ContextualCompositeValueExpression.getValue(ContextualCompositeValueExpression.java:158)
at com.sun.faces.facelets.el.TagValueExpression.getValue(TagValueExpression.java:109)
at javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:194)
at javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:182)
at javax.faces.component.UIData.getValue(UIData.java:732)
at org.primefaces.component.api.UIData.getDataModel(UIData.java:764)
at org.primefaces.component.api.UIData.setRowModel(UIData.java:571)
at org.primefaces.component.api.UIData.setRowIndexWithoutRowStatePreserved(UIData.java:564)
at org.primefaces.component.api.UIData.setRowIndex(UIData.java:473)
at javax.faces.component.UIData.invokeOnComponent(UIData.java:1041)
at javax.faces.component.UIComponent.invokeOnComponent(UIComponent.java:1503)
at javax.faces.component.UIComponentBase.invokeOnComponent(UIComponentBase.java:718)
with this code i get the expected result but not with datatable:
<p:panelGrid class="ui-noborder" columns="2" cellpadding="5">
<f:facet name="header">
<p:row>
<p:column headerText="Paramètre" />
<p:column headerText="Valeur" />
</p:row>
</f:facet>
<c:forEach items="#{cc.attrs.value.parametres}" var="param">
<p:row>
<p:column>
<p:outputLabel value="#{param.label}" />
</p:column>
<p:column>
<p:inputText value="#{param.value}" />
</p:column>
</p:row>
</c:forEach>
</p:panelGrid>
I have the same exception with other component :
<p:commandButton icon="ui-icon-check" value="#{msg['btn.add']}" onstart="PF('statusDialog').show()" oncomplete="PF('#{atWidgetVar}').hide();" actionListener="#{cc.attrs.actionListener}" update="#{cc.attrs.update}" >
</p:commandButton>
this code cause the same exception. when i replace update attribute with :
<f:ajax render="#{cc.attrs.update}"/>
this one work fine.
i think the primefaces datatable have many bugs when the datatable is empty.
Ok i found it (not a problem of jsf or priemfaces).
the problem is when we use a composit to pass parmetre we should use a type in attribute when is # string like this:
<ce:attribute name="value" required="true" type="java.util.List"/>
for now i let open this maybe there is other problem :)
I advance in the debug I think the question is :
it is possible to pass value of datatable in composite attribute ?
<ce:attribute name="value" required="true" />
<p:dataTable value="#{cc.attrs.value}"
I am getting the following error when I select a row in the lazy datatable :
javax.faces.FacesException: Method not found: com.gestion.projet.web.jsf.ProjetComponentImpl#f632823.onRowSelect(org.primefaces.event.SelectEvent)
at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:85)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:97)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:114)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:308)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter.doFilterInternal(OpenEntityManagerInViewFilter.java:113)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1040)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:315)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
and then the code associated with the following bean method:
#Scope("session")
#Component("ProjetComponent")
public class ProjetComponentImpl implements ProjetComponent {
public void onRowSelect(SelectEvent event) {
FacesMessage msg = new FacesMessage("Projet Selected", ((Projet) event.getObject()).getIdprojet().toString());
FacesContext.getCurrentInstance().addMessage(null, msg);
}
}
and this the xhtml page:
<h:form id="form">
<p:dataTable var="current" value="#{ProjetComponent.lazyModel}"
paginator="true" rows="10"
paginatorTemplate="{RowsPerPageDropdown} {FirstPageLink} {PreviousPageLink} {CurrentPageReport} {NextPageLink} {LastPageLink}"
rowsPerPageTemplate="5,10,15" selectionMode="single"
selection="#{ProjetComponent.projet}" id="projetTable" lazy="true">
<p:ajax event="rowSelect" listener="#{ProjetComponent.onRowSelect}"
update=":form:projetDetail" oncomplete="PF('projetDialog').show()" />
<p:column headerText="Id" sortBy="#{current.idprojet}" filterBy="#{current.idprojet}">
<h:outputText value="#{current.idprojet}" />
</p:column>
<p:column headerText="Nom" sortBy="#{current.nomprojet}"
filterBy="#{current.nomprojet}">
<h:outputText value="#{current.nomprojet}" />
</p:column>
</p:dataTable>
<p:dialog header="Projet Detail" widgetVar="projetDialog" modal="true"
showEffect="fade" hideEffect="fade" resizable="false">
<p:outputPanel id="projetDetail" style="text-align:center;">
<p:panelGrid columns="2"
rendered="#{not empty ProjetComponent.projet}"
columnClasses="label,value">
<f:facet name="header">
</f:facet>
<h:outputText value="Id:" />
<h:outputText value="#{ProjetComponent.projet.idprojet}" />
<h:outputText value="Nom:" />
<h:outputText value="#{ProjetComponent.projet.nomprojet}" />
</p:panelGrid>
</p:outputPanel>
</p:dialog>
</h:form>
this is a snaphshot of what i get when i select a row :
Seems you're interchanging Spring Annotations with JSF annotations - PrimeFaces is a JSF component library in use with a JSF Managed Bean - #SessionScope and #ManagedBean(name="projectBlah")
from the javax.faces.bean packages
I'm using prime faces data table in my application where i have
when I select any of a given table
it returns me the following error
someone help?
I used primefaces 3.5
jsf 2.1
My dataTable of primefaces
lazyDataModel = new LazyDataModel<Funcionario>()
{
/**
*
*/
private static final long serialVersionUID = 1L;
#Override
public List<Funcionario> load(int first, int pageSize,
String sortField, SortOrder sortOrder,
Map<String, String> filters) {
try {
funcionarios = funcionarioService.listar(first, pageSize, filters);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if(getRowCount() <= 0)
{
setRowCount(funcionarioService.getRowCount());
}
setPageSize(pageSize);
super.setWrappedData(funcionarios);
return funcionarios;
}
#Override
public Object getRowKey(Funcionario item) {
System.out.println(item.getCodigo());
return item.getCodigo();
}
#Override
public Funcionario getRowData(String rowKey) {
// TODO Auto-generated method stub
Integer id = Integer.valueOf(rowKey);
for (Funcionario funcionario : (List<Funcionario>) getWrappedData()) {
if(id.equals(funcionario.getCodigo()))
{
return funcionario;
}
}
return null;
}
#Override
public void setRowIndex(int rowIndex) {
/*
* The following is in ancestor (LazyDataModel):
* this.rowIndex = rowIndex == -1 ? rowIndex : (rowIndex % pageSize);
*/
if (rowIndex == -1 || getPageSize() == 0) {
super.setRowIndex(-1);
}
else
super.setRowIndex(rowIndex % getPageSize());
}
};
}
my listagem.xhtml
?xml version="1.0" encoding="ISO-8859-1" ?>
<!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:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui"
xmlns:ui="http://java.sun.com/jsf/facelets">
<h:head>
</h:head>
<h:form id = "f">
<p:dataTable emptyMessage="Não tem registros." var = "funcionario"
value = "#{bean.getLazyDataModel()}" paginator="true" rows = "5" id = "tbf"
rowsPerPageTemplate="5,10,15" lazy = "true" filterEvent="enter"
selection="#{bean.selecionado}" selectionMode="single" rowKey="#{bean.funcionario.codigo}"
>
<p:ajax event="rowSelect" update=":t:dialogf:display" oncomplete="funcionarioDialog.show()"/>
<p:column filterBy="#{funcionario.codigo}" headerText="Codigo" filterMatchMode="contains"
>
<h:outputText value="#{funcionario.codigo}" />
</p:column>
<p:column filterBy="#{funcionario.nome}" headerText="Nome" filterMatchMode="contains">
<h:outputText value="#{funcionario.nome}" />
</p:column>
<p:column filterBy="#{funcionario.cpf}" headerText="Cpf" filterMatchMode="contains">
<h:outputText value="#{funcionario.cpf}" />
</p:column>
<p:column filterBy="#{funcionario.dataNascimento}" headerText="Data Nascimento" filterMatchMode="contains" >
<h:outputText value="#{funcionario.dataNascimento}" >
<f:convertDateTime type="date" pattern="dd/MM/yyyy" />
</h:outputText>
</p:column>
<p:column filterBy="#{funcionario.usuario}" headerText="Usuario" filterMatchMode="contains">
<h:outputText value="#{funcionario.usuario}" />
</p:column>
<p:column headerText = "Excluir">
<p:commandLink action ="#{funcionarioBean.excluir()}" update = "tbf" >
excluir
<f:setPropertyActionListener target="#{funcionarioBean.funcionario}" value="#{funcionario}" />
</p:commandLink>
</p:column>
<p:column style="width:4%">
<p:commandButton id="selectButton" update = ":t:dialogf:display" value = "ver"
oncomplete="funcionarioDialog.show()" title="View">
<f:setPropertyActionListener target="#{bean.selecionado}" value="#{funcionario}" />
</p:commandButton>
</p:column>
<p:column headerText = "Alterar">
<p:commandButton id="selectButton2" update = ":t:" value = "Alterar" title="Alterar">
<f:setPropertyActionListener target="#{bean.funcionario}" value="#{funcionario}" />
</p:commandButton>
</p:column>
</p:dataTable>
</h:form>
<h:form id = "dialogf">
<p:dialog id = "dialog" header = "Detalhes do Registro" widgetVar="funcionarioDialog" resizable = "false"
showEffect="fade" hideEffect="explode">
<h:panelGrid id = "display" columns="2" cellpadding="4">
<h:outputText value="Codigo:" />
<h:outputText value="#{bean.selecionado.codigo}" />
<h:outputText value="Nome:" />
<h:outputText value="#{bean.funcionario.nome}" />
<h:outputText value="Cpf:" />
<h:outputText value="#{bean.funcionario.cpf}" />
<h:outputText value="Data Nascimento:" />
<h:outputText value="#{bean.funcionario.dataNascimento}" >
<f:convertDateTime type="date" pattern="dd/MM/yyyy" />
</h:outputText>
<h:outputText value="Usuario:" />
<h:outputText value="#{bean.funcionario.usuario}" />
<h:outputText value="Senha:" />
<h:outputText value="#{bean.funcionario.senha}" />
</h:panelGrid>
</p:dialog>
</h:form>
</html>
error
Set 04, 2013 9:40:56 AM com.sun.faces.context.PartialViewContextImpl processPartial
INFO: java.lang.NullPointerException
java.lang.NullPointerException
at org.primefaces.component.datatable.DataTable.getRowData(DataTable.java:936)
at org.primefaces.component.datatable.feature.SelectionFeature.decodeSingleSelection(SelectionFeature.java:47)
at org.primefaces.component.datatable.feature.SelectionFeature.decode(SelectionFeature.java:38)
at org.primefaces.component.datatable.DataTableRenderer.decode(DataTableRenderer.java:57)
at javax.faces.component.UIComponentBase.decode(UIComponentBase.java:787)
at org.primefaces.component.api.UIData.processDecodes(UIData.java:228)
at com.sun.faces.context.PartialViewContextImpl$PhaseAwareVisitCallback.visit(PartialViewContextImpl.java:506)
at com.sun.faces.component.visit.PartialVisitContext.invokeVisitCallback(PartialVisitContext.java:183)
at org.primefaces.component.api.UIData.visitTree(UIData.java:639)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1600)
at javax.faces.component.UIForm.visitTree(UIForm.java:344)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1600)
at org.primefaces.component.tabview.TabView.visitTree(TabView.java:419)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1600)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1600)
at com.sun.faces.context.PartialViewContextImpl.processComponents(PartialViewContextImpl.java:376)
at com.sun.faces.context.PartialViewContextImpl.processPartial(PartialViewContextImpl.java:252)
at javax.faces.context.PartialViewContextWrapper.processPartial(PartialViewContextWrapper.java:183)
at javax.faces.component.UIViewRoot.processDecodes(UIViewRoot.java:931)
at com.sun.faces.lifecycle.ApplyRequestValuesPhase.execute(ApplyRequestValuesPhase.java:78)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:409)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter.doFilterInternal(OpenEntityManagerInViewFilter.java:178)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:108)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1023)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
I have a jsf page that I can't update the value of some checkboxes in a list of userDamain objects, in fact this is a part of my jsf page :
<h:outputText value="USER's rights list: "></h:outputText>
<p:dataTable id="userss" var="userr" value="#{userMB.userListe}">
<p:column>
<f:facet name="header"><h:outputText value="FirstName" /></f:facet>
<h:outputText value="#{userr.firstName}" />
</p:column>
<p:column>
<h:panelGrid columns="1" style="margin-bottom:10px" cellpadding="5">
<h:outputText value="Basic Usage: " />
<p:selectBooleanCheckbox value="#{userr.deletee}" immediate="true" actionListener="#{userr.deletee}" />
</h:panelGrid>
<p:commandButton value="Submit" update="display" oncomplete="dlg.show()" />
<p:dialog header="Selected Values" modal="true" showEffect="fade" hideEffect="fade" widgetVar="dlg">
<h:panelGrid columns="1" id="display">
<h:outputText value="Value 1: #{userr.deletee}" />
</h:panelGrid>
</p:dialog>
</p:column>
when I click on the boolean button 'Submit', the value of the userr.deletee is always false ( the default value ) and it's not updated anyway, I tried to use the Listner and actionListener in the booleanButton but it doesn't work, I also tried the postValidate event, so if someone has any idea of that, I would be graceful.
this is a part of my managed bean:
private List<UserDomain> userListe ;
public List<UserDomain> getUserListe() {
return this.userListe;
}
public void loadUserListe(){
this.userListe = new ArrayList<UserDomain>();
this.userListe.addAll(getUserServicee().getAll());
}
public void setUserListe(List<UserDomain> userListe) {
this.userListe = userListe;
}
a part of the userDomain bean:
...
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
#Transient
private boolean deletee;
public boolean isDeletee() {
return deletee;
}
public void setDeletee(boolean deletee) {
this.deletee = deletee;
}
I found out a solution which seems logic to me, I added to my checkbox an ajax behavior to execute a method and an attribute which called in this method to get the whole userDomain object, so on I can get the user.deletee value, here is a part of the code I m talking about:
<h:panelGrid columns="1" style="margin-bottom:10px" cellpadding="5">
<h:outputText value="Delete Right: " />
<p:selectBooleanCheckbox value="#{userr.deletee}">
<f:ajax execute="#this" listener="#{userMB.saveUserRights}" />
<f:attribute name="user" value="#{userr}" />
</p:selectBooleanCheckbox>
</h:panelGrid>
I hope this will be helpful for you