问题
I have this form:
<h:form id="form">
<h:panelGrid columns="3" >
<h:outputLabel for="name" value="Name:" />
<h:inputText id="name" value="#{register.person.name}" >
<f:ajax event="blur" listener="#{register.validateName}" render="m_name" />
</h:inputText>
<rich:message id="m_name" for="name" ajaxRendered="false"/>
<!-- other fields -->
<h:commandButton value="Register" action="#{register.registerPerson}" >
<f:ajax execute="@form" render="out" />
</h:commandButton>
<h:outputText value="#{register.recordStatus}" id="out" />
</h:panelGrid>
If I try to register some person without a name and no error message is displayed. Instead, an error message appears when removing a person : <f:ajax execute="@form" render="out" />.
Why is this happening ?
回答1:
You need to include the ID of the message in the render as well.
<f:ajax execute="@form" render="m_name out" />
You can also just render the entire form if you have more than one message.
<f:ajax execute="@form" render="@form" />
See also:
- Communication in JSF 2.0 - Ajax Validation
回答2:
Might be a bit late, but...
The attribute ajaxRendered of <rich:message> has a default value of true, which forces it to appear in AJAX responses.
You set it to false in Your form, and so You have to specify, which AJAX calls should re-render it.
来源:https://stackoverflow.com/questions/7485565/losing-validation-with-fajax