Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Stripes: how to avoid repopulating a textfield

 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a JSP page containing a a form with couple of text fields. Upon form submission, the Stripes action bean saves any values that may be in these text fields, and then re-displays the original page with the form. That works fine.

The problem is that the text fields are re-populated with the values I entered before, even though I'm explicitly clearing them in the action bean before returning the Resolution. What else do I have to do to make sure the fields are not repopulated after a successful form submission?
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I suppose that you are not explicitly setting the value as a tag attribute. The default population strategy also looks in the request for the form input tags, so even if you clear the ActionBean, the values will be displayed if they are in the request. If this strategy does not suit you, you may have to make your own, by extending the DefaultPopulationStrategy. You'll find some info on that in the Tag Library documentation.
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Christophe, that was precisely it. I didn't need to extend DefaultPopulationStrategy - BeanFirstPopulationStrategy seems to work fine.

I think it's a bit strange that values from the request should be taken to repopulate a form that was submitted successfully. Oh well, now that I know this -I hadn't encountered PopulationStrategy and its implementations before- it's easy to work with it.
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also note that you should be doing a Redirect after post. I'd suspect you are doing a ForwardResolution.
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Gregg Bolinger:
Also note that you should be doing a Redirect after post. I'd suspect you are doing a ForwardResolution.


Yes, I'm using ForwardResolution. It makes sense that I should use redirect after post, but with forwarding it's very convenient to attach context messages for display in the JSP.

How are you dealing with that - store those messages under some ID in the session, and then attach that ID to the redirect URL so that the action bean can retrieve it for display?
[ February 16, 2008: Message edited by: Ulf Dittmer ]
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ulf Dittmer:


Yes, I'm using ForwardResolution. It makes sense that I should use redirect after post, but with forwarding it's very convenient to attach context messages for display in the JSP.

How are you dealing with that - store those messages under some ID in the session, and then attach that ID to the redirect URL so that the action bean can retrieve it for display?

[ February 16, 2008: Message edited by: Ulf Dittmer ]


Nah, flash scope. So are you talking about something like "Bla has been successfully saved."?

If so, then all you have to do is add that message to Stripes' message system in the ActionBeanContext. These messages are automatically placed into session for you and then removed using the FlashScope mechanism. There is a section in the stripes docs about this located here under Flash Scope.
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Way cool. I was already using context messages, so all I had to do was use RedirectResolution instead of ForwardResolution to turn them into flash scope messages.

So I got to fix the original problem (w/o resorting to messing with PopulationStrategy, no less), implement a Post/Redirect/Get solution, and learned a couple new things about Stripes.

The only downside are the cryptic "fsk" parameters in the URL, but I can live with that.
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ulf Dittmer:
The only downside are the cryptic "fsk" parameters in the URL, but I can live with that.


Well, Stripes needs to know where to get that session data from and it is encrypted so that is why it is a bit cryptic. Are you using Stripes 1.5 and Clean URLs?
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeah, intellectually I understand why it's needed. That was just an aesthetically inspired comment

I'm using 1.4, and it's very late in the game for this project to be changing versions. But your blog pages about 1.5 are saved on my machine; I'll be sure to check out the new features for the next project.
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ulf Dittmer:
Yeah, intellectually I understand why it's needed. That was just an aesthetically inspired comment

I'm using 1.4, and it's very late in the game for this project to be changing versions. But your blog pages about 1.5 are saved on my machine; I'll be sure to check out the new features for the next project.


Cool. I believe that in 1.5 those oddities in the URL go away.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic