aspose file tools*
The moose likes Struts and the fly likes passing JS values in struts-2 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "passing JS values in struts-2" Watch "passing JS values in struts-2" New topic
Author

passing JS values in struts-2

Pradeep Adibatla
Ranch Hand

Joined: Oct 27, 2009
Posts: 336
This is a repeat of post in html/JS... I would request the moderators to delete there, as no one is answering there or move it to covenient position

I am not certain whether this should be here or be in struts, jsp forum but would proceed...

The application is in struts-2


I have 2 JSP's... The 1st JSP has a 5 column table... The values for the 4th and 5th columns are obtained from the next JSP...These values are currently residing in a JS variable prepared in JSP-2.

Scenario:-->

In 1st JSP, I select row1 and click on 'gotoNext' button to go to next JSP in order to prepare values for the 4th and 5th columns...

In JSP-2, I prepared the 2 values for that row using Javascript...

Now on click of back button in JSP2 I need to go back to JSP1 and set these 2 values in 2 empty fields of the row that I previously selected...


I don't know the correct way to do it and these are a few options circulating in my mind viz...

1)Should I send these values unsing an AJax call?
2)How to pass those 2 JS values from JSP-2 and set them in empty fields of that row of JSP1
Tom Rispoli
Ranch Hand

Joined: Aug 29, 2008
Posts: 349
When you say you click the "Back" button on JSP2, do you mean the browser's back button or do you have an html button called "Back" button on your page? If you are using the browser's back button this won't work since you'll either get the cached version of the previous page or it will resubmit the request for the previous page, either way your selections on the second page will be ignored. If you have an html button that you created then you could use that to submit the form for page 2 to your app and then your app can take the data and and use it for the JSP for page 1.

Another option would be to launch JSP 2 by calling your action/jsp through window.showModalDialog, then the values selected on JSP 2 could be returned to JSP 1 in javascript and you could put javascript on page one to put the returned values in your table. Fair warning, I only use IE so if window.showModalDialog doesn't work for other browsers I won't know about it.

Hope this helps.
Pradeep Adibatla
Ranch Hand

Joined: Oct 27, 2009
Posts: 336
Yes I have a html back button...

On click of back in JSP-2 am submitting it to the jsp-1..Now how will I transfer my JS values?(what should be done in jsp1 to ensure that the values are falling in right place when back is clicked on jsp2?

I would try that showModalDialog...



Tom Rispoli
Ranch Hand

Joined: Aug 29, 2008
Posts: 349
In that case you can use javascript to add the values you want as request parameters to your call to jsp-1. Of course if you are submitting your entire form with the back button then you just need to move these js variables to hidden input fields and they will be sent with the rest of the form.

After that you just need to map the values from JSP2 to the fields you want them in in JSP1 in your action class. If you are just going straight to your JSP then you'll need to get them from the request object.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: passing JS values in struts-2