5 Replies Latest reply on Jul 16, 2009 6:15 PM by asookazian

    FacesMessage not displaying after validation via form submission

    asookazian

      I have a xhtml/JSF page in which the validation is working and displaying on AJAX submission (onblur for HtmlInputText) and is working but not displaying when I click submit button (HTTP POST).


      I am seeing the following in the console in the 2nd case:


      16:06:49,151 INFO  [lifecycle] WARNING: FacesMessage(s) have been enqueued, but may not have been displayed.
      sourceId=mainForm:findingCode1:_findingCode1[severity=(INFO 0), summary=(invalid value), detail=(invalid value)]



      What must I do to get the invalid value text to display next to the field like in the AJAX onblur case?


      After submission of the form, error text is not displaying even though the ValidationException is thrown from the Validator class.


      .xhtml:


      <tr>
                                                                  <th align="left" width="50%"><h:outputText
                                                                       value="Problem Code 1: " /></th>
                                                                  <td align="left" width="50%"><a4j:region id="fcRegion1">
                                                                       <s:decorate id="findingCode1" template="layout/edit.xhtml">
                                                                            <h:inputText id="_findingCode1"
                                                                                 value="#{createRepairCase.findingCode1}"
                                                                                 validator="seamValidatorCodes">
                                                                                 <a4j:support event="onblur" 
                                                                                                 reRender="findingCode1"
                                                                                                 bypassUpdates="true" 
                                                                                                 eventsQueue="myQueue"
                                                                                                 requestDelay="200" 
                                                                                                 ignoreDupResponses="true"
                                                                                                 oncomplete="setFocusFindingCodes();" />
                                                                            </h:inputText>
                                                                            <a4j:status id="s4" for="fcRegion1">
                                                                                 <f:facet name="start">
                                                                                      <h:graphicImage value="/img/spinner.gif" />
                                                                                 </f:facet>
                                                                            </a4j:status>
                                                                       </s:decorate>
                                                                  </a4j:region></td>
                                                             </tr>



      SeamValidatorCodes:


      @Name("seamValidatorCodes") 
      @Scope(ScopeType.CONVERSATION)
      @org.jboss.seam.annotations.faces.Validator
      public class SeamValidatorCodes implements javax.faces.validator.Validator, java.io.Serializable
      
      public void validate(FacesContext context, UIComponent cmp, Object value) throws ValidatorException {
           if (!validateCodes(code))
                throw new ValidatorException(new FacesMessage("invalid value"));
      }



      in both cases (onblur AJAX or form submit), the ValidatorException is being thrown.


      backing bean:


      @Stateful
      @Name("createRepairCase")
      @SuppressWarnings("unchecked")
      public class CreateRepairCaseAction implements CreateRepairCaseLocal {
      
         public String submit(){
            ....
      
            entityManager.flush();     
       
            .....
      
            return "/RepairCaseDetails.xhtml";   //this is the next page in the page flow of the use case
      }






        • 1. Re: FacesMessage not displaying after validation via form submission
          asookazian

          edit.xhtml:


          <ui:composition  xmlns="http://www.w3.org/1999/xhtml"
                           xmlns:ui="http://java.sun.com/jsf/facelets"
                           xmlns:h="http://java.sun.com/jsf/html"
                           xmlns:f="http://java.sun.com/jsf/core"
                           xmlns:s="http://jboss.com/products/seam/taglib">
                            
             
             <div class="entry">           
                  <s:label styleClass="name #{invalid?'errors':''}">
                      <ui:insert name="label"/>
                      <s:span styleClass="required" rendered="#{required}">*</s:span>
                  </s:label>
                  
                  <span class="value #{invalid?'errors':''}">
                      <s:validateAll>
                          <ui:insert/>
                      </s:validateAll>
                  </span>    
                  <BR/>    
                  <s:message styleClass="errors"/>   
              </div>     
              
          </ui:composition>



          If I add <rich:messages globalOnly="false"/> in the facelet, it still doesn't render the error msg (invalid value) in the case of form submission...

          • 2. Re: FacesMessage not displaying after validation via form submission
            asookazian

            Nevermind, I just lied (xhtml/browser refresh issue).  <rich:messages globalOnly="false"/> does display the error msg now.  However, how can I get the error to display next to the HtmlInputText as specified in edit.xhtml when i submit the form?  I'd like to keep it consistent if possible.


            I don't understand why it sometimes works (for onblur a4j:support) but not for form submit...

            • 3. Re: FacesMessage not displaying after validation via form submission
              asookazian

              when I view the page source (HTML) after form submission, I do find the HtmlInputText field's corresponding HTML markup:


              <input id="mainForm:findingCode1:_findingCode1" type="text" name="mainForm:findingCode1:_findingCode1" value="W3" onblur="A4J.AJAX.Submit('mainForm:fcRegion1','mainForm',event,{'eventsQueue':'myQueue','parameters':{'mainForm:findingCode1:j_id204':'mainForm:findingCode1:j_id204'} ,'actionUrl':'/BETS/CreateRepairCase.seam','oncomplete':function(request,event,data){setFocusFindingCodes();},'similarityGroupingId':'mainForm:findingCode1:j_id204','ignoreDupResponses':true,'requestDelay':200} )" />



              So why is JSF/facelets/Seam outputting this?


              16:33:05,416 INFO  [lifecycle] WARNING: FacesMessage(s) have been enqueued, but may not have been displayed.
              sourceId=mainForm:findingCode1:_findingCode1[severity=(INFO 0), summary=(invalid value), detail=(invalid value)]

              • 4. Re: FacesMessage not displaying after validation via form submission
                asookazian

                The LRC is still active (running) after form submission.


                I changed the return type of the submit() method to void and same behavior....

                • 5. Re: FacesMessage not displaying after validation via form submission
                  asookazian

                  Here's the solution.  I wasn't reRendering the problemCodeX and findingCodeX columns in the page (which is the typical root cause of that FacesMessage(s) have been enqueued warning but I forgot :).


                  <a4j:commandButton value="#{createRepairCase.submitButtonLabel}"
                                     eventsQueue="myQueue" 
                                     requestDelay="200" 
                                     ignoreDupResponses="true"
                                     action="#{createRepairCase.submit}"
                                     reRender="serialNumber, equipmentType, repairType, macAddressDecorator, receiptDateDecorator, findingCode1, findingCode2, findingCode3, problemCode1, problemCode2, problemCode3" />



                  Since I am using AJAX live validation for each FC and PC column (three each), I don't need to reRender all of them after form submission.
                                                         
                  Now I was reading the Richfaces doc explanation for reRender attribute of <a4j:commandButton>:


                  Id['s] (in format of call UIComponent.findComponent()) of components, rendered in case of AjaxRequest caused by this component. Can be single id, comma-separated list of Id's, or EL Expression with array or Collection



                  Is it possible to do something like this?


                  reRender="serialNumber, equipmentType, repairType, macAddressDecorator, receiptDateDecorator, #{code}



                  I tried that and it did not work (I was outjecting the code conversation context variable from my validator class).


                  If you use EL expression in reRender attribute, are you disallowed from using hardcoded string values like above?


                  ie.

                  reRender="#{foo}"

                  that may work?