aspose file tools*
The moose likes Other Application Frameworks and the fly likes Stripes: how to avoid repopulating a textfield Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Frameworks » Other Application Frameworks
Bookmark "Stripes: how to avoid repopulating a textfield" Watch "Stripes: how to avoid repopulating a textfield" New topic
Author

Stripes: how to avoid repopulating a textfield

Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42275
    
  64
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?


Ping & DNS - my free Android networking tools app
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

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.


[My Blog]
All roads lead to JavaRanch
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42275
    
  64
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
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

Also note that you should be doing a Redirect after post. I'd suspect you are doing a ForwardResolution.


GenRocket - Experts at Building Test Data
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42275
    
  64
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
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

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
Marshal

Joined: Mar 22, 2005
Posts: 42275
    
  64
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
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

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
Marshal

Joined: Mar 22, 2005
Posts: 42275
    
  64
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
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Stripes: how to avoid repopulating a textfield