This week's book giveaway is in the OCAJP forum.
We're giving away four copies of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) and have Khalid A Mughal & Rolf W Rasmussen on-line!
See this thread for details.
Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

NullPointerException in getter method

 
Prash Singh
Ranch Hand
Posts: 103
jQuery Netbeans IDE Notepad
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 18276
56
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Prash Singh
Ranch Hand
Posts: 103
jQuery Netbeans IDE Notepad
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Tim,

Thanks for your reply.

Can you please recommend me some good book for Jsf ?


 
Tim Holloway
Saloon Keeper
Pie
Posts: 18276
56
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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


 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic