How to clear a bean field with Stripes
Asked Answered
I

1

7

In a JSP I have the following field:

<stripes:text name="email"/>

This field is in my action bean(snippet):

    public class CreateClaim implements ActionBean {

    private String email;

    public void setEmail(String email) {
        this.email = email;
    }

    public String getEmail() {
        return email;
    }

    public Resolution alc(){
        email = "poodle";
        return new ForwardResolution("aForward.jsp");
    }

}

In the alc() methos I am setting email to be null. But when the pages renders the value of the email field is exactly as it was entered originally. Is there a way of clearing this field once and event has triggered?

Cheers

Dave

Immune answered 8/6, 2010 at 15:6 Comment(0)
A
5

This has to do with the population strategy of the Stripes framework. By default it has a Request first strategy (due to backward compatibility with earlier versions), but I always change it to the bean first population strategy.

Just edit the web.xml to add a init-param for your Stripes filter:

<filter>
  <filter-name>StripesFilter</filter-name>
    <filter-class>net.sourceforge.stripes.controller.StripesFilter</filter-class>

    <init-param>
      <param-name>PopulationStrategy.Class</param-name>
      <param-value>
        net.sourceforge.stripes.tag.BeanFirstPopulationStrategy
      </param-value>
    </init-param>
..etc...
Amphora answered 8/6, 2010 at 22:27 Comment(2)
Brilliant, the worked a treat. I did manage a work around using flash scope and a redirect, but this must be the correct way to handle it.Immune
I only use redirect after post requests, because it stops accidental double form submissions in case the browser back button is used. I all cases other cases the BeanFirstPopulationStrategy does its work.Amphora

© 2022 - 2024 — McMap. All rights reserved.