我有一个输入验证表格如下:
<h:form id="insurance-form" rendered = "#{(param['insSaved']=='editable')}">
<div id="insurance-info">
<ul id="form-labels" style="text-align:left;">
<li>Insurance Company </li>
<li>Policy Number </li>
<li>Coverage Amount </li>
<li>Agent's Phone Number </li>
<li>Agent's Email </li>
</ul>
<ul>
<li>
<h:inputText value="#{residenceBeans.insuranceCompany}" id="insurance-company" required="true" requiredMessage="company is required"/>
<h:message for="insurance-company" styleClass="validation-error-msg insuarnce-validation"/>
</li>
<li>
<h:inputText value="#{residenceBeans.policyNumber}" id="insurance-policy" required="true" requiredMessage="number is required"/>
<h:message for="insurance-policy" styleClass="validation-error-msg insuarnce-validation"/>
</li>
<li>
<h:inputText value="#{residenceBeans.coverageAmount}" id="insurance-amount" required="true" requiredMessage="coverage amount is required"/>
<h:message for="insurance-amount" styleClass="validation-error-msg insuarnce-validation"/>
</li>
<li>
<h:inputText value="#{residenceBeans.agentPhone}" id="insurance-phone" required="true" requiredMessage="phone is required"/>
<h:message for="insurance-phone" styleClass="validation-error-msg insuarnce-validation"/>
</li>
<li>
<h:inputText value="#{residenceBeans.agentMail}" id="insurance-mail" required="true" requiredMessage="email is required">
<f:validator validatorId="emailValidator"/>
</h:inputText>
<h:message for="insurance-mail" styleClass="validation-error-msg insuarnce-validation"/>
</li>
</ul>
<h:commandLink value="SAVE POLICY INFORMATION" action="#{residenceBeans.saveInsuranceInfo}" styleClass="insurance-link-container">
<f:param name="insSaved" value="saved"/>
</h:commandLink>
</div>
</h:form>
将字段留空并提交表单时我希望显示验证消息,但我收到以下警告:
21:20:47,671 INFO [javax.enterprise.resource.webcontainer.jsf.renderkit] (http--127.0.0.1-8080-3) WARNING: FacesMessage(s) have been enqueued, but may not have been displayed
sourceId=insurance-form:insurance-company[severity=(ERROR 2), summary=(company is required), detail=(company is required)]
sourceId=insurance-form:insurance-policy[severity=(ERROR 2), summary=(number is required), detail=(number is required)]
sourceId=insurance-form:insurance-amount[severity=(ERROR 2), summary=(coverage amount is required), detail=(coverage amount is required)]
sourceId=insurance-form:insurance-phone[severity=(ERROR 2), summary=(phone is required), detail=(phone is required)]
sourceId=insurance-form:insurance-mail[severity=(ERROR 2), summary=(email is required), detail=(email is required)]
请告知如何解决这个问题。
答案 0 :(得分:7)
未显示消息,因为在回发时根本没有呈现整个表单。您指示仅在insSaved
的请求参数的值为editable
时才呈现表单。但是,在提交按钮中,它已被更改为saved
,因此表单基本上永远不会在回发时呈现,因此封闭的消息也不会。考虑到代码的设置方式,这是完全预期的行为。
如果您想要在回发时出现验证错误的情况下显示表单,那么您需要相应地更改其rendered
属性。取代
<h:form id="insurance-form" rendered="#{(param['insSaved']=='editable')}">
通过
<h:form id="insurance-form" rendered="#{(facesContext.postback and facesContext.validationFailed) or (param['insSaved'] == 'editable')}">
答案 1 :(得分:-1)
我遇到过这个问题,响应是删除primefaces库,然后再次添加到库列表中。