• 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

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

 
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.





 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 162
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 162
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 162
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
You can't have everything. Where would you put it?
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic