当通过 AJAX 提交表单时,我正在验证表单的输入项,但表单未在该h:message
部分呈现所需的消息。通过完整的回发方法验证方法可以正常工作,但在 AJAX 提交方法中,所需的消息不会呈现。
这是代码:
项目.xhtml
<h:form class="form-signin" id="registrationform" enctype="multipart/form-data">
<h:panelGroup id="panel" border="0" cellpadding="0" cellspacing="10" styleClass=" labelText">
<f:facet name="header">
<h:messages id="message" style="color:red;margin:8px;" globalOnly="true" />
</f:facet>
</h:panelGroup>
<div class="section-title">
<div class="title">Item Description</div>
</div>
<h:panelGrid columns="6">
<h:outputLabel for="goodName" value="Names of good *" styleClass="labelforItems" />
<h:outputLabel for="quantity" value="Quantity *" styleClass="labelforItems" />
<h:inputText id="quantity" style="#{ component.valid ? 'border-color:#ccc;' : 'border-color:red;'}" value="#{registrationBean.quantity}" styleClass="form-control input-adjust quantity" required="true" requiredMessage="Package quantity is required." />
<h:outputLabel for="hscode" value="HS Code*" styleClass="labelforItems" />
<h:inputText id="hscode" value="#{registrationBean.hscode}" styleClass="form-control input-adjust hscode" required="true" requiredMessage="HS Code is required" />
<h:outputLabel for="goodsDescription" value="Description *" styleClass="labelforItems" />
<h:inputTextarea id="goodsDescription" value="#{registrationBean.descriptions}" style="#{ component.valid ? 'border-color:#ccc;' : 'border-color:red;'}" required="true" requiredMessage="Goods description is required." styleClass="form-control textareawh goodsDescription" />
<h:commandLink value="Add" id="addItem" action="#{registrationBean.addItemAction}" onclick="pkgDiv()" styleClass="btn btn-primary">
<f:ajax execute="goodName quantity brand model hscode goodsDescription" render=":registrationform:panel" />
</h:commandLink>
<h:outputLabel />
<h:outputLabel />
<h:outputLabel />
<h:outputLabel />
</h:panelGrid>
</h:form>