6 Replies Latest reply on Mar 25, 2008 8:46 PM by jgreene

    submitting selected option when using <s:convertEnum...>

    jgreene

      Hi -
      I have a pair of select boxes, and the options for the 2nd one is dependent on the selection made in the 1st one.  Here's the code I use for this:


      <h:outputLabel for="serviceId" value="Service:" />
      <h:selectOneMenu id="serviceId" value="#{myuser.service}">
         <s:selectItems value="#{serviceRankListManager.services}"
         var="service" label="#{service.serviceText}" />
         <s:convertEnum />
         <a4j:support event="onchange" reRender="rankId" immediate="true" />
      </h:selectOneMenu>
                              
      <h:outputLabel for="rankId" value="Rank:" />
      <h:selectOneMenu id="rankId" value="#{myuser.rank}">
         <s:selectItems value="#{userManager.userRanks}" 
         var="rank" label="#{rank.rankText}" />
         <s:convertEnum/>
      </h:selectOneMenu>



      I want to be able to submit (via ajax) the selected option in the first select box so that the new list of ranks can be generated based on the selected service.  So the first thing I thought of was to add an a4j:actionparam inside the aj4:support... tag that assigned the selected value to a property in my manager bean.  Is there a clean way to do this considering that I'm using the enum converter (service is an enum property of User)?  It might be easier (not sure) using a List of SelectItem objects, but I don't really want to do that unless I have to.  So the bottom line is, Can I use the a4j:actionparam... tag wrapped inside the a4j:support... tag to pass back the selected enum value to the manager bean?  If so, how do I specify the enum value in the a4j:actionparam tag?


      Any help would be greatly appreciated.  Thank you.


      - Joe




        • 1. Re: submitting selected option when using <s:convertEnum...>
          damianharvey.damianharvey.gmail.com

          It shouldn't matter whether you use the Enum or the List. All you need to do is add the <a:support> to the first drop down (as you've done), but remove the immediate="true". If you're concerned about performance instead consider ajaxSingle="true". You definitely don't need the actionParam.


          Cheers,


          Damian.

          • 2. Re: submitting selected option when using <s:convertEnum...>

            I have done something similar a while ago (just some copy paste):


            <h:selectOneRadio id="baseDocumentType" immediate="true" value="#{order.type}" layout="horizontal">
                 <s:convertEnum />
                 <s:selectItems value="#{order.types}" var="type" label="#{type.name}" />
                 <a:support event="onchange" reRender="chooseBaseDocument" />
            </h:selectOneRadio>
             



            panelGrid with id 'chooseBaseDocument' gets rerendered and uses the inputted data (order.type).


            Some bean code:


            private BaseDocumentType[] types = BaseDocumentType.values();
            
            public BaseDocumentType[] getTypes() {
               return types;
            }
            
            private BaseDocumentType type = BaseDocumentType.BLABLA;
            
            public BaseDocumentType getType() {
               return type;
            }
            
            public void setType(BaseDocumentType type) {
               this.type = type;
            }
            
            



            One could (and I should) probably make use of @Factory, @DataModel and @DataModelSelection in some way here...

            • 3. Re: submitting selected option when using <s:convertEnum...>
              jgreene

              Damian -
              thanks for the quick response, Damian.  The approach you described worked great.  I thought I had tried it earlier, but I must have done something wrong before.  It makes perfect sense, and i needed to use the ajaxSingle attribute because I have fields in the same form that are required, and I don't want to validate those until the actual submit.  Thanks again.
              - Joe

              • 4. Re: submitting selected option when using <s:convertEnum...>
                jgreene

                Daniel -
                Thanks for the response.  I've modified my approach to be like yours and Damian's suggestion. It works great.  Thanks again.
                - Joe

                • 5. Re: submitting selected option when using <s:convertEnum...>
                  damianharvey.damianharvey.gmail.com

                  Just as an FYI there is currently a bug with ajaxSingle. I've seen it when trying to reRender an inputText (when the value never renders), but otherwise haven't noticed it.


                  Workaround is to surround your calling component with <a:region>


                  Cheers,


                  Damian.

                  • 6. Re: submitting selected option when using <s:convertEnum...>
                    jgreene

                    Hi Damian -
                    Yes, I've seen this bug, and have just posted another question to the richfaces forum:


                    My Link


                    I've used the a4j:region around my rich:suggestionbox (see forum link above), but still have problems that seems to be related to having validation rule (required) on the field(s).


                    - Joe