• 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

execAndWait Interface problem

 
Ranch Hand
Posts: 189
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Everybody
I have studied about this interface but on implementing it, it is giving weird result. My application is taking an input string and displaying that string in upper case in the result page. The code is as follows :-
struts.xml
MyInterceptor.java
NextInterceptor.java
Login.java
temp.jsp
index.jsp
welcome.jsp
Console is coming as follows :

Now, my questions are :
1.) If we see line 7 of the console, at this point sleep time in the action finishes off. So, after this statement execution of the action class, the interceptors should be called in the reverse order. Which are not being called !!
2.) Line 8,9,10,11 they are printed out because after 2 seconds the temp.jsp page is being refreshed. Here the interceptors are working in their order but why action class is not envoked between this ?
3.) Why is it that the result in the welcome.jsp is not coming in the uppercase ?

Hope i am able to put my questions clearly. Thanks in Advance !!!
 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Most of your questions can be answered with a quick read of the documentation. The function of execAndWait is different than the flow we discussed in your previous post so that may be the source of your confusion. Basically, Struts puts the action on its own thread, completes one round trip of the request to render the wait JSP, then polls the action to see if it is finished yet.

1.) If we see line 7 of the console, at this point sleep time in the action finishes off. So, after this statement execution of the action class, the interceptors should be called in the reverse order. Which are not being called !!


They are called correctly on lines 3 and 4.

2.) Line 8,9,10,11 they are printed out because after 2 seconds the temp.jsp page is being refreshed. Here the interceptors are working in their order but why action class is not envoked between this ?


The action is not called a second time by the execAndWait interceptor. That would cause an infinite loop as another long-running process would be spawned with each check. The spawned thread is checked by Struts and if it is done running, Struts shows the final result.

3.) Why is it that the result in the welcome.jsp is not coming in the uppercase ?


You should not be using the stack for regular user data. Use your "business objects", like Login. I would bet that Login.name is what is actually being referenced by welcome.jsp.
 
Tarun Oohri
Ranch Hand
Posts: 189
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Joe,
It seems my concepts regarding struts2 are not crystal clear. Please correct me where ever i am wrong :

1.) In struts2, for every request there is a separate object of the action class. So, when i input a string from (say) index.jsp. The "param" interceptor will take this string to the valuestack and store this string in the member variable of that action object.

2.) So, now if we do any changes in the value stack, this means we are changing the member variables corresponding to action object. So, if we render the value in the result page by <s:property value="name"/> . What is the difference in storing the value in the action object or in the valuestack ?

3.) It is said that "The ActionContext is thread local which means that values stored in the ActionContext are unique per thread. "
What is "per Thread" here !! What i have studied is, In Struts2 for every request there is a separate action object ( A Thread per Request is the Servlet functionality). So, if every request gets its own action object then no request will interfere in the member variables of other request, That makes it thread safe.

This is what i know about struts2. I can be wrong drastically . Please care to correct me.
Thanks Again!!!
 
Joe Ess
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Tarun Oohri wrote:What is the difference in storing the value in the action object or in the valuestack ?



The framework is designed to use actions for programmer-defined values. When you alter the value stack, you can have unintended consequences (as you have seen, your value isn't what you thought it was) and you are tying your application to the current implementation of Struts. Should the developers change that implementation down the road, your application will break.
Take a look at the Guides and Tutorials in the Struts documentation for Best Practices on using the framework.
 
Tarun Oohri
Ranch Hand
Posts: 189
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Joe..shall look at the source you provided .
 
reply
    Bookmark Topic Watch Topic
  • New Topic