【问题标题】:f:ajax validation shows only one message at oncef:ajax 验证一次只显示一条消息
【发布时间】:2015-08-15 17:51:42
【问题描述】:

我正在处理带有字段验证的 JSF 表单。

<h:form>
    <h:panelGrid id="panel" styleClass="data_table_pricing" columns="3">

        <h:outputText value="Title"/>

        <h:inputText id="title" value="#{pricingForm.title}" validatorMessage="Value is too big.">
            <f:validateLength minimum="0" maximum="40" />
            <f:ajax event="change" render="@form"/>
        </h:inputText>

        <h:message id="title_message" for="title" style="color:red"/>

        <!-- // -->

        <h:outputText value="First name"/>

        <h:inputText id="first_name" value="#{pricingForm.firstName}" validatorMessage="Value is too big.">
            <f:validateLength minimum="0" maximum="40" />
            <f:ajax event="change" render="@form"/>
        </h:inputText>

        <h:message id="first_name_message" for="first_name" style="color:red"/>

        <!-- // -->

        <h:outputText value="Last name"/>

        <h:inputText id="last_name" value="#{pricingForm.lastName}" validatorMessage="Value is too big.">
            <f:validateLength minimum="0" maximum="40" />
            <f:ajax event="change" render="@form"/>
        </h:inputText>

        <h:message id="last_name_message" for="last_name" style="color:red"/>

        <!-- // -->

    </h:panelGrid>

    <h:commandLink value="reset" class="link" type="reset" style="margin: 20px;">
        <f:ajax execute="@form" render="@form"/>
    </h:commandLink>
    <h:commandLink value="Next" class="link" style="margin: 20px;" actionListener="#{pricingForm.calculatorPage()}">
        <f:ajax execute="@form" render="@form"/>
    </h:commandLink>

</h:form>

当我在多个输入字段中插入大值时,我只看到一条错误消息。看起来在呈现表单时未保存旧值。你帮我解决这个问题吗?

【问题讨论】:

    标签: validation jsf message


    【解决方案1】:

    这个,

    <f:ajax event="change" render="@form"/>
    

    意思同:“当当前输入的值发生变化时,提交并处理当前输入并更新整个表单”。

    所以,其他输入没有被处理/验证,更新基本上清除了以前的消息。

    您可能只想更新相关的消息。例如。如果您是第一次输入:

    <f:ajax render="title_message" />
    

    我只省略了event="change",因为这是&lt;h:inputXxx&gt; 组件中的默认设置。

    另见:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多