Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes HTML, CSS and JavaScript and the fly likes How to get the value from action to the javascript. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "How to get the value from action to the javascript." Watch "How to get the value from action to the javascript." New topic
Author

How to get the value from action to the javascript.

rahulJ james
Ranch Hand

Joined: Oct 03, 2008
Posts: 123
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.
Saifuddin Merchant
Ranch Hand

Joined: Feb 08, 2009
Posts: 606

Keep using Ajax. I don't get the point where you are stuck at?

Cheers - Sam.
Twisters - The new age Java Quiz || My Blog
siva saran
Greenhorn

Joined: Mar 11, 2007
Posts: 17
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
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
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
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
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...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to get the value from action to the javascript.