javax.el.MethodNotFoundException: Method not found: JSF - jsf

I am getting error while trying a simple application with JSF.
javax.el.MethodNotFoundException: Method not found: com.jsf.training.beans.TravelBean#4b6b8628.travelInfo()
at org.apache.el.util.ReflectionUtil.getMethod(ReflectionUtil.java:245)
at org.apache.el.parser.AstValue.invoke(AstValue.java:271)
at org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:274)
at javax.faces.event.MethodExpressionActionListener.processAction(MethodExpressionActionListener.java:149)
at javax.faces.event.ActionEvent.processListener(ActionEvent.java:88)
at javax.faces.component.UIComponentBase.broadcast(UIComponentBase.java:818)
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.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
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.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
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:409)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1044)
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)
My managed bean is :
#ManagedBean (name="travelBean")
#SessionScoped
public class TravelBean {
private int index = 0;
private String source;
private String destination;
private Date date;
java.sql.Date sqlDate;
private boolean visible = false;
public boolean isVisible() {
return visible;
}
public void setVisible(boolean visible) {
this.visible = visible;
}
public TravelBean() {
}
public String getSource() {
return source;
}
public void setSource(String source) {
this.source = source;
}
public String getDestination() {
return destination;
}
public void setDestination(String destination) {
this.destination = destination;
}
public Date getDate() {
return date;
}
public void setDate(Date date) {
this.date = date;
}
public int getIndex() {
return index;
}
public void setIndex(int index) {
this.index = index;
}
public void getDateInSql() {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
sdf.format(date);
sqlDate = new java.sql.Date(date.getTime());
}
public void getTravelInfo() throws SQLException {
setVisible(true);
/*SearchServiceImpl search = new SearchServiceImpl();
search.searchTrainsService(travelBean);*/
System.out.println("********** in travel Bean :" +source +destination +date);
TrainBean tb = new TrainBean();
tb.getTrainsList(source,destination,sqlDate);
}
and my xhtml :
<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>
<script name="jquery/jquery.js" library="primefaces"></script>
<h:outputStylesheet library="css" name="resources/css/table-style.css" />
</h:head>
<h:body>
<h:form>
<p:growl id="message"></p:growl>
<p:tabView activeIndex="#{travelBean.index}" dynamic="true" effect="fade" effectDuration="fast">
<p:tab title="Trains">
<h:form>
<h:outputText value="Source"/>:<h:inputText id="source" value="#{travelBean.source}"></h:inputText>
<h:outputText value="Destination"/>:<h:inputText id="destination" value="#{travelBean.destination}"></h:inputText>
<h:outputText value="Date"/>:<p:calendar id="date" value="#{travelBean.date}"></p:calendar>
<h:commandButton value="Search Trains" update="table-wrapper" action="#{travelBean.travelInfo}" actionListener="#{travelBean.travelInfo}" >
<!-- <f:ajax execute="#this source destination date" render="output" /> -->
<f:attribute name="source" value="#{travelBean.source}"/>
<f:attribute name="destination" value="#{travelBean.destination}"/>
<f:attribute name="date" value="#{travelBean.date}"/>
</h:commandButton>
<h2><h:outputText id="output" value="#{travelBean.source} #{travelBean.destination} #{travelBean.date}"/></h2>
</h:form>
</p:tab>
<p:tab title="Flights">
<h1>Search flights by routes</h1>
<h:form>
<h:outputText value="Source"/>:<h:inputText id="source" value="#{travelBean.source}"></h:inputText>
<h:outputText value="Destination"/>:<h:inputText id="destination" value="#{travelBean.destination}"></h:inputText>
<h:outputText value="Date"/>:<h:inputText id="date" value="#{travelBean.date}"></h:inputText>
<h:commandButton value="Search Flights" >
<f:ajax execute="#form" render="output" />
</h:commandButton>
<h2><h:outputText id="output" value="#{travelBean.source}"/> </h2>
</h:form>
</p:tab>
</p:tabView>
</h:form>
</h:body>
</html>
I have looked at the other questions, and tried the answer but nothing worked.
Any help is highly appreciated. Thanks in advance!

Just in case the same kind of problem might happen if you are not importing the right library. Sometimes your IDE can autoimport: "import java.awt.event.ActionEvent;" instead of "import javax.faces.event.ActionEvent;" and thus causing the "same" issue. It will not be able to find the method.

action="#{travelBean.travelInfo}" is an action method. Only value methods converts travelInfo from EL expression to getTravelInfo() when searching for appropriate method. In action method exactly travelInfo() method is expected to be present in your managed bean, but it isn't.

Related

My #PostConstruct method is getting called everytime I delete the last element of a dataTable in JSF

I have a dataTable in JSF to show the phone numbers from a selected user.
Like the image below
My DataTable
In this dataTable I have a column with a commandLink to delete the element. The commandLink is working fine except in one particular case : If I delete the element of the last row and I try to delete any other element my #PostConstruct method is called again and it throws an exception. I concluded that the exception is being called because the param that contains the id of the user is null.
My question is why is this bug triggered only when I delete the last row of the dataTable ?
nov 28, 2022 11:36:54 AM com.sun.faces.application.view.FaceletViewHandlingStrategy handleRenderException
SEVERE: Error Rendering View[/telefone.xhtml]
com.sun.faces.mgbean.ManagedBeanCreationException: An error occurred performing resource injection on managed bean telefoneBean
at com.sun.faces.mgbean.BeanBuilder.invokePostConstruct(BeanBuilder.java:227)
at com.sun.faces.mgbean.BeanBuilder.build(BeanBuilder.java:103)
at com.sun.faces.mgbean.BeanManager.createAndPush(BeanManager.java:409)
at com.sun.faces.mgbean.BeanManager.create(BeanManager.java:269)
at com.sun.faces.el.ManagedBeanELResolver.resolveBean(ManagedBeanELResolver.java:244)
at com.sun.faces.el.ManagedBeanELResolver.getValue(ManagedBeanELResolver.java:116)
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.AstIdentifier.getValue(AstIdentifier.java:93)
at org.apache.el.parser.AstValue.getValue(AstValue.java:136)
at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:189)
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.UIOutput.getValue(UIOutput.java:174)
at com.sun.faces.renderkit.html_basic.HtmlBasicInputRenderer.getValue(HtmlBasicInputRenderer.java:205)
at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.getCurrentValue(HtmlBasicRenderer.java:355)
at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeEnd(HtmlBasicRenderer.java:164)
at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:924)
at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeRecursive(HtmlBasicRenderer.java:312)
at com.sun.faces.renderkit.html_basic.GridRenderer.renderRow(GridRenderer.java:185)
at com.sun.faces.renderkit.html_basic.GridRenderer.encodeChildren(GridRenderer.java:129)
at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:894)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1856)
at javax.faces.render.Renderer.encodeChildren(Renderer.java:176)
at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:894)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1856)
at com.sun.faces.context.PartialViewContextImpl$PhaseAwareVisitCallback.visit(PartialViewContextImpl.java:559)
at com.sun.faces.component.visit.PartialVisitContext.invokeVisitCallback(PartialVisitContext.java:183)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1689)
at javax.faces.component.UIForm.visitTree(UIForm.java:371)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1700)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1700)
at com.sun.faces.context.PartialViewContextImpl.processComponents(PartialViewContextImpl.java:399)
at com.sun.faces.context.PartialViewContextImpl.processPartial(PartialViewContextImpl.java:319)
at org.primefaces.context.PrimePartialViewContext.processPartial(PrimePartialViewContext.java:57)
at javax.faces.component.UIViewRoot.encodeChildren(UIViewRoot.java:1004)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1856)
at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:417)
at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:131)
at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:120)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:219)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:647)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:227)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:197)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:97)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:541)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:135)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:687)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:78)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:360)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:399)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:890)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1743)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
at org.apache.tomcat.util.threads.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1191)
at org.apache.tomcat.util.threads.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:659)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.base/java.lang.Thread.run(Thread.java:829)
Caused by: com.sun.faces.spi.InjectionProviderException
at com.sun.faces.vendor.WebContainerInjectionProvider.invokeAnnotatedMethod(WebContainerInjectionProvider.java:115)
at com.sun.faces.vendor.WebContainerInjectionProvider.invokePostConstruct(WebContainerInjectionProvider.java:95)
at com.sun.faces.mgbean.BeanBuilder.invokePostConstruct(BeanBuilder.java:221)
... 65 more
Caused by: java.lang.reflect.InvocationTargetException
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at com.sun.faces.vendor.WebContainerInjectionProvider.invokeAnnotatedMethod(WebContainerInjectionProvider.java:113)
... 67 more
Caused by: java.lang.NumberFormatException: null
at java.base/java.lang.Long.parseLong(Long.java:655)
at java.base/java.lang.Long.parseLong(Long.java:817)
at managedBean.TelefoneManagedBean.init(TelefoneManagedBean.java:42)
... 72 more
nov 28, 2022 11:36:54 AM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [Faces Servlet] in context with path [/pos-java-maven-hibernate] threw exception
java.lang.IllegalStateException: CDATA tags may not nest
at com.sun.faces.renderkit.html_basic.HtmlResponseWriter.startCDATA(HtmlResponseWriter.java:681)
at javax.faces.context.ResponseWriterWrapper.startCDATA(ResponseWriterWrapper.java:179)
at javax.faces.context.PartialResponseWriter.startError(PartialResponseWriter.java:341)
at org.primefaces.context.PrimePartialResponseWriter.startError(PrimePartialResponseWriter.java:116)
at com.sun.faces.context.AjaxExceptionHandlerImpl.handlePartialResponseError(AjaxExceptionHandlerImpl.java:200)
at com.sun.faces.context.AjaxExceptionHandlerImpl.handle(AjaxExceptionHandlerImpl.java:124)
at javax.faces.context.ExceptionHandlerWrapper.handle(ExceptionHandlerWrapper.java:100)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:119)
at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:219)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:647)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:227)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:197)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:97)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:541)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:135)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:687)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:78)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:360)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:399)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:890)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1743)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
at org.apache.tomcat.util.threads.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1191)
at org.apache.tomcat.util.threads.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:659)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.base/java.lang.Thread.run(Thread.java:829)
#PostConstruct
public void init() {
String codUser = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap()
.get("codigouser");
daoUsuario = new DaoUsuario();
daoTelefone = new DaoTelefone();
telefone = new TelefoneUser();
usuario = daoUsuario.pesquisar(Long.parseLong(codUser), UsuarioPessoa.class);
lista = daoTelefone.consultarLista(usuario);
}
The code of my xhtml page
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.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">
<h:head></h:head>
<h:body>
<h:form>
<p:breadCrumb>
<p:menuitem></p:menuitem>
<p:menuitem value="Pagina Index" action="index.jsf" />
<p:menuitem value="Pagina Primefaces" action="primefaces.jsf" />
</p:breadCrumb>
</h:form>
<h:form id="formulario">
<h:messages showDetail="true" showSummary="false" id="msg"></h:messages>
<h:panelGrid columns="2">
<h:outputLabel value="Usuário: " />
<h:outputText value="#{telefoneBean.usuario.nome}" />
<h:outputLabel value="ID " />
<h:inputText value="#{telefoneBean.telefone.id}" readonly="true" />
<h:outputLabel value="Numero: " />
<h:inputText value="#{telefoneBean.telefone.numero}" required="true" />
<h:outputLabel value="Tipo: " />
<h:inputText value="#{telefoneBean.telefone.tipo}" required="true" />
<h:commandButton value="Salvar" action="#{telefoneBean.salvar}" />
</h:panelGrid>
</h:form>
<h:form id="formularioTelefones">
<p:dataTable rowStatePreserved="true" value="#{telefoneBean.lista}"
id="tabelatelefones" var="tel">
<f:facet name="header">Lista de Telefones</f:facet>
<p:column>
<h:outputText value="#{tel.id}" />
<f:facet name="header">ID</f:facet>
</p:column>
<p:column>
<h:outputText value="#{tel.numero}" />
<f:facet name="header">Numero</f:facet>
</p:column>
<p:column>
<f:facet name="header">Tipo</f:facet>
<h:outputText value="#{tel.tipo}" />
</p:column>
<p:column>
<f:facet name="header">Deletar</f:facet>
<h:commandLink id="botaodeletar" action="#{telefoneBean.remover}">
<h:graphicImage url="resources/img/deletar.png" />
<f:setPropertyActionListener value="#{tel}"
target="#{telefoneBean.telefone}" />
<f:ajax execute="botaodeletar" render="#form :formulario:msg" />
</h:commandLink>
</p:column>
</p:dataTable>
</h:form>
</h:body>
</html>
I will explain the bug using this example, lets imagine I delete the row with id= 484.If I do this, I can delete any other row perfectly fine.
Now, lets say I delete the row 503. This row is going to be removed, but if I try to remove any other row my #PostConstruct method is going to be called again and it will throw an exception because the param "codigouser"(this is the param that gets the ID of the user I want) will be null, BUT I still am able to add another number to the list and if I do this the table starts working again (with the same conditions)...
.See the example of a dataTable
First I thought the problem was on the method that I use to delete the phone number in the DB. Then I thought the problem was on the method that I use to get the list of phone numbers in the DB. Then I noticed that this bug just happens when I refresh the values of the dataTable. If I dont refresh the values on the dataTable then everything works perfectly fine, but the problem of course is that the phone numbers I remove still show in the table because I didnt refreshed it.
Edit :
The managed bean class
package managedBean;
import java.io.Serializable;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;
import dao.DaoTelefone;
import dao.DaoUsuario;
import model.TelefoneUser;
import model.UsuarioPessoa;
#ManagedBean(name = "telefoneBean")
#ViewScoped
public class TelefoneManagedBean implements Serializable {
/**
*
*/
private static final long serialVersionUID = 1L;
private UsuarioPessoa usuario; // the user
private DaoUsuario daoUsuario; // dao to find the user in the database
private DaoTelefone daoTelefone; // dao to find the phone numbers in the data base
private TelefoneUser telefone; // Object used to save and delete the phone number
private List<TelefoneUser> lista; // list of phone numbers from the user
#PostConstruct
public void init() {
String codUser = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap()
.get("codigouser"); // getting the user id
daoUsuario = new DaoUsuario();
daoTelefone = new DaoTelefone();
telefone = new TelefoneUser();
usuario = daoUsuario.pesquisar(Long.parseLong(codUser), UsuarioPessoa.class); // getting the user
lista = daoTelefone.consultarLista(usuario); // getting the list of phone numbers
}
public void setUsuario(UsuarioPessoa usuario) {
this.usuario = usuario;
}
public UsuarioPessoa getUsuario() {
return usuario;
}
public TelefoneUser getTelefone() {
System.out.println("telefone");
return telefone;
}
public String remover() throws Exception {
daoTelefone.deleteId(telefone);
FacesContext.getCurrentInstance().addMessage(null,
new FacesMessage(FacesMessage.SEVERITY_INFO, "Informação:", "Telefone removido."));
telefone = new TelefoneUser();
return "";
}
public String salvar() {
telefone.setPessoa(usuario);
daoTelefone.salvar(telefone);
telefone = new TelefoneUser();
FacesContext.getCurrentInstance().addMessage(null,
new FacesMessage(FacesMessage.SEVERITY_INFO, "Informação:", "Telefone Salvo."));
return "";
}
public void setTelefone(TelefoneUser telefone) {
this.telefone = telefone;
}
public DaoUsuario getDaoUsuario() {
return daoUsuario;
}
public void setDaoUsuario(DaoUsuario daoUsuario) {
this.daoUsuario = daoUsuario;
}
public DaoTelefone getDaoTelefone() {
return daoTelefone;
}
public void setDaoTelefone(DaoTelefone daoTelefone) {
this.daoTelefone = daoTelefone;
}
public List<TelefoneUser> getLista() {
lista = daoTelefone.consultarLista(usuario);
return lista;
}
public void setLista(List<TelefoneUser> lista) {
this.lista = lista;
}
}
The method used to remove the phone number :
public void deleteId(E entidade) throws Exception {
Object primaryKey = HibernateUtil.getPrimaryKey(entidade);
EntityTransaction transaction = entityManager.getTransaction();
transaction.begin();
entityManager.createNativeQuery("delete from "+entidade.getClass().getSimpleName().toLowerCase()+" where id="+primaryKey).executeUpdate();
transaction.commit();
}
In the comment section We found the problem. That was a rendering problem here:
<f:ajax execute="botaodeletar" render="#form :formulario:msg" />
Changed to this:
<f:ajax execute="#this" render=":formulario:msg :formularioTelefones:tabelatelefones" />

Error Rendering View[dummy.xhtml]: java.lang.NullPointerException [duplicate]

This question already has an answer here:
How to send form input values and invoke a method in JSF bean
(1 answer)
Closed 6 years ago.
I'm pretty new to JSF and recently I get this error, which I couldn't manage to solve. My intention was to open a dialog which has a picklist in it to select from the list and reload the datatable with the chosen elements.
:
13:47:22,873 SEVERE
[javax.enterprise.resource.webcontainer.jsf.context] (default task-72)
javax.faces.component.UpdateModelException:
javax.el.PropertyNotWritableException:
/forms/bestellungLieferant.xhtml #29,29
value="#{bestellungLieferantController.getAllAvailableKomponentDualListModel()}":
Illegal Syntax for Set Operation
My JSF Page:
<!DOCTYPE HTML>
<html lang="en" 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">
<f:view>
<f:metadata>
<!-- Start working on a task. Task Id is read internally from
request parameters and cached in the CDI conversation scope.
-->
<f:event type="preRenderView"
listener="#{camundaTaskForm.startTaskForm()}" />
</f:metadata>
<h:head>
<title>Paket zusammenstellen</title>
</h:head>
<h:body>
<p:dialog id="komponentenAuswahlDialog" header="Komponenten auswählen"
widgetVar="komponentenAuswahlDialog" modal="true" height="auto"
width="auto" immediate="true" rendered="true">
<p:pickList converter="entityConverter"
id="komponenteAuswahlPickList"
value="#{bestellungLieferantController.getAllAvailableKomponentDualListModel()}"
var="komponente" itemLabel="#{komponente.serienNummer}"
itemValue="#{komponente.id}" showSourceFilter="true"
showTargetFilter="true">
<f:facet name="sourceCaption">Quelle</f:facet>
<f:facet name="targetCaption">Ziel</f:facet>
</p:pickList>
<h:form>
<p:commandButton update="komponenteTable" value="Auswahl speichern"
oncomplete="PF('komponentenAuswahlDialog').hide();" />
</h:form>
</p:dialog>
<h:panelGrid id="paketInformationPG" columns="2" border="1">
<f:facet name="header">
<h:outputText value="Paket zusammenstellen" />
</f:facet>
<h:outputLabel value="Kunde:" />
<h:outputText value="#{processVariables['kunde']}" />
<h:outputLabel value="Betriebssystem:" />
<h:outputText value="Platzhalter" />
<h:outputLabel value="Benutzer:" />
<h:outputText value="#{processVariables['benutzerName']}" />
</h:panelGrid>
<h:panelGrid id="komponentenZusammenstellungPG" columns="2" border="1">
<f:facet name="header">
<h:panelGrid columns="2">
<h:outputText value="Komponenten" />
<h:commandButton type="button"
onclick="PF('komponentenAuswahlDialog').show();" value="+" />
</h:panelGrid>
</f:facet>
<p:dataTable id="komponenteTable" widgetVar="komponenteTable"
var="komponente"
value="#{bestellungLieferantController.komponentenList}">
<p:column>
<f:facet name="header">Typ</f:facet>
<h:outputText value="#{komponente.produkt.typ.name}" />
</p:column>
<p:column>
<f:facet name="header">Bezeichnung</f:facet>
<h:outputText value="#{komponente.produkt.name}" />
</p:column>
<p:column>
<f:facet name="header">SN</f:facet>
<h:outputText value="#{komponente.serienNummer}" />
</p:column>
<p:column headerText="Kaufdatum">
<f:facet name="header">Kaufdatum</f:facet>
<h:outputText value="#{komponente.bestellDatum}" />
</p:column>
<p:column>
<f:facet name="header">Aktion</f:facet>
<p:commandLink value="Bearbeiten" />
<p:commandLink value="Enfernen" />
</p:column>
</p:dataTable>
</h:panelGrid>
</h:body>
</f:view>
</html>
My Controller:
#ManagedBean
#SessionScoped
public class BestellungLieferantController implements Serializable{
#EJB
private BestellungFacade bestellungFacade;
#EJB
private PaketFacade paketFacade;
#EJB
private KomponenteFacade komponenteFacade;
#EJB
private BetriebssystemFacade betriebssystemFacade;
// Komponent-List with added komponent items
private List<Komponente> komponentenList = new ArrayList<Komponente>();
private DualListModel<Komponente> komponentenDualListModel;
public DualListModel<Komponente> getKomponentenDualListModel() {
return komponentenDualListModel;
}
public void setKomponentenDualListModel(DualListModel<Komponente> komponentenDualListModel) {
this.komponentenDualListModel = komponentenDualListModel;
}
public List<Komponente> getKomponentenList() {
return komponentenList;
}
public void setKomponentenList(List<Komponente> komponentenList) {
LogManager logManager = LogManager.getLogManager();
Logger rootLogger = logManager.getLogger("DUMMY");
rootLogger.setLevel(Level.ALL);
rootLogger.info("KomponentenList");
this.komponentenList = komponentenList;
}
/**
* Gets the actual Model with the distinct source and
* #param targetList
* #return
*/
public DualListModel<Komponente> getAllAvailableKomponentDualListModel(){
List<Komponente> sourceKomponenteList = this.komponenteFacade.getAllAvailableKomponente();
List<Komponente> sourceKomponenteDistinctList = new ArrayList<Komponente>();
if (this.komponentenList.size() != 0){
for(Komponente k : sourceKomponenteList){
if (!komponentenList.contains(k)){
sourceKomponenteDistinctList.add(k);
}
}
} else {
sourceKomponenteDistinctList = sourceKomponenteList;
}
// komponentenDualListModel.setSource(sourceKomponenteDistinctList);
// komponentenDualListModel.setTarget(komponentenList);
this.setKomponentenDualListModel(new DualListModel<Komponente>());
this.getKomponentenDualListModel().setSource(sourceKomponenteDistinctList);
this.getKomponentenDualListModel().setTarget(this.komponentenList);
return this.getKomponentenDualListModel();
}
public void putSelectionIntoKomponenteList(){
LogManager logManager = LogManager.getLogManager();
Logger rootLogger = logManager.getLogger("DUMMY");
rootLogger.setLevel(Level.ALL);
rootLogger.info("PutSelectionIntoKomponentList");
rootLogger.info("KOMPONENTELIST: " + komponentenDualListModel.getTarget());
this.komponentenList = this.komponentenDualListModel.getTarget();
}
}
My Stacktrace:
13:47:22,873 SEVERE [javax.enterprise.resource.webcontainer.jsf.context] (default task-72) javax.faces.component.UpdateModelException: javax.el.PropertyNotWritableException: /forms/bestellungLieferant.xhtml #29,29 value="#{bestellungLieferantController.getAllAvailableKomponentDualListModel()}": Illegal Syntax for Set Operation
at javax.faces.component.UIInput.updateModel(UIInput.java:866)
at org.primefaces.component.picklist.PickList.updateValue(PickList.java:530)
at org.primefaces.component.picklist.PickList.validateValue(PickList.java:394)
at javax.faces.component.UIInput.validate(UIInput.java:982)
at org.primefaces.component.picklist.PickList.validate(PickList.java:424)
at javax.faces.component.UIInput.executeValidate(UIInput.java:1248)
at javax.faces.component.UIInput.processValidators(UIInput.java:712)
at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1261)
at org.primefaces.component.dialog.Dialog.processValidators(Dialog.java:423)
at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1261)
at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1261)
at javax.faces.component.UIViewRoot.processValidators(UIViewRoot.java:1195)
at com.sun.faces.lifecycle.ProcessValidationsPhase.execute(ProcessValidationsPhase.java:76)
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:658)
at io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:85)
at io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:62)
at io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36)
at org.wildfly.extension.undertow.security.SecurityContextAssociationHandler.handleRequest(SecurityContextAssociationHandler.java:78)
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
at io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:131)
at io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:57)
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
at io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:46)
at io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:64)
at io.undertow.security.handlers.AuthenticationMechanismsHandler.handleRequest(AuthenticationMechanismsHandler.java:60)
at io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:77)
at io.undertow.security.handlers.NotificationReceiverHandler.handleRequest(NotificationReceiverHandler.java:50)
at io.undertow.security.handlers.AbstractSecurityContextAssociationHandler.handleRequest(AbstractSecurityContextAssociationHandler.java:43)
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
at org.wildfly.extension.undertow.security.jacc.JACCContextIdHandler.handleRequest(JACCContextIdHandler.java:61)
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
at io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:292)
at io.undertow.servlet.handlers.ServletInitialHandler.access$100(ServletInitialHandler.java:81)
at io.undertow.servlet.handlers.ServletInitialHandler$2.call(ServletInitialHandler.java:138)
at io.undertow.servlet.handlers.ServletInitialHandler$2.call(ServletInitialHandler.java:135)
at io.undertow.servlet.core.ServletRequestContextThreadSetupAction$1.call(ServletRequestContextThreadSetupAction.java:48)
at io.undertow.servlet.core.ContextClassLoaderSetupAction$1.call(ContextClassLoaderSetupAction.java:43)
at io.undertow.servlet.api.LegacyThreadSetupActionWrapper$1.call(LegacyThreadSetupActionWrapper.java:44)
at io.undertow.servlet.api.LegacyThreadSetupActionWrapper$1.call(LegacyThreadSetupActionWrapper.java:44)
at io.undertow.servlet.api.LegacyThreadSetupActionWrapper$1.call(LegacyThreadSetupActionWrapper.java:44)
at io.undertow.servlet.api.LegacyThreadSetupActionWrapper$1.call(LegacyThreadSetupActionWrapper.java:44)
at io.undertow.servlet.api.LegacyThreadSetupActionWrapper$1.call(LegacyThreadSetupActionWrapper.java:44)
at io.undertow.servlet.api.LegacyThreadSetupActionWrapper$1.call(LegacyThreadSetupActionWrapper.java:44)
at io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:272)
at io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:81)
at io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:104)
at io.undertow.server.Connectors.executeRootHandler(Connectors.java:202)
at io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:805)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Caused by: javax.el.PropertyNotWritableException: /forms/bestellungLieferant.xhtml #29,29 value="#{bestellungLieferantController.getAllAvailableKomponentDualListModel()}": Illegal Syntax for Set Operation
at com.sun.faces.facelets.el.TagValueExpression.setValue(TagValueExpression.java:136)
at javax.faces.component.UIInput.updateModel(UIInput.java:832)
... 53 more
Caused by: javax.el.PropertyNotWritableException: Illegal Syntax for Set Operation
at com.sun.el.parser.AstValue.setValue(AstValue.java:228)
at com.sun.el.ValueExpressionImpl.setValue(ValueExpressionImpl.java:294)
at org.jboss.weld.el.WeldValueExpression.setValue(WeldValueExpression.java:64)
at org.jboss.weld.el.WeldValueExpression.setValue(WeldValueExpression.java:64)
at com.sun.faces.facelets.el.TagValueExpression.setValue(TagValueExpression.java:131)
... 54 more
My Converter:
#FacesConverter(value = "entityConverter")
public class EntityConverter implements Converter {
private static Map<Object, String> entities = new WeakHashMap<Object, String>();
#Override
public String getAsString(FacesContext context, UIComponent component, Object entity) {
synchronized (entities) {
if (!entities.containsKey(entity)) {
String uuid = UUID.randomUUID().toString();
entities.put(entity, uuid);
return uuid;
} else {
return entities.get(entity);
}
}
}
#Override
public Object getAsObject(FacesContext context, UIComponent component, String uuid) {
for (Entry<Object, String> entry : entities.entrySet()) {
if (entry.getValue().equals(uuid)) {
return entry.getKey();
}
}
return null;
}
}
Any hints are welcome.
Thanks in advance!
You want to access a property in your backing bean. The property is not getAllAvailableKomponentDualListModel or allAvailableKomponentDualListModel but komponentenDualListModel
value="#{bestellungLieferantController.komponentDualListModel}"
You already have the setter and getter method in your bean. However, you need to call the method getAllAvailableKomponentDualListModel() before you access it from the view.
Write like this in p:pickList component value attribute:
value="#{bestellungLieferantController.getAllAvailableKomponentDualListModel}"
Edit
just to see try to return something else in this method like this:
#Override
public Object getAsObject(FacesContext context, UIComponent component, String uuid) {
for (Entry<Object, String> entry : entities.entrySet()) {
if (entry.getValue().equals(uuid)) {
return entry.getKey();
}
}
return uuid;
}

p:push objects and update via ui:repeat

This non-working implementation tries to start a new ScheduledExecutorService to dynamically push new Items to the client and update the form:
index.xhtml
<?xml version="1.0" encoding="UTF-8"?>
<!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://xmlns.jcp.org/jsf/html"
xmlns:p="http://primefaces.org/ui" xmlns:ui="http://java.sun.com/jsf/facelets"
xml:lang="en" lang="en">
<h:head>
<title>GG Well Trade</title>
</h:head>
<h:body>
<h:form>
<p:socket channel="/notify" onMessage="#{bean.add()}"/>
<p:commandButton value="Start" action="#{bean.start()}"/>
<ui:repeat value="#{bean.items}" var="item" id="content">
<p:outputLabel for="foo" value="#{item.label}" />
<p:inputText id="foo" value="#{item.value}" />
<p:commandButton value="Remove" action="#{bean.remove(item)}" update="#form" />
<br/>
</ui:repeat>
<!--<p:commandButton value="Add" action="#{bean.add}" update="#form" />-->
</h:form>
</h:body>
</html>
Item.class
public class Item {
private String label;
private String value;
public String getLabel() {
return label;
}
public void setLabel(String label) {
this.label = label;
}
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
}
Bean.class
#ManagedBean
#ViewScoped
#PushEndpoint("/notify")
public class Bean implements Serializable{
private List<Item> items;
#PostConstruct
public void init() {
items = new ArrayList<Item>();
}
public void start() {
ScheduledExecutorService timer = Executors.newSingleThreadScheduledExecutor();
timer.scheduleAtFixedRate(()->add(),0,3,TimeUnit.SECONDS);
}
public void add() {
Item item = new Item();
item.setLabel("label" + items.size());
items.add(item);
EventBus eventBus = EventBusFactory.getDefault().eventBus();
eventBus.publish("/notify", item);
}
#OnMessage(encoders = {JSONEncoder.class})
public Item onMessage(Item item){
return item;
}
public void remove(Item item) {
items.remove(item);
}
public List<Item> getItems() {
return items;
}
}
Pressing the Add button doesn't update the form, Start button instead does but only on clicks. Is there better ways to do this?
EDIT: exception raised:
HTTP Status 500 -
type Exception report
message
description The server encountered an internal error that prevented it from fulfilling this request.
exception
javax.servlet.ServletException
javax.faces.webapp.FacesServlet.service(FacesServlet.java:671)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
root cause
java.lang.NullPointerException
Bean.add(Bean.java:43)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
java.lang.reflect.Method.invoke(Method.java:498)
javax.el.BeanELResolver.invoke(BeanELResolver.java:158)
javax.el.CompositeELResolver.invoke(CompositeELResolver.java:79)
org.apache.el.parser.AstValue.getValue(AstValue.java:159)
org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:184)
com.sun.faces.facelets.el.TagValueExpression.getValue(TagValueExpression.java:109)
javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:194)
org.primefaces.component.socket.Socket.getOnMessage(Socket.java:125)
org.primefaces.component.socket.SocketRenderer.encodeEnd(SocketRenderer.java:55)
javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:920)
javax.faces.component.UIComponent.encodeAll(UIComponent.java:1863)
javax.faces.render.Renderer.encodeChildren(Renderer.java:176)
javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:890)
javax.faces.component.UIComponent.encodeAll(UIComponent.java:1856)
javax.faces.component.UIComponent.encodeAll(UIComponent.java:1859)
javax.faces.component.UIComponent.encodeAll(UIComponent.java:1859)
com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:458)
com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:134)
com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:120)
com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:219)
javax.faces.webapp.FacesServlet.service(FacesServlet.java:659)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
note The full stack trace of the root cause is available in the Apache Tomcat/8.5.8 logs.

IllegalArgumentException: Cannot convert PROPERTY of type class org.omnifaces.el.ExpressionInspector$ValueExpressionType to class java.lang.Boolean

I have an issue with OmniFaces 1.11 <o:validateBean /> at class level (http://showcase.omnifaces.org/validators/validateBean)
Basically, i'm trying to validate the same bean using two validation groups according to the button I click :
<h:commandButton value="Mandatory">
<o:validateBean value="#{testBean.pojo}" validationGroups="bo.ihm.beans.Mandatory" />
</h:commandButton>
<h:commandButton value="Optional">
<o:validateBean value="#{testBean.pojo}" validationGroups="javax.validation.groups.Default" />
</h:commandButton>
Whenever I click on a button, I get
GRAVE: Exception occured while doing validation.
javax.el.ELException: /testOmnifaces.xhtml #21,74 value="#{testBean.pojo.forain}": java.lang.IllegalArgumentException: Cannot convert PROPERTY of type class org.omnifaces.el.ExpressionInspector$ValueExpressionType to class java.lang.Boolean
at com.sun.faces.facelets.el.TagValueExpression.getValue(TagValueExpression.java:114)
at org.omnifaces.el.ExpressionInspector.getValueReference(ExpressionInspector.java:43)
at org.omnifaces.taghandler.ValidateBean$6.invoke(ValidateBean.java:331)
at org.omnifaces.taghandler.ValidateBean$6.invoke(ValidateBean.java:326)
at org.omnifaces.util.Components$ForEach$1.visit(Components.java:508)
at org.omnifaces.util.Components$ForEach$TypesVisitCallback.visit(Components.java:573)
at com.sun.faces.component.visit.FullVisitContext.invokeVisitCallback(FullVisitContext.java:151)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1689)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1700)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1700)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1700)
at javax.faces.component.UIForm.visitTree(UIForm.java:371)
at org.omnifaces.util.Components$ForEach.invoke(Components.java:541)
at org.omnifaces.util.Components$ForEach.invoke(Components.java:505)
at org.omnifaces.taghandler.ValidateBean.forEachInputWithMatchingBase(ValidateBean.java:326)
at org.omnifaces.taghandler.ValidateBean.access$400(ValidateBean.java:151)
at org.omnifaces.taghandler.ValidateBean$3.run(ValidateBean.java:286)
at org.omnifaces.taghandler.ValidateBean$ValidateBeanCallback.invoke(ValidateBean.java:430)
at org.omnifaces.util.Events$1.invoke(Events.java:278)
at org.omnifaces.util.Events$4.beforePhase(Events.java:312)
at org.omnifaces.eventlistener.CallbackPhaseListener.beforePhase(CallbackPhaseListener.java:63)
at com.sun.faces.lifecycle.Phase.handleBeforePhase(Phase.java:228)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:99)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:198)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:646)
at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:696)
at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:521)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:138)
at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:564)
at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:213)
at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1097)
at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:448)
at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:175)
at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1031)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:136)
at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:200)
at org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:109)
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:97)
at org.eclipse.jetty.server.Server.handle(Server.java:446)
at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:271)
at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:246)
at org.eclipse.jetty.io.AbstractConnection$ReadCallback.run(AbstractConnection.java:358)
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:601)
at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:532)
at java.lang.Thread.run(Thread.java:745)
Caused by: javax.el.ELException: java.lang.IllegalArgumentException: Cannot convert PROPERTY of type class org.omnifaces.el.ExpressionInspector$ValueExpressionType to class java.lang.Boolean
at com.sun.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:229)
at com.sun.faces.facelets.el.TagValueExpression.getValue(TagValueExpression.java:109)
... 44 more
Caused by: java.lang.IllegalArgumentException: Cannot convert PROPERTY of type class org.omnifaces.el.ExpressionInspector$ValueExpressionType to class java.lang.Boolean
at com.sun.el.lang.ELSupport.coerceToBoolean(ELSupport.java:189)
at com.sun.el.lang.ELSupport.coerceToType(ELSupport.java:394)
at com.sun.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:227)
... 45 more
testWithClassLevelValidation.xhtml :
<!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://xmlns.jcp.org/jsf/facelets" xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:h="http://xmlns.jcp.org/jsf/html" xmlns:o="http://omnifaces.org/ui">
<f:metadata>
<f:viewAction action="#{testBean.init}" />
</f:metadata>
<h:head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Test</title>
</h:head>
<h:body>
<h:form id="formaliteACCRE">
<h:panelGrid columns="1" style="width: 100%;">
<h:panelGrid columns="2" style="width: 100%; display: inline-block;">
<h:outputLabel for="forain">Yes or No ?</h:outputLabel>
<h:selectBooleanCheckbox id="forain" value="#{testBean.pojo.forain}">
<f:ajax execute="forain" render="groupeDomicile" />
</h:selectBooleanCheckbox>
</h:panelGrid>
<h:panelGroup id="groupeDomicile">
<h:outputText value="Yes" rendered="#{testBean.pojo.forain}" />
<h:outputText value="No" rendered="#{not testBean.pojo.forain}" />
</h:panelGroup>
<h:inputText id="numeroSecu" value="#{testBean.pojo.numeroSecuriteSociale}" maxlength="13" size="13" />
<h:inputText id="numeroSecuCle" value="#{testBean.pojo.cleSecuriteSociale}" maxlength="2" size="3" />
<h:panelGrid columns="2" style="width: 100%; display: inline-block;">
<h:inputText id="mandatory" value="#{testBean.pojo.mandatory}" maxlength="13" size="13" />
<h:outputText value="*" style="color:red;" />
</h:panelGrid>
<f:ajax execute="#form" render="#form">
<h:commandButton value="Mandatory">
<o:validateBean value="#{testBean.pojo}" validationGroups="bo.ihm.beans.Mandatory" />
</h:commandButton>
<h:commandButton value="Optional">
<o:validateBean value="#{testBean.pojo}" validationGroups="javax.validation.groups.Default" />
</h:commandButton>
</f:ajax>
</h:panelGrid>
<ui:remove> ################################################################################################ </ui:remove>
<ui:remove> ===== MESSAGES D'ERREURS ===== </ui:remove>
<ui:remove> ################################################################################################ </ui:remove>
<h:panelGroup id="messagesErreur">
<h:panelGrid class="dr-pnl" width="100%" rendered="#{not empty facesContext.messageList}">
<h:messages style="color:red;" />
</h:panelGrid>
</h:panelGroup>
</h:form>
</h:body>
</html>
TestBean.java :
package bo.ihm.beans;
import java.io.Serializable;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.validation.Valid;
#ViewScoped
#ManagedBean(name = "testBean")
public class TestBean implements Serializable {
private static final long serialVersionUID = 1L;
#Valid
private Pojo pojo;
public Pojo getPojo() {
return pojo;
}
public void init() {
pojo = new Pojo();
pojo.setNumeroSecuriteSociale("2531257351038");
pojo.setCleSecuriteSociale("22");
}
public void setPojo(final Pojo pPojo) {
this.pojo = pPojo;
}
}
Pojo.java :
package bo.ihm.beans;
import org.hibernate.validator.constraints.NotEmpty;
#NumeroSecuriteSociale
public class Pojo {
private boolean forain;
private String cleSecuriteSociale;
private String numeroSecuriteSociale;
#NotEmpty(groups = Mandatory.class)
private String mandatory;
public String getCleSecuriteSociale() {
return cleSecuriteSociale;
}
public String getMandatory() {
return mandatory;
}
public String getNumeroSecuriteSociale() {
return numeroSecuriteSociale;
}
public boolean isForain() {
return forain;
}
public void setCleSecuriteSociale(final String pCleSecuriteSociale) {
cleSecuriteSociale = pCleSecuriteSociale;
}
public void setForain(final boolean pForain) {
forain = pForain;
}
public void setMandatory(final String pMandatory) {
mandatory = pMandatory;
}
public void setNumeroSecuriteSociale(final String pNumeroSecuriteSociale) {
numeroSecuriteSociale = pNumeroSecuriteSociale;
}
/*
* (non-Javadoc)
*
* #see java.lang.Object#toString()
*/
#Override
public String toString() {
final StringBuilder builder = new StringBuilder();
builder.append("Pojo [forain=");
builder.append(forain);
builder.append(", cleSecuriteSociale=");
builder.append(cleSecuriteSociale);
builder.append(", numeroSecuriteSociale=");
builder.append(numeroSecuriteSociale);
builder.append(", mandatory=");
builder.append(mandatory);
builder.append("]");
return builder.toString();
}
}
the full code is available at https://github.com/ErwanLeroux/Bo_ihm_test_omnifaces just run clean jetty:run-war et go to http://localhost:14080/bo_ihm/testWithClassLevelValidation.xhtml
The second page http://localhost:14080/bo_ihm/testWithoutClassLevelValidation.xhtml is her to demonstrate that class level constraints doesn't work, when i click on whenever button, I should get a validation error message like this : 'Pojo [forain=false, cleSecuriteSociale=22, numeroSecuriteSociale=2531257351038, mandatory=null] is not valid'
It turns out that implicit EL coercion is was causing this all. We were passing around internal values like ValueExpressionType.PROPERTY and ValueExpressionType.METHOD to indicate if the EL expression represents a property (getter/setter) call or a method (action) call. However, this approach failed if the value has implicit EL coercion support, like java.lang.Boolean, on which EL would implicitly convert e.g. a string of "true" to a boolean true.
This approach of passing around internal values to indicate the kind of EL expression was since OmniFaces 2.0 used to breakdown the EL expression in <o:grapicImage value> and extract any EL method arguments so they could be converted and passed around as HTTP query string parameters. That explains why it still worked fine in OmniFaces 1.x.
As per this commit, this has been fixed for OmniFaces 2.2.

Property 'productCategoryName' not found on type java.lang.String

I have checked as much as i can ,but i could not find where the problem is , i have seen few stack overflow Questions related to mine but mostly they all seems missing # .
and i have seen somewhere that old version of mojora lib may cause this exceptions.i checked Names i am using in hibernate beans they all looks good but am not able to locate the problem .....
My Html Page:
<?xml version="1.0" encoding="UTF-8"?>
<!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:ui="http://java.sun.com/jsf/facelets"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui"
xmlns:t="http://myfaces.apache.org/tomahawk">
<h:body>
<ui:composition template="/WEB-INF/templates/layout.xhtml">
<ui:param name="category" value="Admin" />
<ui:param name="item" value="Create User" />
<ui:param name="user" value="#{createUserAccountBean}" />
<ui:define name="content">
<h:form id="productsForm">
<div class="headerbg">
<div id="innerheaderbg">
<div id="iconarea">
<img src="#{request.contextPath}/images/headerimages/productlist.png" />
</div>
<div id="headertextarea">
<p class="headingtext">Order</p>
<p id="breadCrumbtext">Order  <img src="#{request.contextPath}/images/error-bullet.gif" />
 Product Category List
</p>
</div>
<div id="otherarea"></div>
</div>
</div>
<p:growl />
<div class="widget widget-table action-table">
<div class="widget-header"> <i class="icon-th-list"></i>
<h3>Product List</h3>
<p:spacer width="10px" height="30px"/>
<h:outputLabel value="Product Category" style="color:#0A8FFF;font-weight:bold;margin-bottom:50px;"/>
<p:selectOneMenu value="#{productBean.productCategoryId}" id="pFilter" >
<f:selectItem itemLabel="--All--" itemValue="all" noSelectionOption="false"/>
<f:selectItems value="#{productCategoryBean.categoriesList}" var="category"
itemLabel="#{category.productCategoryName}"
itemValue="#{category.productCategoryId}" />
<p:ajax update=":productsForm:productsTable" event="change" listener="#{productBean.filterProducts}" />
</p:selectOneMenu>
</div> <!-- /widget-header -->
<div class="widget-content">
<p:dataTable id="productsTable" value="#{productBean.products}" var="products" rowIndexVar="rowIndex"
paginator="true" rows="10" paginatorPosition="bottom"
paginatorTemplate="{FirstPageLink} {PreviousPageLink} {CurrentPageReport} {NextPageLink} {LastPageLink}" widgetVar="dt_products">
<p:column headerText="S.No">#{rowIndex+1}</p:column>
<p:column headerText="Product Name">#{products.name}</p:column>
<p:column headerText="Product Code">#{products.code}</p:column>
<p:column headerText="Price">#{products.price}</p:column>
</p:dataTable>
</div> <!-- /widget-content -->
</div>
</h:form>
<br></br>
</ui:define>
</ui:composition>
</h:body>
</html>
and here is my bean, ProductCategoryBean.java:
#Named(value = "productCategoryBean")
#Scope("session")
public class ProductCategoryBean
{
private java.util.List<ProductCategory> categoriesList;
public java.util.List<ProductCategory> getCategoriesList()
{
categoriesList.removeAll(Collections.singleton(null));
return categoriesList;
}
public void setCategoriesList(java.util.List<ProductCategory> categoriesList)
{
this.categoriesList = categoriesList;
}
}
Am Initializing categories list while Login in at LoginBean.java
#Named(value = "loginBean")
#Scope("session")
public class LoginBean {
#Inject
private UserService userService;
#Inject
private StocktrackService stocktrackService;
#Inject
private MenuController menuController;
#Inject
private CheckOut checkOut;
#Inject
private ProductCategoryBean categoryBean;
#Inject
private ProductsBean productsBean;
private String userName;
private String password;
private String statusMessage;
HttpSession session = (HttpSession) FacesContext.getCurrentInstance().getExternalContext().getSession(true);
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getStatusMessage() {
return statusMessage;
}
public void setStatusMessage(String statusMessage) {
this.statusMessage = statusMessage;
}
public String login() throws EncryptionException, ServiceException
{
StringEncrypter se = new StringEncrypter("DES");
String encpassword = se.encrypt(getPassword());
UserAccount userAccount = userService.validateLogin(userName,
encpassword);
if (userAccount == null) {
statusMessage = "The username or password is incorrect.";
return "login.xhtml";
}
session.setAttribute("UserAccount", userAccount);
statusMessage = "";
menuController.setTopmenu(menuLoader(userAccount));
checkOut.setUserId(userAccount.getUserId());
checkOut.setUsername(userAccount.getUserName());
checkOut.setUserAccount(userAccount);
//setting category list of ProductCategoryBean
categoryBean.setCategoriesList(stocktrackService.getProductCategory());
//setting product list of ProductListBean
productsBean.setProducts(stocktrackService.getProduct());
return "/pages/leave/home.xhtml?faces-redirect=true";
}
}
Am getting the following Error:
> Feb 09, 2015 1:04:54 PM
> com.sun.faces.application.view.FaceletViewHandlingStrategy
> handleRenderException SEVERE: Error Rendering
> View[/pages/order/products.xhtml] javax.faces.FacesException:
> javax.el.PropertyNotFoundException: /pages/order/products.xhtml #52,59
> itemLabel="#{category.productCategoryName}": Property
> 'productCategoryName' not found on type java.lang.String at
> javax.faces.component.UIComponentBase$AttributesMap.get(UIComponentBase.java:2364)
> at
> org.primefaces.renderkit.InputRenderer.createSelectItem(InputRenderer.java:102)
> at
> org.primefaces.renderkit.InputRenderer.getSelectItems(InputRenderer.java:86)
> at
> org.primefaces.component.selectonemenu.SelectOneMenuRenderer.encodeMarkup(SelectOneMenuRenderer.java:71)
> at
> org.primefaces.component.selectonemenu.SelectOneMenuRenderer.encodeEnd(SelectOneMenuRenderer.java:65)
> at
> javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:875)
> at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1786)
> at javax.faces.render.Renderer.encodeChildren(Renderer.java:168) at
> javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:845)
> at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1779)
> at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1782)
> at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1782)
> at
> com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:419)
> at
> com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:125)
> at
> com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:121)
> at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
The Problem is that you are already using the parameter-name category and that it refers to a String
<ui:param name="category" value="Admin" />
And then you are reusing the parameter-name in f:selectItems,
<f:selectItems value="#{productCategoryBean.categoriesList}" var="category"
itemLabel="#{category.productCategoryName}"
itemValue="#{category.productCategoryId}" />
but as it is already defined as an ui:param you are getting the given Exception. To resolve this, just use another name for the var in f:selectItems:
<f:selectItems value="#{productCategoryBean.categoriesList}" var="productCategory"
itemLabel="#{productCategory.productCategoryName}"
itemValue="#{productCategory.productCategoryId}" />

Resources