首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >关于Icefaces和valueChangeListener的问题

关于Icefaces和valueChangeListener的问题
EN

Stack Overflow用户
提问于 2009-04-29 12:39:59
回答 1查看 5.3K关注 0票数 0

我使用了icefaces 1.7.1,我使用了ice:inputText和valueChangeListener,就像这样:

代码语言:javascript
复制
<ice:inputText value="#{myBean.name}" valueChangeListener="#{myBean.nameChangedListener}"/>

在MyBean.java中,我有:

代码语言:javascript
复制
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
}

再次感谢您的帮助……

EN

回答 1

Stack Overflow用户

发布于 2009-04-29 13:49:42

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

代码语言:javascript
复制
  /** 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验证模型,必须将验证合并到操作逻辑中。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/802172

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档