aspose file tools*
The moose likes Struts and the fly likes Struts passing info from the stack to actions as pass by value? causing severe issues. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Struts passing info from the stack to actions as pass by value? causing severe issues." Watch "Struts passing info from the stack to actions as pass by value? causing severe issues." New topic
Author

Struts passing info from the stack to actions as pass by value? causing severe issues.

David Rocks
Ranch Hand

Joined: Apr 24, 2001
Posts: 162
Recently I changed my application from RestfullMapper to using wilcards and this has created some pretty strange behaviour from my app.

I have chosen one particular case to explain and wondered if anyone has any ideas before I start debugging through the struts code, the behaviour is pretty strange and I doubt it is meant to work this way.

I have a JPA entity object, Competition, an Action CompetitionAction, a persistance mananger ComptitionManager and a displayCompetition.jsp. All very basic. I am using the basic 'session in view' pattern from hibernate.

my xml for this is..




CompetitionAction holds a competition object.

My interceptors are params, staticParams and actionParams

myURL is

/competition/view/competitionname

now as competition name can have spaces when I display the URL I replace the spaces with -s and then the view method replaces them back to spaces. The view method calls a select in the CompetitionManager, places that in the competition variable in CompetitionAction, forwards onto displayCompetition.jsp and everything is OK.

The problem arises as I have an action called within displayCompetition.jsp that shows a simple count(*) from a table which is to be displayed.



Even though this has nothing to do with the competition object it kicks of a call to the Competition object and resets the name to the one with hyphens in it. Take that page located action out and it's all fine, put it back and it goes wrong.

This has another serious issue as the get and display is all done in one request, at the end of the render a hibernate commit is called and it places the hyphenated name into the database.

As far as I can tell the stack is dealing out copied object to the actions, probably passed by value although I am not sure just yet. Depsite me changing the value of the object on my first action that gets blasted on subsequent calls to other actions.

This is either a very simple config change or a more serious underlying issue in struts IMO.

I will probably post this to the user lists later, I cannot access them at my current location.





David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

I think I don't understand what you're saying.

If you modify a Hibernate object inside a transaction with a commit at the end it's going to get updated in the DB. That doesn't have anything to do with Struts at all.
David Rocks
Ranch Hand

Joined: Apr 24, 2001
Posts: 162
David Newton wrote:I think I don't understand what you're saying.

If you modify a Hibernate object inside a transaction with a commit at the end it's going to get updated in the DB. That doesn't have anything to do with Struts at all.


Ignore the hibernate issue, it is a knock on from the struts issue,.

In the first action I take the object from the request and modify the name on it, when the second action is called struts sets the name back to the original value despite the second action having no interest whatsoever in the modified object.

That most certainly is a struts issue and is wrong in my opinion


David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

By the "second action" you mean the action called via the action tag?

I think you're just not understanding how the action tag and S2 requests work. Also, why would you replace things in a URL with non-URL-encoded values? Why not use mechanisms that already exist?
David Rocks
Ranch Hand

Joined: Apr 24, 2001
Posts: 162
David Newton wrote:By the "second action" you mean the action called via the action tag?

I think you're just not understanding how the action tag and S2 requests work. Also, why would you replace things in a URL with non-URL-encoded values? Why not use mechanisms that already exist?


I understand perfectly how the actions work, if you take the time to read through the description of the issue you will see that. Once again..

I pass an attribute to an action in a URL
my action modifies that attribute.
the action forwards to the JSP which displays the attribute

If I have an action tag on that screen the attribute will be displayed as the value from the URL

If I do not have an action tag the attribute will be diplayed as the value from the action.

If you cannot see that is unexpected and incorrect behaviour we are wasting out time here.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

The action tag, which is generally avoided precisely because of issues like this (and a few others), is basically processing a request. Meaning if you pass in a parameter it'll be set. If you don't want to modify it then set ignoreContextParams to true.

So far I haven't seen anything unexpected. Awfully sorry to "waste your time" by trying to help and understand--it won't happen again.
David Rocks
Ranch Hand

Joined: Apr 24, 2001
Posts: 162
David Newton wrote:The action tag, which is generally avoided precisely because of issues like this (and a few others), is basically processing a request. Meaning if you pass in a parameter it'll be set. If you don't want to modify it then set ignoreContextParams to true.

So far I haven't seen anything unexpected. Awfully sorry to "waste your time" by trying to help and understand--it won't happen again.


The page display is off the back of one request and the action tag will be creating another request, the action called by the URL and the action called by the tag are different.

The second request is therefore modifying data on the first request. That is clearly unexpected.
 
 
subject: Struts passing info from the stack to actions as pass by value? causing severe issues.