My #PostConstruct method is getting called everytime I delete the last element of a dataTable in JSF - 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" />

Related

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;
}

javax.el.MethodNotFoundException: Method not found: 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.

java.lang.NullPointerException at org.primefaces.util.ResourceUtils.getComponentResources

I'm using PF6.0 and Wildfly 10 and my web app in some point needs to build some quite big grid of p:inplace objects on single page. Sounds easy.
The problem: when my grid is too big any ajax request ends with error.
To reproduce this problem I have working example:
The page test.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://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui">
<h:head>
<title>Test</title>
</h:head>
<h:body>
<h:form>
<!--it's a part of something bigger so this part is in outputPanel-->
<p:outputPanel id="details">
<h:outputText value="Size: #{backBean.size}" />
<p:panelGrid>
<!--btw. why it forces me to set all of this variables at p.repeat?-->
<p:repeat value="#{backBean.content}"
var="_row"
offset="0"
step="1"
size="#{backBean.content.size()}"
varStatus="_rowStatus" >
<p:row>
<p:repeat value="#{_row}"
var="_cell"
offset="0"
step="1"
size="#{_row.size()}"
varStatus="_rowStatus" >
<p:column>
<p:inplace editor="true">
<f:facet name="output">
<h:outputText value="#{_cell.output}" />
</f:facet>
<f:facet name="input">
<!--in real example it will be more complex with checkboxes, selectonemenu etc-->
<h:outputText value="First:" />
<p:inputText value="#{_cell.something}" />
<br />
<h:outputText value="Second:" />
<p:inputText value="#{_cell.another}" />
</f:facet>
</p:inplace>
</p:column>
</p:repeat>
</p:row>
</p:repeat>
</p:panelGrid>
</p:outputPanel>
<p:commandButton value="more" update="details" actionListener="#{backBean.weNeedMore}" />
</h:form>
</h:body>
</html>
Backing bean:
package com.test;
import javax.inject.Named;
import javax.enterprise.context.SessionScoped;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.PostConstruct;
#Named(value = "backBean")
#SessionScoped
public class BackBean implements Serializable {
private List<List<CellContent>> content;
private int size;
/**
* Creates a new instance of BackBean
*/
public BackBean() {
}
private void build() {
content = new ArrayList<>();
for(int i=0;i<size;i++) {
List<CellContent> row = new ArrayList<>();
for(int j=0;j<size;j++) {
CellContent cell = new CellContent();
row.add(cell);
}
content.add(row);
}
}
#PostConstruct
public void init() {
size = 10;
//create first content
build();
}
public void weNeedMore() {
//increase until we get error after click.
size = size + 10;
build();
}
//plain getters & setters
public List<List<CellContent>> getContent() {
return content;
}
public void setContent(List<List<CellContent>> content) {
this.content = content;
}
public int getSize() {
return size;
}
public void setSize(int size) {
this.size = size;
}
}
and one class that holds my objects:
package com.test;
public class CellContent {
private String something = "";
private String another = "";
private String output = "click_me";
public CellContent() {
}
//some dummy update based on inputs
private void update() {
if(!something.equals(""))
output = something;
if(!another.equals(""))
output = "another: " + another;
}
//those two setters update the object
public void setSomething(String something) {
this.something = something;
update();
}
public void setAnother(String another) {
this.another = another;
update();
}
//rest are plain get&seters
public String getSomething() {
return something;
}
public String getAnother() {
return another;
}
public String getOutput() {
return output;
}
public void setOutput(String output) {
this.output = output;
}
}
When grid of my objects are "small" like 10x10 or 20x20 it works - I can click and update any cell.
But increasing size up to 30 (by hitting more button) leads to this error when I click anything:
09:47:13,602 ERROR [io.undertow.request] (default task-89) UT005023: Exception handling request to /myapp/test.xhtml: javax.servlet.ServletException
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:671)
at io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:85)
at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:129)
at org.primefaces.webapp.filter.FileUploadFilter.doFilter(FileUploadFilter.java:100)
at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:60)
at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131)
at io.undertow.servlet.handlers.FilterHandler.handleRequest(FilterHandler.java:84)
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.AuthenticationConstraintHandler.handleRequest(AuthenticationConstraintHandler.java:51)
at io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:46)
at io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:64)
at io.undertow.servlet.handlers.security.ServletSecurityConstraintHandler.handleRequest(ServletSecurityConstraintHandler.java:56)
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:284)
at io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:263)
at io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:81)
at io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:174)
at io.undertow.server.Connectors.executeRootHandler(Connectors.java:202)
at io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:793)
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: java.lang.NullPointerException
at org.primefaces.util.ResourceUtils.getComponentResources(ResourceUtils.java:66)
at org.primefaces.context.PrimePartialResponseWriter.startMetadataIfNecessary(PrimePartialResponseWriter.java:280)
at org.primefaces.context.PrimePartialResponseWriter.startError(PrimePartialResponseWriter.java:107)
at com.sun.faces.context.AjaxExceptionHandlerImpl.handlePartialResponseError(AjaxExceptionHandlerImpl.java:203)
at com.sun.faces.context.AjaxExceptionHandlerImpl.handle(AjaxExceptionHandlerImpl.java:127)
at javax.faces.context.ExceptionHandlerWrapper.handle(ExceptionHandlerWrapper.java:100)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:119)
at com.sun.faces.lifecycle.RestoreViewPhase.doPhase(RestoreViewPhase.java:123)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:198)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:658)
... 34 more
Any idea what's happen? Is there any parameter I could adjust to avoid this error? Or any other solution (my current workaround is using datagrid with pagination).
FOUND IT ;)
I switched back to PF 5.3 to check if it's PrimeFaces issue.
There is no p:repeat # PF5.3 so I switched to ui:repeat.
Same was here but error message finally tells what's going on:
10:37:58,508 SEVERE [javax.enterprise.resource.webcontainer.jsf.context] (default task-44) java.lang.IllegalStateException: UT000047: The number of parameters exceeded the maximum of 1000
at io.undertow.server.handlers.form.FormData.add(FormData.java:78)
at io.undertow.server.handlers.form.FormData.add(FormData.java:68)
All what I need to do is update max-parameters value at http-listener in standalone configuration:
<subsystem xmlns="urn:jboss:domain:undertow:3.0">
<buffer-cache name="default"/>
<server name="default-server">
<http-listener name="default" max-parameters="10000" socket-binding="http" redirect-socket="https"/>
(found it at https://developer.jboss.org/thread/241526)

I can't sort dataTable in primefaces 3.5

I want to sort a dataTable in primefaces 3.5. When I click on the column header - it seems to be clicked clicked (the background and the arrow changes its colour) - but the table is not sorting. Here's my code:
Bean (I also tried putting the code from #PostConstruct to the constructor, but then I get NullPointerException):
package view;
import entity.Klient;
import facade.KlientFacade;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.ejb.EJB;
import javax.inject.Named;
import javax.enterprise.context.Dependent;
import javax.faces.bean.ViewScoped;
import static util.Messages.addFlashMessage;
#Named(value = "manageClient")
#Dependent
#ViewScoped
public class ManageClient implements Serializable {
private List<Klient> clientList;
#EJB
private KlientFacade klientFacade;
public List<Klient> returnClientList(){
return getKlientFacade().findAll();
}
#PostConstruct
public void init(){
clientList = new ArrayList<>();
clientList = returnClientList();
}
public ManageClient() {
}
public String removeClient(Klient klient){
addFlashMessage("Klient ["+klient.getLogin()+"] został usunięty.");
getKlientFacade().remove(klient);
return "manage";
}
public List<Klient> getClientList() {
return clientList;
}
public void setClientList(List<Klient> clientList) {
this.clientList = clientList;
}
public KlientFacade getKlientFacade() {
return klientFacade;
}
public void setKlientFacade(KlientFacade klientFacade) {
this.klientFacade = klientFacade;
}
}
xhtml:
<p:dataTable paginator="true" rows="10" var="klient" value="#{manageClient.clientList}">
<p:column sortBy="#{klient.idKlienta}" headerText="ID">
<h:outputText value="#{klient.idKlienta}" />
</p:column>
<p:column sortBy="#{klient.imie}" headerText="Imię">
<h:outputText value="#{klient.imie}" />
</p:column>
<p:column sortBy="#{klient.nazwisko}" headerText="Nazwisko">
<h:outputText value="#{klient.nazwisko}" />
</p:column>
<p:column sortBy="#{klient.login}" headerText="Login">
<h:outputText value="#{klient.login}" />
</p:column>
<p:column sortBy="#{klient.haslo}" headerText="Hasło">
<h:outputText value="#{klient.haslo}" />
</p:column>
<p:column sortBy="#{klient.idTypu.typ}" headerText="Typ">
<h:outputText value="#{klient.idTypu.typ}" />
</p:column>
<p:column headerText="Usuń">
<h:commandButton value="Usuń" action="#{manageClient.removeClient(klient)}" />
</p:column>
</p:dataTable>
EDIT:
When I put the code from #PostConstruct to the constructor, I get NullPointerException, stack trace:
com.sun.faces.mgbean.ManagedBeanCreationException: Cant instantiate class: view.ManageClient.
at com.sun.faces.mgbean.BeanBuilder.newBeanInstance(BeanBuilder.java:191)
at com.sun.faces.mgbean.BeanBuilder.build(BeanBuilder.java:100)
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 com.sun.el.parser.AstIdentifier.getValue(AstIdentifier.java:116)
at com.sun.el.parser.AstValue.getBase(AstValue.java:151)
at com.sun.el.parser.AstValue.getValue(AstValue.java:200)
at com.sun.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:226)
at org.jboss.weld.el.WeldValueExpression.getValue(WeldValueExpression.java:50)
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.datatable.DataTable.getValue(DataTable.java:867)
at org.primefaces.component.api.UIData.getDataModel(UIData.java:579)
at javax.faces.component.UIData.getRowCount(UIData.java:356)
at org.primefaces.component.api.UIData.calculateFirst(UIData.java:157)
at org.primefaces.component.datatable.DataTableRenderer.encodeMarkup(DataTableRenderer.java:176)
at org.primefaces.component.datatable.DataTableRenderer.encodeEnd(DataTableRenderer.java:82)
at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:924)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1863)
at javax.faces.render.Renderer.encodeChildren(Renderer.java:176)
at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:894)
at org.primefaces.renderkit.CoreRenderer.renderChild(CoreRenderer.java:59)
at org.primefaces.renderkit.CoreRenderer.renderChildren(CoreRenderer.java:47)
at org.primefaces.component.layout.LayoutUnitRenderer.encodeEnd(LayoutUnitRenderer.java:51)
at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:924)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1863)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1859)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1859)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1859)
at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:443)
at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:131)
at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:337)
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.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:357)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:260)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:188)
at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:191)
at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:168)
at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:189)
at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:288)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:206)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:136)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:114)
at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)
at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:838)
at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:113)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:115)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:55)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:135)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:564)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:544)
at java.lang.Thread.run(Thread.java:722)
Caused by: java.lang.NullPointerException
at view.ManageClient.returnClientList(ManageClient.java:31)
at view.ManageClient.<init>(ManageClient.java:36)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:525)
at java.lang.Class.newInstance0(Class.java:374)
at java.lang.Class.newInstance(Class.java:327)
at com.sun.faces.mgbean.BeanBuilder.newBeanInstance(BeanBuilder.java:186)
... 68 more
I simplified your problem in order to get a compilable and testable SSCCE example which works perfectly for me and runs in a basic servlet container (Mojarra JSF impl 2.1.25, Primefaces 3.5 and Tomcat 7). I changed some of your annotations because I don't have a Java EE container or CDI available. That's what works for me:
index.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://java.sun.com/jsf/facelets"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.org/ui">
<h:head>
</h:head>
<h:body>
<f:view>
<h:form>
<p:dataTable paginator="true" rows="10" var="klient"
value="#{manageClient.clientList}">
<p:column sortBy="#{klient.imie}" headerText="Imię">
<h:outputText value="#{klient.imie}" />
</p:column>
<p:column sortBy="#{klient.login}" headerText="Login">
<h:outputText value="#{klient.login}" />
</p:column>
</p:dataTable>
</h:form>
</f:view>
</h:body>
</html>
ManageClient.java
package com.mycompany;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
#ManagedBean
#ViewScoped
public class ManageClient implements Serializable {
//Created my own Klient class which only has two properties
public class Klient {
private String imie;
private String login;
public String getImie() {
return imie;
}
public void setImie(String imie) {
this.imie = imie;
}
public String getLogin() {
return login;
}
public void setLogin(String login) {
this.login = login;
}
}
private List<Klient> clientList;
public List<Klient> returnClientList() {
//changed your data access object by my own list
Klient k = new Klient();
k.setImie("imi1");
k.setLogin("log1");
Klient k2 = new Klient();
k2.setImie("-imi1");
k2.setLogin("-log1");
return Arrays.asList(k, k2);
}
public ManageClient() {
clientList = new ArrayList<Klient>();
clientList = returnClientList();
}
public String removeClient(Klient klient) {
return "manage";
}
public List<Klient> getClientList() {
return clientList;
}
public void setClientList(List<Klient> clientList) {
this.clientList = clientList;
}
}
Which basically suggests the problem is not about Primefaces in this case. I tested it with latest versions of FF, Chrome and IE. If you're working with previous versions that could be the problem, Primefaces 3.5 is no longer supporting IE 7 for example.

DataTable not displaying info JSF

I'm having trouble with a DataTable.
I have a SelectOneMenu component with 3 options. Every option should render a DataTable with different information.
My xhtml page is working (I tested it with a simple code), but it seems that my backing bean is not working as I was expecting. When I run the page throws an error message.
My xhtml looks like
<h:form>
<h:outputLabel for="reporte" value="Tipo de reporte: " />
<h:selectOneMenu id="reporte"
value="#{reportController.type}">
<f:selectItem itemLabel="Seleccione tipo de reporte..." itemValue="null" />
<f:selectItems value="#{reportController.reportType}" />
<f:ajax execute="#form" render="#form" />
</h:selectOneMenu>
<h:panelGrid id="porSistema"
rendered="#{reportController.type == 'Por sistema'}">
<h:dataTable value="#{reportController.list}" var="item"
border="1">
<h:column>
<f:facet name="header">
<h:outputText value="Nombre del archivo"/>
</f:facet>
<h:outputText value="#{item.fileName}"/>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="Registros correctos"/>
</f:facet>
<h:outputText value="#{item.registersOk}"/>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="Registros incorrectos"/>
</f:facet>
<h:outputText value="#{item.registersNok}"/>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="Registros procesados"/>
</f:facet>
<h:outputText value="#{item.registers}"/>
</h:column>
</h:dataTable>
</h:panelGrid>
</h:form>
The bean is
#ManagedBean
#ViewScoped
public class ReportController {
List<Object> list = new ArrayList<Object>();
String type;
String[] reportType = new String[]{"Por sistema",
"Por programa y componente",
"Por estatus de pago"};
#PostConstruct
public void init() {
if (type.equals("Por sistema")) {
list.add(new ReporteSistema("A", "B", "C", "D"));
} else if (type.equals("Por programa y componente")) {
list.add(new ReporteProgramaComponenteA("E", "F", "G", "H", "I", "J"));
} else if (type.equals("Por estatus de pago")) {
list.add(new ReporteProgramaComponenteB("K", "L", "M", "N"));
}
}
public String[] getReportType() {
return reportType;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public List<Object> getList() {
return list;
}
public void setList(List<Object> list) {
this.list = list;
}
}
and the stack trace is
com.sun.faces.mgbean.ManagedBeanCreationException: Se ha producido un error al realizar la inyección de recurso en el bean administrado reportController
at com.sun.faces.mgbean.BeanBuilder.invokePostConstruct(BeanBuilder.java:229)
at com.sun.faces.mgbean.BeanBuilder.build(BeanBuilder.java:105)
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:71)
at org.apache.el.parser.AstValue.getValue(AstValue.java:147)
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:169)
at com.sun.faces.renderkit.html_basic.MenuRenderer.getCurrentSelectedValues(MenuRenderer.java:648)
at com.sun.faces.renderkit.html_basic.MenuRenderer.renderOptions(MenuRenderer.java:749)
at com.sun.faces.renderkit.html_basic.MenuRenderer.renderSelect(MenuRenderer.java:844)
at com.sun.faces.renderkit.html_basic.MenuRenderer.encodeEnd(MenuRenderer.java:298)
at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:875)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1764)
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:1757)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1760)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1760)
at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:401)
at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:131)
at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:121)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:594)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:304)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at mx.gob.sagarpa.NoCacheFilter.doFilter(NoCacheFilter.java:29)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.myfaces.webapp.filter.ExtensionsFilter.doFilter(ExtensionsFilter.java:349)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:393)
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:240)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:164)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:462)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:563)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:399)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:317)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:204)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:311)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:722)
Caused by: com.sun.faces.spi.InjectionProviderException
at com.sun.faces.vendor.WebContainerInjectionProvider.invokeAnnotatedMethod(WebContainerInjectionProvider.java:119)
at com.sun.faces.vendor.WebContainerInjectionProvider.invokePostConstruct(WebContainerInjectionProvider.java:99)
at com.sun.faces.mgbean.BeanBuilder.invokePostConstruct(BeanBuilder.java:223)
... 56 more
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.GeneratedMethodAccessor85.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at com.sun.faces.vendor.WebContainerInjectionProvider.invokeAnnotatedMethod(WebContainerInjectionProvider.java:117)
... 58 more
Caused by: java.lang.NullPointerException
at mx.gob.sagarpa.beans.ReportController.init(ReportController.java:32)
... 62 more
You seem to be misunderstanding the purpose of the #PostConstruct. This annotation is to be used to specify methods which are to be executed directly after bean's construction. This annotation allows you to execute code after injection of managed properties specified by #ManagedProperty and all other dependencies such as #Inject or #EJB. Those injected properties and dependencies are namely not available inside the bean's constructor (a fully constructed instance of the bean has to be obtained first before all injections can take place, of course). The #PostConstruct of a view scoped bean is not invoked when you send an ajax request on it. It's only invoked when you initially open the page in the browser.
You actually want to invoke that method when the ajax event is fired. You need to change the view and bean as follows in order to get it to work.
<h:selectOneMenu id="reporte" value="#{reportController.type}">
<f:selectItem itemLabel="Seleccione tipo de reporte..." itemValue="null" />
<f:selectItems value="#{reportController.reportType}" />
<f:ajax execute="#form" listener="#{reportController.changeType}" render="#form" />
</h:selectOneMenu>
(note the new listener attribute)
and
public void changeType() { // No, do not put #PostConstruct on it!
if ("Por sistema".equals(type)) {
list.add(new ReporteSistema("A", "B", "C", "D"));
} else if ("Por programa y componente".equals(type)) {
list.add(new ReporteProgramaComponenteA("E", "F", "G", "H", "I", "J"));
} else if ("Por estatus de pago".equals(type)) {
list.add(new ReporteProgramaComponenteB("K", "L", "M", "N"));
}
}
Also note that I swapped the both sides of the equals() so that you can guarantee that it will never throw NPE. If the type happen to be null, then it will simply be compared as non-equal. When you actually invoked equals() on something which is null, you will guaranteed get a NPE (that's what the whole exception stands for! see also its javadoc).
Your problem is obviously stated in the stacktrace. Your init method threw a NullPointerException. To be precise, your type variable was not given any value. You cannot call equals function with it.

Resources