tags:

views:

1560

answers:

1

Hi There... I used icefaces 1.7.1, and i use ice:inputText with valueChangeListener like that :

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

In MyBean.java i have:

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
}

Thanks again for any Help.....

+1  A: 

Value change listeners cannot be used to alter the values being changed (FYI: they are invoked in the validation phase). Have a look at converters and validators - they prevent junk data from getting into your model.

  /** 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);
    }
  }

One area that trips many people up is that a submitted form that contains invalid data will prevent actions firing. This is by design - it prevents business logic from operating on bad data. If you need to fire an action even though there is invalid data in the request, you cannot use the JSF validation model and will have to incorporate validation into your action logic.

McDowell