Search code examples
jsfjsf-2nullpointerexceptionmyfaces

java.lang.NullPointerException at javax.faces.component._SelectItemsUtil.matchValue


After endless reading of posts here, especially answers from @BalusC I still couldn't solve the following problem.

I have the following composite component:

<ui:component xmlns="http://www.w3.org/1999/xhtml"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:cc="http://java.sun.com/jsf/composite"
    xmlns:p="http://primefaces.org/ui">
    <cc:interface componentType="testComponent">
        <!-- Define component attributes here -->
         <cc:attribute name="clientId"/>
    </cc:interface>


    <cc:implementation>
        <div id="#{cc.clientId}">

        <div id="test" style="min-width: 310px; height: 500px; margin: 0 auto">1</div>

            <script type="text/javascript">

                    $('#test').text('#{cc.tagList}');
                    alert('#{cc.tagList}');

            </script>
        </div>
    </cc:implementation>
</ui:component>

This is implementation of @FacesComponent("testComponent')

@FacesComponent("testComponent")
public class TestComponent extends UINamingContainer{
    public String getTagList(){
        List<Tag> tags = (List<Tag>)getAttributes().get("tags");
        String result = "Tags are: ";
        for(Tag tag : tags){
            result += tag.getName();
        }
        return result;
    }
}

And this is *.jsf page from which I trying to use this custom component

<h:form>
    <p:selectCheckboxMenu id="tags_selector"
                            converter="#{tagConverter}" 
                            value="#{tagsRequestsBean.selectedTags}" label="Tag"
                              filter="true" 
                              filterMatchMode="startsWith" 
                              panelStyle="width:250px">
                     <f:selectItems value="#{tagsRequestsBean.tags}" var="tag" itemValue="#{tag}" itemLabel="#{tag.name}" />
                      <f:ajax  event="change" render="test"></f:ajax>
             </p:selectCheckboxMenu>

        <hc:test_component id="test" tags="#{tagsRequestsBean.selectedTags}"></hc:test_component>


        </h:form>

what am trying to do is to update testComponent when I select tags by p:selectCheckboxMenu, but when I perform selection I get the following error:

javax.faces.FacesException: java.lang.NullPointerException
    at org.apache.myfaces.shared_impl.context.ExceptionHandlerImpl.wrap(ExceptionHandlerImpl.java:241)
    at org.apache.myfaces.shared_impl.context.ExceptionHandlerImpl.handle(ExceptionHandlerImpl.java:156)
    at org.apache.myfaces.lifecycle.LifecycleImpl.executePhase(LifecycleImpl.java:192)
    at org.apache.myfaces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:119)
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:189)
    at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1230)
    at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:779)
    at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:478)
    at com.ibm.ws.webcontainer.servlet.ServletWrapperImpl.handleRequest(ServletWrapperImpl.java:178)
    at com.ibm.ws.webcontainer.filter.WebAppFilterManager.invokeFilters(WebAppFilterManager.java:1071)
    at com.ibm.ws.webcontainer.servlet.CacheServletWrapper.handleRequest(CacheServletWrapper.java:87)
    at com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java:914)
    at com.ibm.ws.webcontainer.WSWebContainer.handleRequest(WSWebContainer.java:1662)
    at com.ibm.ws.webcontainer.channel.WCChannelLink.ready(WCChannelLink.java:200)
    at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleDiscrimination(HttpInboundLink.java:453)
    at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleNewRequest(HttpInboundLink.java:515)
    at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.processRequest(HttpInboundLink.java:306)
    at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.ready(HttpInboundLink.java:277)
    at com.ibm.ws.tcp.channel.impl.NewConnectionInitialReadCallback.sendToDiscriminators(NewConnectionInitialReadCallback.java:214)
    at com.ibm.ws.tcp.channel.impl.NewConnectionInitialReadCallback.complete(NewConnectionInitialReadCallback.java:113)
    at com.ibm.ws.tcp.channel.impl.AioReadCompletionListener.futureCompleted(AioReadCompletionListener.java:175)
    at com.ibm.io.async.AbstractAsyncFuture.invokeCallback(AbstractAsyncFuture.java:217)
    at com.ibm.io.async.AsyncChannelFuture.fireCompletionActions(AsyncChannelFuture.java:161)
    at com.ibm.io.async.AsyncFuture.completed(AsyncFuture.java:138)
    at com.ibm.io.async.ResultHandler.complete(ResultHandler.java:204)
    at com.ibm.io.async.ResultHandler.runEventProcessingLoop(ResultHandler.java:775)
    at com.ibm.io.async.ResultHandler$2.run(ResultHandler.java:905)
    at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1702)
Caused by: java.lang.NullPointerException
    at javax.faces.component._SelectItemsUtil.matchValue(_SelectItemsUtil.java:67)
    at javax.faces.component.UISelectMany.validateValue(UISelectMany.java:366)
    at javax.faces.component.UIInput.validate(UIInput.java:627)
    at javax.faces.component.UISelectMany.validate(UISelectMany.java:392)
    at javax.faces.component.UIInput.processValidators(UIInput.java:281)
    at org.apache.myfaces.context.servlet.PartialViewContextImpl$PhaseAwareVisitCallback.visit(PartialViewContextImpl.java:550)
    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:1051)
    at javax.faces.component.UIComponent.visitTree(UIComponent.java:793)
    at javax.faces.component.UIComponentBase.visitTree(UIComponentBase.java:1051)
    at javax.faces.component.UIForm.visitTree(UIForm.java:290)
    at javax.faces.component.UIComponent.visitTree(UIComponent.java:793)
    at javax.faces.component.UIComponentBase.visitTree(UIComponentBase.java:1051)
    at javax.faces.component.UIComponent.visitTree(UIComponent.java:793)
    at javax.faces.component.UIComponentBase.visitTree(UIComponentBase.java:1051)
    at org.apache.myfaces.context.servlet.PartialViewContextImpl.processPartialExecute(PartialViewContextImpl.java:379)
    at org.apache.myfaces.context.servlet.PartialViewContextImpl.processPartial(PartialViewContextImpl.java:359)
    at org.primefaces.context.PrimePartialViewContext.processPartial(PrimePartialViewContext.java:60)
    at javax.faces.context.PartialViewContextWrapper.processPartial(PartialViewContextWrapper.java:88)
    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:172)
    ... 25 more

What am I doing wrong?

UPDATE: I'm using JSF 2.0 Apache MyFaces 2.0.3 on Websphere 8.0.0.9


Solution

  • As @dognose suggested in him comment it was an issue of a converter. I've implemented getAsString method, but forget to implement getAsObject method and it always returned null. So, I now fixed it and it works like it should.