Meaningless Drivel is fun!*
The moose likes Struts and the fly likes How to change property of form bean from java script using AJAX Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "How to change property of form bean from java script using AJAX " Watch "How to change property of form bean from java script using AJAX " New topic
Author

How to change property of form bean from java script using AJAX

Varun Vyas
Greenhorn

Joined: Jul 06, 2006
Posts: 2
I am trying to change property of a form bean with java script code in ajax.

<html:select property="branch" onchange="validate('currect.do');">
....
....
</html:select>

AJAX function
function validate(url)
{
// For IE
req = new ActiveXObject("Microsoft.XMLHTTP");
if (req)
{
req.onreadystatechange = processStateChange;
req.open("GET", url, true);
req.send();
}
}

According to this url, it directly calls the action 'currect.do'. It is not setting property 'branch' as per selection. What should i do to set this property from java script? Let me know if there is any other way to get this problem solved.
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
Varun,
It is not setting property 'branch' as per selection


In JavaScript, an "onchange" event does not change anything, it responds to a change. So, when the user clicks on the "branch" select box and changes the value, it calls your code.

In AJAX, the server-side URL that you call is expected to return XML as output. Does your "currect" action return XML?

Your code indicates that the JavaScript function "processStateChange" is to be called when the response is received from the server. You haven't shown us that function, so we have no idea what it does or if it exists. What it is generally supposed to do is use JavaScript functions to parse the XML returned from the server and then use the Document Object Model (DOM) to change the HTML document in some way.

What should i do to set this property from java script?


I'm afraid I don't have enough information to answer htis. It sounds like you want to change the value in the "branch" select box.. Ok I get that. What do you want to trigger that change? How do you want to change it? from what to what?

Here's my advice: If you're not a strong JavaScript coder, don't bother with the nitty-gritty details of AJAX, but use a framework instead. The one I've used and highly recommend is DWR. Go to the website, download it, and do some of tutorials they suggest, and then try this again using DWR.


Merrill
Consultant, Sima Solutions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to change property of form bean from java script using AJAX