【问题标题】:Question about Icefaces and valueChangeListener关于 Icefaces 和 valueChangeListener 的问题
【发布时间】:2009-04-29 12:39:58
【问题描述】:

我使用了 icefaces 1.7.1,我使用 ice:inputText 和 valueChangeListener 类似:

<ice:inputText value="#{myBean.name}" valueChangeListener="#{myBean.nameChangedListener}"/>

在 MyBean.java 我有:

public void nameChangedListener(ValueChangeEvent event){
   // test the new value : if it's ok continue but if it is not ok i need it to keep the old value.
   // I know that the valueChangeListener invoked before the old value is replaced by the newValue, is it ok?, and if ok : what to do to keep the oldValue if the newValue is worng
}

再次感谢您的帮助.....

【问题讨论】:

    标签: jsf icefaces


    【解决方案1】:

    值更改侦听器不能用于更改正在更改的值(仅供参考:它们在验证阶段被调用)。看看converters 和validators - 它们可以防止垃圾数据进入您的模型。

      /** validator="#{myBean.checkThreeCharsLong}" */
      public void checkThreeCharsLong(FacesContext context,
          UIComponent component, Object value) {
        boolean failedValidation = (value == null)
            || (value.toString().trim().length() < 3);
        if (failedValidation) {
          ((EditableValueHolder) component).setValid(false);
          // message to user
          String clientId = component.getClientId(context);
          FacesMessage message = new FacesMessage(
              "value should be at least three characters long");
          context.addMessage(clientId, message);
        }
      }
    

    让很多人感到困惑的一个方面是,包含无效数据的提交表单会阻止操作触发。这是设计使然 - 它可以防止业务逻辑对错误数据进行操作。如果即使请求中存在无效数据,您也需要触发操作,则不能使用 JSF 验证模型,并且必须将验证合并到您的操作逻辑中。

    【讨论】:

      猜你喜欢
      • 2013-04-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-01-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-04-14
      相关资源
      最近更新 更多