Losing validation with <f:ajax>

独自空忆成欢 提交于 2019-12-11 06:51:18

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!