Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

send json object to jsf backing bean

 
pradeep gamage
Ranch Hand
Posts: 85
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am creating multi step registration. when first step next button click i want to send those data to jsf backing bean so i wroje jquery script. but i am not sure how to add URL here. this is my jquery code.


and how i can access json data object from jsf backing bean?
Thanks in advance...
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18212
53
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HTTP is all about text, and JSON is a way to encode one or more client-side objects in an easily-parsed text sequence. So the first step is to provide a "set" method on your backing bean to accept the JSON data as a String.

The backing bean's "set" method can then use one of the ready-made JSON parsers to break down the string into usable java objects. There are a number of J2EE-compatible JSON format/parse libraries available, including one from json.org, another from SourceForge (net.sf.json), and one from Google.
 
pradeep gamage
Ranch Hand
Posts: 85
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Tim Holloway, this is my jsf backing bean getter setter for string variable


but how i can assign value to this variable. How i can give URL in jquery

give me example.
Thanks in advance
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18212
53
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't use the "$" convention when doing jQuery in JSF. The EL processor will get confused and think you coded an EL expression. So instead of "$ajax", code "jQuery.ajax".

Your your sample expression is valid (except for the "$" part), but the important thing to note is that the EL expression "#{registerBean.jsonmsg}" is not dynamic. The JSF view processor will compile and evaluate the EL expression before that portion of the webpage is sent to the client, so effectively, the expression becomes a constant value that is equal to whatever value the jsonmsg property had when that part of the page was rendered. To update it, you'd have to re-render that section of the webpage.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic