*
The moose likes Struts and the fly likes [solved] passing 3 times by default through action using struts 2 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "[solved] passing 3 times by default through action using struts 2" Watch "[solved] passing 3 times by default through action using struts 2" New topic
Author

[solved] passing 3 times by default through action using struts 2

Tudor Raneti
Ranch Hand

Joined: Nov 29, 2009
Posts: 145
The Data action gets called 3 times. I searched my code i haven't found anything that would do that.
Furthermore i didn't find anything that would run getData() from my Data.java action class, but i can use the data it makes in data.jsp.
I have to paste the code, seems it doesn't allow archives. The code passes 3 times where i used the line: System.out.println("setting query");
data.jsp

Data.java




Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9291
    
  17

Is this question missing something?? You've shown a JSP page, but what's the name of that jsp page?? Is it data.jsp, how is it concerned with action getting called three times?? How are you actually reaching to Data action?? Are you making a URL request by typing the URL in the browser's address bar??


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Tudor Raneti
Ranch Hand

Joined: Nov 29, 2009
Posts: 145
data.jsp (above) gets called from main which gets called from dataParams.jsp, main and dataParams action only return success:
dataParams.jsp


main.jsp


struts.xml
Tudor Raneti
Ranch Hand

Joined: Nov 29, 2009
Posts: 145
I debugged the application and it does this weird thing:
it runs fine until it gets to data.jsp, then, after parsing this it jumps back to action:

on this line:



then it jumps back after a while at the line it jumped out of and parses until it jumps back to action upon finishing the loop, then comes back from the jump to this line:

after this it exits normally. Why is this happening, and how does Data.java know to run getData()?
Tudor Raneti
Ranch Hand

Joined: Nov 29, 2009
Posts: 145
Sorry for triple posting, but i'm working a timeline here
I think i got it myself. Seems that getData() is beeing called by something else (very weird) because when i renamed it to getSomeStuff(),
it doesn't run at all no more. Good ol' debugging.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Because you keep calling ${data.xxx} in the JSP, which means it's going to call getData() on the action each time.

I'd consider spending some time with the S2 documentation, since this kind of stuff is very basic to the framework.

It's not weird at all--you just don't know how the framework works.
Tudor Raneti
Ranch Hand

Joined: Nov 29, 2009
Posts: 145
Thanks for promptness. I thought that it's bound to the action class as a bean too, thus data.property, but it was working because it was seeing getData as a property so I see how that works, you were saying Action sets the property to the action context...
Solved like:



 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: [solved] passing 3 times by default through action using struts 2
 
Similar Threads
JSP column name hyperlink help
design problem
How do I update table using postJSON
how to overwrite a request param?
Oracle error on jsp page, but the sql runs fine in Oracle tool