Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

warning facesmessage(s) have been enqueued but may not have been displayed

i have a form with inputs validation as follows:

<h:form id="insurance-form" rendered = "#{(param['insSaved']=='editable')}">
    <div id="insurance-info">
        <ul id="form-labels" style="text-align:left;">
            <li>Insurance Company&nbsp;</li>
            <li>Policy Number&nbsp;</li>
            <li>Coverage Amount&nbsp;</li>
            <li>Agent's Phone Number&nbsp;</li>
            <li>Agent's Email&nbsp;</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>   

when leaving fields empty and submitting the form i am expecting the validation messages to be displayed, but instead i am getting the following warning:

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)]

please advise how to fix that.

like image 204
Mahmoud Saleh Avatar asked Oct 29 '12 19:10

Mahmoud Saleh


1 Answers

The messages are not been displayed because the whole form is not been rendered at all on postback. You instructed the form to be rendered only when the request parameter of insSaved has a value of editable. However, in the submit button it's been changed to saved, so the form is basically never rendered on postback and the enclosed messages thus also not. This is fully expected behaviour given the way how the code is set up.

If you'd like to show the form in case of a validation error on postback anyway, then you'd need to alter its rendered attribute accordingly. Replace

<h:form id="insurance-form" rendered="#{(param['insSaved']=='editable')}">

by

<h:form id="insurance-form" rendered="#{(facesContext.postback and facesContext.validationFailed) or (param['insSaved'] == 'editable')}">
like image 65
BalusC Avatar answered Oct 18 '22 19:10

BalusC