验证消息立即显示和清除

时间:2013-08-05 21:03:48

标签: jsf jsf-2 icefaces-3

我正在使用JSF 2.1.21并显示我的错误消息,然后在输入文本框中按Enter键时立即清除。我在输入上有一个javascript来触发命令按钮。

<h:form>
<div><ice:messages /></div>
<ice:inputText  onkeyup="submitOnEnter(event);" value="#{bean.name}" maxlength="6" size="6">
                                <f:validator validatorId="stringValidator" />
</ice:inputText>
<ice:panelGroup>
   <ice:commandButton id="button" value="Go"    actionListener="#{myController.getReport}">
   </ice:commandButton>
</ice:panelGroup>
</h:form>

stringValidator:

public void validate(FacesContext context, UIComponent component, Object value) throws 
    ValidatorException {
if (!(((String) value).trim()).matches(REGEX_CONSTANT)) {
        ((UIInput) component).setValid(false);
        throw new ValidatorException(new FacesMessage(FacesMessage.SEVERITY_ERROR, 
                                        myMessage, null));
    } else {
        ((UIInput) component).setValid(true);
    }

更新

function submitOnEnter(event) {
   var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
   if(keyCode == 13) 
   {
           document.getElementById("myForm:button").click();
           return false;
   }
}

0 个答案:

没有答案