【问题标题】:How to clear a bean field with Stripes如何使用 Stripes 清除 bean 字段
【发布时间】:2010-06-08 15:06:09
【问题描述】:

在 JSP 中,我有以下字段:

<stripes:text name="email"/>

此字段在我的操作 bean(sn-p) 中:

    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");
    }

}

在 alc() 方法中,我将电子邮件设置为空。但是当页面呈现时,电子邮件字段的值与最初输入的完全一样。 有没有办法在事件触发后清除该字段?

干杯

戴夫

【问题讨论】:

    标签: java web-applications stripes


    【解决方案1】:

    这与 Stripes 框架的人口策略有关。默认情况下,它有一个请求优先策略(由于与早期版本的向后兼容性),但我总是将其更改为bean first population strategy

    只需编辑 web.xml 为您的 Stripes 过滤器添加一个 init-param:

    <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...
    

    【讨论】:

    • 太棒了,这是一种享受。我确实使用闪存范围和重定向解决了一个问题,但这一定是处理它的正确方法。
    • 我只在发布请求后使用重定向,因为它会在使用浏览器后退按钮的情况下阻止意外的双重表单提交。我在其他情况下都是 BeanFirstPopulationStrategy 完成它的工作。
    猜你喜欢
    • 2016-11-23
    • 1970-01-01
    • 2021-03-31
    • 1970-01-01
    • 1970-01-01
    • 2011-08-10
    • 2015-12-19
    • 1970-01-01
    • 2012-07-09
    相关资源
    最近更新 更多