How to get the value from action to the javascript.

I have a scenario, where the user changes something in the page, then throw a popup with a confirm propmt. when the user clicks ok, I pass a dynamic value from the javascript to the struts action, manipulate something in the database and fetch a value. I wanted to pass the fetched value to the javascript with a pop again and with a message for the popup asking the user to confirm.

When the user selects ok, I have to prompt him again with a message.

I am able to throw a pop when the user changes something and pass that to action by AJAX. Can anyone advise how do I proceed the remaining steps like pass the value back to javascript with a popup and so on.

You should use the form property (in the struts-config.xml) to set the data in the Action class and then retrieve in the javascript by using the getEl("") method.
Dont forget to pass the form property as hidden like this before using in the javascript.

Hope this helps.

rahulJ james
Ranch Hand

Joined: Oct 03, 2008
Posts: 123

posted Mar 30, 2009 05:56:33

0

I have the value in my action and I am stuck to get the same value in a popup through the java script.

I am usign struts 2 version and I dont have options to use the form property in struts.xml

siva saran
Greenhorn

Joined: Mar 11, 2007
Posts: 17

posted Mar 30, 2009 06:13:22

0

rahulJ james wrote:I have the value in my action and I am stuck to get the same value in a popup through the java script.

I am usign struts 2 version and I dont have options to use the form property in struts.xml

How about using the request.setAttrribute("",value) .You can use the following piece of code to pass the value to the javascript

Then you can use the getEl("name") in the javascript function to retreive the value that was packed in the action class.

rahulJ james
Ranch Hand

Joined: Oct 03, 2008
Posts: 123

posted Mar 30, 2009 08:47:57

0

In struts 2 I am not able to use the request. I tried using session.setAttribute() to set and get the value back in the JS. I am able to set and get the value through a hidden field though I am not able to get that in the Javascript where I am using the Ajax function call.

siva saran
Greenhorn

Joined: Mar 11, 2007
Posts: 17

posted Mar 31, 2009 05:34:51

0

rahulJ james wrote:In struts 2 I am not able to use the request. I tried using session.setAttribute() to set and get the value back in the JS. I am able to set and get the value through a hidden field though I am not able to get that in the Javascript where I am using the Ajax function call.

I presume you are not doing a document submit during the initial AJAX call to the servlet.Once the database operation is over and you receive a readyState == 4 from the browser you can use the window.open() to open a new popup, pass the values from ajax reposne as query params in the window.open function and retrieve the query params in the popup to display to the users.Hope the data to be presented is not bulk.In that case I have no idea what to do...