jQuery in Action, 2nd edition*
The moose likes JSF and the fly likes Noob JSF question on h:selectOneMenu item. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "Noob JSF question on h:selectOneMenu item." Watch "Noob JSF question on h:selectOneMenu item." New topic
Author

Noob JSF question on h:selectOneMenu item.

christian leclerc
Ranch Hand

Joined: Apr 08, 2008
Posts: 38
Hello guy's , im realy starting with JSF2 and I've got some problems here to figure out what happened.

Im trying to do a h:selectOneMenu on an arrayLisf of addresses and get my selected object in a property of my action bean.

Here the xhtml code :



And here my Bean's code.



And in my server log i've got this so far :

23:55:58,480 ERROR [STDERR] 16-Nov-2010 11:55:58 PM com.sun.faces.renderkit.html_basic.HtmlBasicInputRenderer getConvertedValue
SEVERE: Could not instantiate converter for type class ca.s3s.lqmanager.entities.Address: java.lang.NullPointerException
23:55:58,481 ERROR [STDERR] 16-Nov-2010 11:55:58 PM com.sun.faces.renderkit.html_basic.HtmlBasicInputRenderer getConvertedValue
SEVERE:
java.lang.NullPointerException
at com.sun.faces.renderkit.html_basic.HtmlBasicInputRenderer.getConvertedValue(HtmlBasicInputRenderer.java:125)
at com.sun.faces.renderkit.html_basic.MenuRenderer.convertSelectOneValue(MenuRenderer.java:198)
at com.sun.faces.renderkit.html_basic.MenuRenderer.getConvertedValue(MenuRenderer.java:315)
at javax.faces.component.UIInput.getConvertedValue(UIInput.java:1023)
at javax.faces.component.UIInput.validate(UIInput.java:953)
at javax.faces.component.UIInput.executeValidate(UIInput.java:1204)
at javax.faces.component.UIInput.processValidators(UIInput.java:693)
at javax.faces.component.UIForm.processValidators(UIForm.java:240)
at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1081)
at javax.faces.component.UIViewRoot.processValidators(UIViewRoot.java:1159)
at com.sun.faces.lifecycle.ProcessValidationsPhase.execute(ProcessValidationsPhase.java:72)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:97)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:114)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:308)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:182)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:432)
at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:157)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:262)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:446)
at java.lang.Thread.run(Thread.java:619)

Take note that the Address object is a simple POJO. Without any specific code.
I passed the last 2 hours trying to figure what happened but , I just don't get it !
I've read some post on the internet that told me to put a String instead of an Address for the property selectedAddress but when I try this, I god a beautiful error that the value is incompatible type.
I also try to create a custom converter but it just not called. Its like my value are always null.

I user JSF2 with Jboss 4.2.3 if this can help anybody.

Thanks in advance for any kind of hint.

Christian Leclerc, CSSLP, SCJP, OCBCD, ZCE
http://www.s3s.ca - free hosting coming soon.

Ilari Moilanen
Ranch Hand

Joined: Apr 15, 2008
Posts: 198
If you use your own pojo with selectItems you have to tell which value is displayed and what is sent to server:

It is explained in the documentation
http://download.oracle.com/docs/cd/E17802_01/j2ee/javaee/javaserverfaces/2.0/docs/pdldocs/facelets/f/selectItems.html

christian leclerc wrote:
I've read some post on the internet that told me to put a String instead of an Address for the property selectedAddress but when I try this, I god a beautiful error that the value is incompatible type.

When you changed the values in selectItems to Strings did you also change the value of selectOneMenu to String? If you did not then they were of incompatible types.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16019
    
  20

What you did not show what your code for obtaining the address list.

If you coded that as a simple "get" method that merely returns "addresses", that's the problem. The "getAddresses()" method must return an array or List of SelectItems, not a list of Strings. That's because a Select option consists of not one, but two data elements: the option key and the option value. In many cases both elements can be the same object, but for accounting purposes, they're always a pair of objects. When the key and value are both the same object, there's a simplified single-element constructor for SelectItem you can use.


Customer surveys are for companies who didn't pay proper attention to begin with.
christian leclerc
Ranch Hand

Joined: Apr 08, 2008
Posts: 38
yeah !



Yeah with this example & the string , i've got it !!!

Thanks !!
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Noob JSF question on h:selectOneMenu item.