Meaningless Drivel is fun!*
The moose likes JSF and the fly likes passing java-script value to java-bean-property Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "passing java-script value to java-bean-property" Watch "passing java-script value to java-bean-property" New topic
Author

passing java-script value to java-bean-property

nimo frey
Ranch Hand

Joined: Jun 28, 2008
Posts: 580
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

Joined: Aug 25, 2008
Posts: 12
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

Joined: May 26, 2008
Posts: 40
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

Joined: Jul 11, 2011
Posts: 19
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

Joined: Jun 25, 2001
Posts: 15950
    
  19

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.


Customer surveys are for companies who didn't pay proper attention to begin with.
 
wood burning stoves
 
subject: passing java-script value to java-bean-property
 
Similar Threads
problem with the popup
calling javascript function through onclick present on checkbox
how to convert byte [] to String?
passing parameters between JSF(or JSP) and java script
Spring-Hibernate transaction management