Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to get the value from action to the javascript.

 
rahulJ james
Ranch Hand
Posts: 123
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 607
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Keep using Ajax. I don't get the point where you are stuck at?
 
siva saran
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 123
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 123
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic