我使用了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
}再次感谢您的帮助……
发布于 2009-04-29 13:49:42
值更改侦听器不能用于更改正在更改的值(仅供参考:它们在验证阶段调用)。看看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验证模型,必须将验证合并到操作逻辑中。
https://stackoverflow.com/questions/802172
复制相似问题