Search code examples
jsfprimefaceswebsphere

Ajax in SelectOneMenu resulting in NullPointerException


I have a web application which runs perfectly fine on Wildfly9, but gives me a headache on Websphere8:

<h:form id="productsForm">
    <p:selectOneMenu id="productSelector"
        value="#{productManager.productName}" style="width: 100%;">
        <f:selectItem value="#{null}" />
        <f:selectItems value="#{productManager.products}"
            var="product" itemLabel="#{product.productName}"
            itemValue="#{product.productName}" />
        <p:ajax event="change" update="editProductButton" />
    </p:selectOneMenu>
    <p:button id="editProductButton"
        value="Edit Product" outcome="/pages/products/productDetails"
        style="float: left; margin-left: 10px;" disabled="#{productManager.productName == null}">
        <f:param name="productName"
            value="#{productManager.productName}" />
    </p:button>
</h:form>

Java side:

private String productName;
private List<Product> products;


public String getProductName() {
    return this.productName;
}

public void setProductName(String productName) {
    this.productName = productName;
}
public List<Product> getProducts() {
    if(null == this.products){
        this.products = this.productService.findAll();
    }
    return this.products;
}

If an item in the selectOneMenu is selected, I want the "edit" button to be enabled. On Wildfly everything is fine, on websphere the following exception occurs when I select an item:

com.ibm.ws.webcontainer.servlet.ServletWrapper service SRVE0014E: Uncaught service() exception root cause Faces Servlet: javax.servlet.ServletException
        at javax.faces.webapp.FacesServlet.service(FacesServlet.java:221)
        at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1224)
        at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:774)
[...]
Caused by: java.lang.NullPointerException
        at javax.faces.component._SelectItemsIterator.hasNext(_SelectItemsIterator.java:124)
        at javax.faces.component._SelectItemsUtil.matchValue(_SelectItemsUtil.java:48)
        at javax.faces.component.UISelectOne.validateValue(UISelectOne.java:77)
        at org.primefaces.component.selectonemenu.SelectOneMenu.validateValue(SelectOneMenu.java:282)
        at javax.faces.component.UIInput.validate(UIInput.java:583)
        at javax.faces.component.UIInput.processValidators(UIInput.java:247)
        at org.apache.myfaces.context.servlet.PartialViewContextImpl$PhaseAwareVisitCallback.visit(PartialViewContextImpl.java:533)
        at org.apache.myfaces.component.visit.PartialVisitContext.invokeVisitCallback(PartialVisitContext.java:207)
        at javax.faces.component.UIComponent.visitTree(UIComponent.java:773)
        at javax.faces.component.UIComponentBase.visitTree(UIComponentBase.java:1007)
        at javax.faces.component.UIForm.visitTree(UIForm.java:269)
        at javax.faces.component.UIComponent.visitTree(UIComponent.java:793)
        at javax.faces.component.UIComponentBase.visitTree(UIComponentBase.java:1007)
        at javax.faces.component.UIComponent.visitTree(UIComponent.java:793)
        at javax.faces.component.UIComponentBase.visitTree(UIComponentBase.java:1007)
        at org.apache.myfaces.context.servlet.PartialViewContextImpl.processPartialExecute(PartialViewContextImpl.java:362)
        at org.apache.myfaces.context.servlet.PartialViewContextImpl.processPartial(PartialViewContextImpl.java:342)
        at org.primefaces.context.PrimePartialViewContext.processPartial(PrimePartialViewContext.java:60)
        at javax.faces.component.UIViewRoot$ProcessValidatorPhaseProcessor.process(UIViewRoot.java:1394)
        at javax.faces.component.UIViewRoot._process(UIViewRoot.java:1282)
        at javax.faces.component.UIViewRoot.processValidators(UIViewRoot.java:758)
        at org.apache.myfaces.lifecycle.ProcessValidationsExecutor.execute(ProcessValidationsExecutor.java:34)
        at org.apache.myfaces.lifecycle.LifecycleImpl.executePhase(LifecycleImpl.java:171)
        at org.apache.myfaces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
        at javax.faces.webapp.FacesServlet.service(FacesServlet.java:189)
        ... 33 more

Any ideas why this is happening or how to fix/workaround this?


Solution

  • WebSphere uses MyFaces as JSF implementation and Wildfly uses Mojorra. Thats why you have different results.

    You have defined a null value as selectItem. This breaks the code. Use instead an empty String. Or another solution would be to change the JSF implementation.

    Also consider your development environment should always be as close as possible to the productive/final one.