aspose file tools*
The moose likes Struts and the fly likes execAndWait Interface problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "execAndWait Interface problem" Watch "execAndWait Interface problem" New topic
Author

execAndWait Interface problem

Tarun Oohri
Ranch Hand

Joined: Feb 20, 2013
Posts: 175
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 !!!
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8866
    
    8

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.

"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
Tarun Oohri
Ranch Hand

Joined: Feb 20, 2013
Posts: 175
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

Joined: Oct 29, 2001
Posts: 8866
    
    8

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

Joined: Feb 20, 2013
Posts: 175
Thanks Joe..shall look at the source you provided .
 
wood burning stoves
 
subject: execAndWait Interface problem