• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

passing java-script value to java-bean-property

 
nimo frey
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
how can I transfer the ivalue of a java-script to a java-bean-property?

This java-script returns me a ivalue:

alert(myJsValue);

I need to pass the value of myJsValue to a java-bean-property. How can I do that?
 
Bertjan Underhill
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

To set a javascript property with a java bean property:



To set a java bean property with a javascript property you can try this:

In your JSP you have to following line:


Then set with javascript your myJsValue:


I hope it will work.
 
prash patil
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just to add more on it ..
You can send any value form JavaScrip to Java or vice versa using DWR. Direct Web Remoting a easy AJAX for java.
:-)

Regards
PP.
 
rashmi coorg
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bertjan Underhill wrote:Hello,

To set a javascript property with a java bean property:



To set a java bean property with a javascript property you can try this:

In your JSP you have to following line:


Then set with javascript your myJsValue:


I hope it will work.





this is not working for me... any suggestions y?
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18100
51
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The only way JavaScript can set a backing bean property is by making a request to the server, since that's where the backing bean lives. That means that the client must make an HTTP URL request to the server. The brute-force way of doing that would be to set a form control property (you can use a hidden text control) and pass the value in when the form is submitted.

A more elegant approach that avoids the need to submit and re-render the entire page is to do an AJAX request. That can be done in a number of ways, including:

1. brute-force javascript
2. Using an AJAX support javascript library like dojo or jQuery
3. Using the JSF2 AJAX support features
4. Using third-party JSF AJAX support packages such as RichFaces or IceFaces.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic