1

I'm using JSF 2 (Mojarra 2.2.11) with WildFly9.0.1.

I have 3 selectOneMenus as seen below. The ajax events work fine loading data to the next one using omnifaces converter.

Problem: even if the third "Header" selectOneMenu is populated, on h:commandButton action I can't get the Header Object giving a Null in the backing bean.

I'm able to get the Module Object calling saveNewHeader method but saveNewQuestion crashes when I'm trying to access the Header Object.

From the reference: Retrieving the value of the selected item in a SelectOneMenu List, I am suspecting a queue processing issue of JSF?

How can I solve/manage it? Thank you for your time.

Console:

12:37:17,583 FATAL [javax.enterprise.resource.webcontainer.jsf.context] (default task-1) JSF1073: javax.faces.FacesException caught during processing of INVOKE_APPLICATION 5 : UIComponent-ClientId=, Message=#{questionBean.saveNewQuestion(questionBean.header)}: java.lang.NullPointerException
...

xhtml:

<ui:composition xmlns=...> 

<h:head></h:head> 

<h:body>

<h:form id="frmQuestion" > 

<h4>Add Question to Header</h4>

    <h:panelGrid columns="2">
    <h:outputLabel  value="ProductType: " />

    <h:selectOneMenu value="#{questionBean.productType}" converter="omnifaces.SelectItemsConverter">
        <f:selectItem itemValue="#{null}" itemLabel="-- select one --" />
        <f:selectItems value="#{questionBean.productTypes}" var="productType" 
            itemValue="#{productType}" itemLabel="#{productType.type}" />
        <f:ajax listener="#{questionBean.loadModules()}" render="moduleId2" />
    </h:selectOneMenu>

    <h:outputLabel  value="Module: " />

    <h:selectOneMenu id="moduleId2" value="#{questionBean.module}" converter="omnifaces.SelectItemsConverter">
        <f:selectItem itemValue="#{null}" itemLabel="-- select one --" />
        <f:selectItems value="#{questionBean.modules}" var="module" 
            itemValue="#{module}" itemLabel="#{module.moduleName}" />
        <f:ajax listener="#{questionBean.loadHeaders()}" render="headerId2" />
    </h:selectOneMenu>

    <h:outputLabel  value="Header Name: " />

        <h:selectOneMenu id="headerId2" value="#{questionBean.header}" converter="omnifaces.SelectItemsConverter">
            <f:selectItem itemValue="#{null}" itemLabel="-- select one --" />
            <f:selectItems value="#{questionBean.headers}" var="header" 
                itemValue="#{header}" itemLabel="#{header.name}" />
    </h:selectOneMenu>


</h:panelGrid>


<h:commandButton action="#{questionBean.saveNewQuestion(questionBean.header)}" value="Add New Question"  

/>



...

QuestionBean:

import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;

@ManagedBean
@ViewScoped
public class QuestionBean implements Serializable {

private List<Header> headers; // getter & setter
private Header header; // getter & setter

private List<Module> modules; // getter & setter
private Module module; // getter & setter


@PostConstruct
public void init(){

    this.productTypes = publicService.getAllproductTypes();

}

public void saveNewHeader(Module module)
{
    System.out.println(module.getModuleName()); // works fine
}

public void saveNewQuestion(Header header){

        System.out.println(header.getHeaderName()); // crashes here
}

UPDATE (after BalusC comment)

It looks like a the bean behaves like a @RequestScoped: how can this happen?

enter image description here

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
LEK
  • 83
  • 2
  • 11
  • Why do you need parameters in these methods if you got access to them in backing bean? Is your `@ViewScoped` from `javax.faces.bean` package? – Geinmachi Jan 03 '16 at 12:21
  • @Geinmachi: With or without specifying the parameter I can't access the Object or its properties in the backing bean. Yes my `@ViewScoped` is from `javax.faces.bean` (I've edited the bean). – LEK Jan 03 '16 at 12:45
  • Symptoms suggst bean is actually not view scoped and behaves like request scoped. Can you confirm this? (just debug/log the construction) – BalusC Jan 03 '16 at 18:46
  • @BalusC: You are right Legend. I've edited my question. How can this happen? I defined it as a `@ViewScoped` – LEK Jan 03 '16 at 18:58
  • Any JARs in webapp's /WEB-INF/lib? – BalusC Jan 03 '16 at 19:04
  • @BalusC: Many: primefaces, richfaces, iText.... – LEK Jan 03 '16 at 19:19
  • Make sure it doesn't contain server-provided JARs. – BalusC Jan 03 '16 at 19:25
  • @BalusC: Do you recognize a server-provided one in the below List? annotations-4.0.0.Final.jar, com.mysql.jdbc_5.1.5.jar, commons-beanutils-1.8.2.jar, commons-digester-1.7.jar, commons-logging-1.1.jar, commons.collections-3.2.1.jar, cssparser-0.9.16.jar, groovy-all-1.8.6.jar, guava-18.0.jar, humanity-1.0.10.jar, iText-2.1.7.jar, jasperreports-5.1.2.jar, omnifaces-2.2.jar, primefaces-5.3.jar, richfaces-a4j-4.5.8.Final.jar, richfaces-core-4.5.8.Final.jar, richfaces-page-fragments-4.5.8.Final.jar, richfaces-rich-4.5.8.Final.jar, sac-1.3.jar, validation-api-1.0.0.GA.jar – LEK Jan 03 '16 at 19:33
  • Only validation-api. And, on an unrealated note, mysql should actually be moved to server (as it is normally the one responsible for managing the DB connection pool). – BalusC Jan 03 '16 at 19:45
  • @BalusC: removed it. but no improvement. totally agree I'm generating japerreport with this connection. – LEK Jan 03 '16 at 19:57
  • @BalusC: Thank you for trying to troubleshoot. – LEK Jan 04 '16 at 08:33

0 Answers0