my dog learned polymorphism*
The moose likes JSF and the fly likes NullPointerException in getter method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "NullPointerException in getter method" Watch "NullPointerException in getter method" New topic
Author

NullPointerException in getter method

Prash Singh
Ranch Hand

Joined: Aug 23, 2009
Posts: 103

Dear All,
I am new to jsf and facing some issues dealing with it.
I am making a simple jsp file which is backed by a class.
Every Component I am using the page is bounded to some property in the backing java class.
example

and In the class


Now on the value change listener event of some other component in the same page ,
i have to update the value of this field.
I am using following code in the valueChangeListener method of the event causing component.



But I am getting NullPointerException at this line.
Please explain me how to remove this.
Also what is the difference between value and binding attribute of the jsf component?
Is it ok to bind every form component to a property in the managed bean?

Thanks in advance.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16020
    
  20

JSF is different. I don't like to even use the term "JSP" in JSP, because the ".jsp" files in JSF aren't really JSP files, just JSF View definitions whose filename extension just happens to be ".jsp".

Binding is something that I think was required in the early days when JSF was still being designed and the documentation ended up polluting the Internet forevermore. These days, the only really good excuse for using binding is if you plan to dynamically build GUI elements on the webpage - a practice that itself is generally not encouraged. For the most part, your programming will be simpler and cleaner if you use "value=" attributes instead. You you tried, in fact, won't work, because binding is done to a JSF UIComponent object, not to a data properly. I recommend getting a good book on JSF.

Like Binding, Listeners are also used over-much. You don't need to use them to set properties. JSF will set your properties from the view directly without you needing to code anything other than a POJO property-set method in the backing bean. Listeners do have their uses, but they mostly are needed for things like updating cascaded drop-down lists of the country/state/city variety and not for simple data access.


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

Joined: Aug 23, 2009
Posts: 103

Dear Tim,

Thanks for your reply.

Can you please recommend me some good book for Jsf ?


Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16020
    
  20

Prash Singh wrote:Dear Tim,

Thanks for your reply.

Can you please recommend me some good book for Jsf ?




I'm not up to date on JSF books myself. I found Kito Mann's JSF in action to be good myself.

And for the benefit of those I've confused even more than usual,

I don't like to even use the term "JSP" in JSP


should have been


I don't like to even use the term "JSP" in JSF


 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: NullPointerException in getter method