This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes HTML, CSS and JavaScript and the fly likes accessing request scope variable from javascript Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "accessing request scope variable from javascript" Watch "accessing request scope variable from javascript" New topic
Author

accessing request scope variable from javascript

veena sasikumar
Greenhorn

Joined: Nov 27, 2006
Posts: 29
Dear all,
In my jsp page, I am using javascript function.The function is written in between <HEAD> and /<HEAD> in the document. I use only one form in the jsp page. I use a condition for calling a struts action class whenever a variable bCheck becomes true. I want to validate date fields in the execute method of the action class. In the execute method, I am setting a variable(newView) in the request scope.My aim is to open a new window with a specified url, if the validation is true. The strange behaviour, i noticed is mentioned below.

I printed the variable correctly which i set in the execute method before returning back to the same jsp form from the execute method.
Assume I entered values in the form 3 times(for testing) and clicked for validation. During the second time, i found that variable showNewView is getting the value that was set in the previuos time in the execute method. For example, assume the date format entered is correct for the first two times and wrong for the third time. I should get the variable showNewView as true for the first two times
and false for the third time. Instead of that, first time, alert window showed " showNewView value is null" . second time it showed " showNewView value is true" and in the the third time, it showed the previous value. That is " showNewView value is true"
what is the reason for this?


[ January 10, 2007: Message edited by: Bear Bibeault ]
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
You need to rethink your logic here

document.forms[0].action = document.forms[0].action+"?Action=ValidateViewBill";
document.forms[0].submit();

causes the post back to the server

The following lines may or not be called depending on how fast the post back works.

${requestScope.newView} is filled in from the orginal render of the page. View the source. It is not going to change with a postback.

Bear has an article on the JavaRanch journal that explains about CLient and Server differences. Hopefully he will read this and point you towards it.

Eric
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60800
    
  65

The Secret Life of JavaServer Pages


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
veena sasikumar
Greenhorn

Joined: Nov 27, 2006
Posts: 29
Thanks for the answer. it was really informative and I read the article suggested by you . Still i am not getting a solution for implementing the same.

My existing jsp page is written as one form inside <html:form> tag. and from inside the form, i call a number of javascript functions which are written between <head> and </head> . As per your answer, there is no guarantee that the second function will be called only after the post back from the server. In such a situation, could you suggest a method to implement the same.

I have two struts action classes. If I use second action class, the details from the first jsp page ( or action form) is not available since I use a function showInNewWindow( strUrl ); which opens a new window. How can I solve the problem?

Expecting your valuable answer in this regard..

thanks
veena
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: accessing request scope variable from javascript
 
Similar Threads
form bean value not getting
Two actions in single button click
Struts parent & popup window with validator framework
Diffterent action from different button
how to delete the rows which are checked