• 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

accessing request scope variable from javascript

 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The Secret Life of JavaServer Pages
 
veena sasikumar
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
reply
    Bookmark Topic Watch Topic
  • New Topic