• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to get the value from action to the javascript.

 
Ranch Hand
Posts: 123
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 608
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Keep using Ajax. I don't get the point where you are stuck at?
 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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...
 
You get good luck from rubbing the belly of a tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic