NullPointerException with SelectItem

I receive the following error whether I select an item or not.

[11/15/05 8:52:05:570 EST] 0000003a WebAppESRVE0026E: [Servlet Error]-[Faces Servlet]: java.lang.NullPointerException

at javax.faces.model.SelectItem.setValue(SelectItem.java:234)

at javax.faces.model.SelectItem.<init>(SelectItem.java:118)

at javax.faces.component.SelectItemsIterator.next(SelectItemsIterator.java:106)

at javax.faces.component.UISelectOne.matchValue(UISelectOne.java:140)

at javax.faces.component.UISelectOne.validate(UISelectOne.java:113)

at javax.faces.component.UIInput.executeValidate(UIInput.java:796)

at javax.faces.component.UIInput.processValidators(UIInput.java:412)

at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:940)

at javax.faces.component.UIForm.processValidators(UIForm.java:165)

at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:940)

at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:940)

at javax.faces.component.UIViewRoot.processValidators(UIViewRoot.java:377)

at com.sun.faces.lifecycle.ProcessValidationsPhase.execute(ProcessValidationsPhase.java:80)

at com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:201)

at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:91)

at javax.faces.webapp.FacesServlet.service(FacesServlet.java:197)

at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1212)

at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:629)

at com.ibm.ws.webcontainer.webapp.WebApp.handleRequest(WebApp.java:2837)

at com.ibm.ws.webcontainer.webapp.WebGroup.handleRequest(WebGroup.java:220)

at com.ibm.ws.webcontainer.VirtualHost.handleRequest(VirtualHost.java:204)

at com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java:1681)

at com.ibm.ws.webcontainer.channel.WCChannelLink.ready(WCChannelLink.java:77)

at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleDiscrimination(HttpInboundLink.java:421)

at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleNewInformation(HttpInboundLink.java:367)

at com.ibm.ws.http.channel.inbound.impl.HttpICLReadCallback.complete(HttpICLReadCallback.java:94)

at com.ibm.ws.tcp.channel.impl.WorkQueueManager.requestComplete(WorkQueueManager.java:548)

at com.ibm.ws.tcp.channel.impl.WorkQueueManager.attemptIO(WorkQueueManager.java(Compiled Code))

at com.ibm.ws.tcp.channel.impl.WorkQueueManager.workerRun(WorkQueueManager.java:934)

at com.ibm.ws.tcp.channel.impl.WorkQueueManager$Worker.run(WorkQueueManager.java:1021)

at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java(Compiled Code))

From the message, I assume the problem is in my jsp, but I cannot figure out what the problem is.

<h:panelGrid styleClass="panelGrid" id="giGrid1" columns="2">

<h:outputText styleClass="outputText" id="salesrep" value="#{constants.sales_rep}"></h:outputText>

<h:selectOneMenu styleClass="selectOneMenu" id="cpslsrep" value="#{gi.cpslsrep}" required="true">

<f:selectItem itemValue="#{constants.sov}"

itemLabel="#{constants.select_one}" />

<f:selectItems value="#{selectitems.applData.salesReps.name.name.toArray}" />

</h:selectOneMenu>

<h:outputText styleClass="outputText" id="salesanalyst" value="#{constants.sales_analyst}"></h:outputText>

<h:selectOneMenu styleClass="selectOneMenu" id="cpslsanl" value="#{gi.cpslsanl}">

<f:selectItems value="#{selectitems.applData.salesAnalysts.name.name.toArray}" />

</h:selectOneMenu>

<h:outputText styleClass="outputText" id="opptype" value="#{constants.opp_type}"></h:outputText>

<h:selectOneMenu styleClass="selectOneMenu" id="cpotype" value="#{gi.cpotype}">

<f:selectItems value="#{selectitems.applData.oppTypes.desc.desc.toArray}" />

</h:selectOneMenu>

<h:outputText styleClass="outputText" id="custnm" value="#{constants.cust_nm}"></h:outputText>

<h:inputText styleClass="inputText" id="cpcuname" value="#{gi.cpcuname}" size="30" required="true">

<f:validateLength minimum="1" maximum="25"></f:validateLength>

</h:inputText>

</h:panelGrid>

[4505 byte] By [lewkima] at [2007-10-2 5:14:41]
# 1

My guess it's at the name.name.toArray in the EL expression.

If I remember correctly the above will tranlate into getName().getName().getToArray().

Will that work for you? I find it easier with selectItems to return a List of SelectItem's.

For example you could add method List<SelectItem> getSalesAnalysts() in applData and adjust your EL expression accordingly.

Looma at 2007-7-16 1:17:10 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2

I am not understanding where "#{selectitems.applData.salesAnalysts.name.name.toArray}" is the problem because when my application runs, the proper values are displayed (see below):

<table id="form1:giGrid1" class="panelGrid">

<tbody>

<tr>

<td><span id="form1:salesrep" class="outputText">Sales Rep:</span></td>

<td><select id="form1:cpslsrep" name="form1:cpslsrep" class="selectOneMenu" size="1">

<option value="S">Select One</option>

<option value="RANDY DORN">RANDY DORN</option>

<option value="ROGER DOTSON">ROGER DOTSON</option>

<option value="ALAN EDWARDS">ALAN EDWARDS</option>

<option value="JOHN GREEN">JOHN GREEN</option>

<option value="JACK HOGELAND">JACK HOGELAND</option>

<option value="PATRICIA HUTCHINSON">PATRICIA HUTCHINSON</option>

<option value="JOE MCKENNA">JOE MCKENNA</option>

<option value="MICKY MILLER">MICKY MILLER</option>

<option value="DAVID MORSE">DAVID MORSE</option>

<option value="TOM MUELLER">TOM MUELLER</option>

<option value="MARK MUMFORD">MARK MUMFORD</option>

<option value="CHIP NORFORD, JR.">CHIP NORFORD, JR.</option>

<option value="MARY PALMER">MARY PALMER</option>

</select></td>

</tr>

<tr>

<td><span id="form1:salesanalyst" class="outputText">Sales Analyst:</span></td>

<td><select id="form1:cpslsanl" name="form1:cpslsanl" class="selectOneMenu" size="1">

<option value="TONY DREYHAUPT">TONY DREYHAUPT</option>

<option value="CRAIG DURHAM">CRAIG DURHAM</option>

<option value="PAMELA FISHER">PAMELA FISHER</option>

<option value="LARRY GOLDSTEIN">LARRY GOLDSTEIN</option>

<option value="ED KERN">ED KERN</option>

<option value="MATT LONG">MATT LONG</option>

<option value="CONNIE NICHOLS">CONNIE NICHOLS</option>

<option value="CARLENE TUCKER">CARLENE TUCKER</option>

<option value="FLORENCE WARUGA">FLORENCE WARUGA</option>

<option value="PETER YANN">PETER YANN</option>

</select></td>

</tr>

<tr>

<td><span id="form1:opptype" class="outputText">Opportunity Type:</span></td>

<td><select id="form1:cpotype" name="form1:cpotype" class="selectOneMenu" size="1"><option value="NO DIV">NO DIV</option>

<option value="REEFER">REEFER</option>

<option value="CHARLOTTE ">CHARLOTTE </option>

<option value="DEDICATED ">DEDICATED </option>

<option value="TEAM EXPED">TEAM EXPED</option>

<option value="OTR">OTR</option>

</select></td>

</tr>

<tr>

<td><span id="form1:custnm" class="outputText">Customer Name:</span></td>

<td><input id="form1:cpcuname" type="text" name="form1:cpcuname" class="inputText" size="30" /></td>

</tr>

</tbody>

</table>

lewkima at 2007-7-16 1:17:10 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3
If you use request scoped managed beans for selectItem or selectItems,try to use session scoped managed beans.
yuki.yoshidaa at 2007-7-16 1:17:10 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4
The managed beans scope is session.
lewkima at 2007-7-16 1:17:10 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 5

I'll explain why I doubt you use a request scoped bean.

The message seems to show that "#{constants.sov}" is null.

But, when rendering the page, the expression is not null, may be "S".

So, I guess the value changes before validation in the next request

which means the bean 'constants' is not in session scope.

yuki.yoshidaa at 2007-7-16 1:17:10 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 6

Hi, I have the same error with Websphere 6. On tomcat all works fine.

I am not using bundle. Here is my test code:

<h:selectOneMenu id="test" value="" immediate="true">

<f:selectItem itemLabel="test" itemValue="1"/>

</h:selectOneMenu>

Anyone knows where is the problem ?

Thanks a lot.

JaneSoaresa at 2007-7-16 1:17:10 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...