0 Replies Latest reply on Jun 27, 2009 8:57 AM by Andreas Marx

    Problem with validation on an ajax supported h:selectOneMenu

    Andreas Marx Newbie

      I want to implement a validation on an onchange event of a selectOneMenu. This menu is part of a h:datatable and it must be guaranted that the selected value is not already selected anywhere else in the table. I think this is a situation which might happen quit often. But I am not able to solve it.

      This is part of my xhtml:

      <h:dataTable id="exTable" var="_exWrapper" value="#{exercises}">
           <f:facet name="header">#{messages.exName}</f:facet>
           <h:selectOneMenu id="selectExercises" value="#{_exWrapper.exercise}" 
                   required="true" converter="#{exerciseConverter}"
               <s:selectItems var="exercise" value="#{exerciseManager.exercises}" 
                   <a4j:support event="onchange" reRender="selectExercise, messagesField" 

      I tried the validator approach:

      public class MyGymExerciseValidator implements Validator {
          public void validate(FacesContext arg0, UIComponent arg1, Object arg2)
                  throws ValidatorException {
              ExWrapperHome home = (ExWrapperHome) Component.getInstance("exWrapperHome");
              if (!myGymHome.checkExercise((Exercise) arg2)) {
                  throw new ValidatorException(new FacesMessage());

      I created an empty FacesMessage because I didn't succeed in getting access to the resource boundle. Therefore I use the validatorMessage.
      Anything works: the validator is called, the exception is thrown but: the problem is that neither message is displayed nor the selectonemenu is rerendered.
      But I see the following message in the console:

      08:29:26,203 INFO  [lifecycle] WARNING: FacesMessage(s) have been enqueued, but may not have been displayed.
      sourceId=myForm:exTable:3:selectExercises[severity=(ERROR 2), summary=(the message), detail=(the message)]

      The messages panel is defined in the template.xhtml:

          <rich:layoutPanel position="top" width="100%">
           <a4j:outputPanel id="messagesField" ajaxRendered="true">
             <h:messages id="messages" globalOnly="true" styleClass="message"
                errorClass="errormsg" infoClass="infomsg" warnClass="warnmsg"
                rendered="#{showGlobalMessages != 'false'}" />
           <ui:insert name="body" />

      I suppose that after the exception is thrown the reRender of the ajax request does not happen. I tried a lot and searched the www but did not find a hint that helped me.

      Any suggestions?