12 Replies Latest reply on Apr 7, 2009 8:35 PM by Helge Rottmann

    Problem with ajax enabled h:selectOneMenu

    Raghunath Nandy Newbie

      Hi ALL,
      I'm trying to implement 4 linked comboboxes.
      Example: http://www.partsallover.com.au/home


      My code is :


      registration.components.xml :


       <framework:restrictions>
                 <value>college.university.id = #{ClassroomSearch.university.id}</value>
             </framework:restrictions>
          
         </framework:entity-query>
          <factory name="collegeListUnderUniversityList" value="#{collegeListUnderUniversityQuery.resultList}"  />
          



      And the jsf is ...


      <s:decorate template="../../layout/edit.xhtml">
                      <ui:define name="label">University</ui:define>
                              <h:selectOneMenu  id="col1" value="#{ClassroomSearch.university}">
                               <s:selectItems 
                                       value="#{universityList.resultList}"  
                                       var="h" label="#{h.community.name}" 
                                       noSelectionLabel="None"
                                       />
                                       <s:convertEntity />
                                       
                                       <a4j:support event="onchange"  
                                       action="#{ClassroomSearch.classroomSearch}" 
                                      reRender="collegeBox"  bypassUpdates="false" ajaxSingle="true"/>
                                      
                                      </h:selectOneMenu>
                      
                  </s:decorate>
            <s:decorate  template="../../layout/edit.xhtml">
              <a4j:outputPanel id="collegeBox" >
                
                      <ui:define name="label">College</ui:define>
                              <h:selectOneMenu  id="col2" value="#{ClassroomSearch.college}" 
                              >
                               <s:convertEntity />
                              
                               <s:selectItems 
                                       value="#{collegeListUnderUniversityList}"  
                                       var="h" label="#{h.community.name}" 
                                       noSelectionLabel="None"
                                       />
                                        
                                       
                                       <a4j:support event="onchange" 
                                       action="#{ClassroomSearch.classroomSearch2}" 
                                       reRender="CourseBranch"/>
                                      </h:selectOneMenu>
                
                        </a4j:outputPanel>
                              </s:decorate>



      here I'm getting


      07:00:37,562 INFO  [lifecycle] WARNING: FacesMessage(s) have been enqueued, but may not have been displayed.
      sourceId=user:atestForm:j_id151:col2[severity=(ERROR 2), summary=(value is not valid), detail=(value is not valid)]



      In the query restrictions  ,if i replace ClassroomSearch.university.id
      to 1 (hard code a sample value) .. it's able to work fine.
      But the dynamic population of query restrictions is not working.


      I have gone through several forums like this ,but of no use..
      I tried my best to find the clue :(


      plz help me ..


      thanks
      raghu

        • 1. Re: Problem with ajax enabled h:selectOneMenu
          Raghunath Nandy Newbie

          hi all,


          this issue is became big hurdle for us..
          please help me.. is this a bug. is there any other altrnstives ..


          plz suggest us


          thanks
          raghu

          • 2. Re: Problem with ajax enabled h:selectOneMenu
            Aldo Bonzi Novice

            This seems to be similar to your problem

            • 3. Re: Problem with ajax enabled h:selectOneMenu
              Raghunath Nandy Newbie
              Problem with dynamic h:selectOneMenu with a4j:support

              I'm not able to fix my proble still.. And I got some trace for the issue.
              Error:
              `
              18:17:32,593 INFO  [lifecycle] WARNING: FacesMessage(s) have been enqueued, but may not have been displayed.
              sourceId=user:atestForm:atestForm2:j_id151:col2[severity=(ERROR 2), summary=(value is not valid), detail=(value is not valid)]`

              Trace:
              The proble is at selectOneMenu item vaidation is failing evnthough the EntityConverter
              is able to map the entity with select-option value. The component isValid is returning false.
              In other successful cases it's true ,with this I'm able to guess that select item is becoming invalid
              after convertions phase.
              I know read that the above failure case is unpredictable.

              Code fragments:
              I did a clear debug over seam,jboss-el,jsf-mojarra source codes. In the following code is for
              select items represents jsf selectitems component of selectOneMenu. Items variable is getting
              populated with only single value(noSelectionValue), because of this , selected value is not matched woth
              the items. This maight be JSF bug, but I'm not sure of it.

              `
              javax.faces.component.SelectUtils
              ...
              static boolean matchValue(FacesContext ctx,
                                            UIComponent component,
                                            Object value,
                                            Iterator items,
                                            Converter converter) {

                      while (items.hasNext()) {
                          SelectItem item = (SelectItem) items.next();
                          if (item instanceof SelectItemGroup) {
                              SelectItem subitems[] =
                                    ((SelectItemGroup) item).getSelectItems();
                              if ((subitems != null) && (subitems.length > 0)) {
                                  if (matchValue(ctx, component, value, new ArrayIterator(subitems), converter)) {
                                      return (true);
                                  }
                              }
                          } else {
                              Object itemValue = item.getValue();
                              if (itemValue == null && value == null) {
                                  return (true);
                              }
                              if ((value == null) ^ (itemValue == null)) {
                                  continue;
                              }
              ...
              `

              If I escape validation using immediate (true) in a4j:support ,it's not populating values further.

              I'm not sure in which method http://www.partsallover.com.au got implemented this. Is there any
              workaround ,for this issue.

              thanks
              raghu

              • 4. Re: Problem with ajax enabled h:selectOneMenu
                Raghunath Nandy Newbie

                hi Aldo ,


                thanks for your reply ..
                here I'm using single entityManager. Your link also have same
                kind of issue,but the error message remains same for different situations.


                thanks
                raghu

                • 5. Re: Problem with ajax enabled h:selectOneMenu
                  Ingo Jobling Master

                  Hi Raghuath,


                  18:17:32,593 INFO [lifecycle] WARNING: FacesMessage(s) have been enqueued, but may not have been displayed.
                  sourceId=user:atestForm:atestForm2:j_id151:col2[severity=(ERROR 2), summary=(value is not valid), detail=(value is not valid)]



                  This message indicates that the selected value is not in the list of values.  This is a validation that is performed by JSF SelectOne components.


                  It seems that conversion is failing.  Try displaying the source HTML to see what is being rendered (the value attribute of the <option> tag, as well as the value of the <select>)


                  Try writing your own converter, it is quite simple (see the Seam reference), and, if the problem persists, set breakpoints in the getAsString and getAsObject methods to see what is going on!


                  Don't lose hope, once you have figured out what is going wrong it will work fine. We chain select menus in this fashion, using A4J, with no problem.

                  • 6. Re: Problem with ajax enabled h:selectOneMenu
                    Ingo Jobling Master

                    <a4j:support event="onchange"  
                                                     action="#{ClassroomSearch.classroomSearch}" 
                    



                    How you are passing the selected value to be used in the Query criteria?  Don't this require something like :


                    <a4j:support event="onchange"  
                                                     action="#{ClassroomSearch.classroomSearch(selectedValue)}" 
                    



                    • 7. Re: Problem with ajax enabled h:selectOneMenu
                      Raghunath Nandy Newbie
                      Your reply recharged me with full bottle bear :) , my debug outcomes ..

                      There is no problem with EntityConverter, I created my own entity converter and it's
                      also working like the same way. I'm able to see the converted entity object , but after conversion, "SelectUtils.matchValue" is failing because the items list is filled with only one value 
                      UISelectItems$NullableSelectItem, it should fill with entity also , Im not able to get where
                      it's going mad ..
                      Following is the stacktrace for the iterator making ..
                      Stack trace
                      `SelectItemsIterator.<init>(UIComponent) line: 75
                              HtmlSelectOneMenu(UISelectOne).validateValue(FacesContext, Object) line: 144   
                              HtmlSelectOneMenu(UIInput).validate(FacesContext) line: 875    
                              HtmlSelectOneMenu(UIInput).executeValidate(FacesContext) line: 1072    
                              HtmlSelectOneMenu(UIInput).processValidators(FacesContext) line: 672   
                              AjaxViewRoot$3.invokeContextCallback(FacesContext, UIComponent) line: 439      
                              InvokerCallbackWrapper(ContextCallbackWrapper).invokeContextCallback(FacesContext, UIComponent) line: 24       
                              HtmlSelectOneMenu(UIComponent).invokeOnComponent(FacesContext, String, ContextCallback) line: 711`

                      And

                      ` action="#{ClassroomSearch.classroomSearch}`

                      is not required , i added this for debug purpose ...

                      thanks
                      raghu
                      • 8. Re: Problem with ajax enabled h:selectOneMenu
                        Raghunath Nandy Newbie

                        here my observation is ,
                        the ajax made dom is not able to regain it's structure in the server.


                        thanks
                        raghu

                        • 9. Re: Problem with ajax enabled h:selectOneMenu
                          Raghunath Nandy Newbie

                          I guess im doing mistake .. let me try with some other samples..


                          thanks
                          raghu

                          • 10. Re: Problem with ajax enabled h:selectOneMenu
                            Raghunath Nandy Newbie

                            Got it,


                            this bug gave me lot of experience in internal flow of seam,jsf ..


                            any how mistake is small one ..
                            Everything should be under conversation
                            The problem here is the error message , using this error message we beginners can't trace the code , so it would be better there some  seam level error messages instead of following error message ..



                            07:00:37,562 INFO  [lifecycle] WARNING: FacesMessage(s) have been enqueued, but may not have been displayed.
                            sourceId=user:atestForm:j_id151:col2[severity=(ERROR 2), summary=(value is not valid), detail=(value is not valid)]




                            thanks
                            raghu

                            • 11. Re: Problem with ajax enabled h:selectOneMenu
                              Mikael Andersson Master

                              Those error messages appear when there is a validation related error which isn't displayed on the screen.


                              Adding a <h:messages> or <rich:messages> will get rid of it.

                              • 12. Re: Problem with ajax enabled h:selectOneMenu
                                Helge Rottmann Newbie

                                The problem arises when using the template based <s:decorate> tag. The following will
                                NOT work. Removing the template="layout/edit.xhtml" will make the example work.


                                <s:decorate template="layout/edit.xhtml">
                                  <a:region >     
                                    <h:selectOneMenu value="#{communicationAction.selectedCompany}" required="true" >
                                      <a:support event="onchange" reRender="test"  />
                                      <s:selectItems value="#{companyList.resultList}" var="company" label="#{company.companyName}" noSelectionLabel="auswählen" />          
                                      <s:convertEntity/>     
                                    </h:selectOneMenu>
                                  </a:region>
                                </s:decorate>
                                <h:outputText id="test" value="#{communicationAction.selectedCompany.companyName}"/>