8 Replies Latest reply on Jun 14, 2008 8:17 PM by frer

    SelectOneMenu onchange

    frer

      Hi,


      Is it possible to have an event called when the selectOneMenu component is modified.


      For example for the locale selection:


                  <h:form id="locale">
                      <h:selectOneMenu value="#{localeSelector.localeString}" >
                          <f:selectItems value="#{localeSelector.supportedLocales}"/>
                      </h:selectOneMenu>
                      <h:commandButton action="#{localeSelector.select}" value="#{messages['ChangeLanguage']}"/>
                  </h:form>
      



      I would prefer not to have any commandButton but rather only a select and when you change the select the method


      #{localeSelector.select}
      



      would be called.


      Is this possible? Is so how?


      Thank you,


      Francois

        • 1. Re: SelectOneMenu onchange
          accless

          User RichFaces 
          a:support-Tag within the h:selectOneMenu-Tag.


          This meets your requirements

          • 2. Re: SelectOneMenu onchange
            damianharvey.damianharvey.gmail.com

            You'll be wanting to read up on Richfaces and the a4j:support tag.


            <h:form id="locale">
                <h:selectOneMenu value="#{localeSelector.localeString}" >
                    <f:selectItems value="#{localeSelector.supportedLocales}"/>
                    <a4j:support event="onchange" action="#{localeSelector.select}" ajaxSingle="true"/>
                </h:selectOneMenu>
            </h:form>
            


            Cheers,


            Damian.

            • 3. Re: SelectOneMenu onchange
              frer

              Thank you both for your answers!


              How can I integrate ajax4jsf to my seam deployment...I added the oscache-2.3.2.jar and the ajax4jsf.jar in my WEB-INF/lib but do I need to specify anything in my web.xml?


              Thank you,


              Francois

              • 4. Re: SelectOneMenu onchange
                dan.j.allen

                In this case Ajax4jsf might be overkill (though you could certainly use it). You can simply use the JavaScript onchange event:


                onchange="submit()"

                • 5. Re: SelectOneMenu onchange
                  frer

                  Thanks Dan!  That's actually a better solution for me since I do not wish to use ajax4jsf anywhere else (at least for now) and I was having trouble setting up ajax4jsf...


                  Here is my final code snippet:


                              <h:form id="locale" action="#{localeSelector.select}">
                                  <h:selectOneMenu value="#{localeSelector.localeString}" onchange="submit()">
                                      <f:selectItems value="#{localeSelector.supportedLocales}"/>
                                  </h:selectOneMenu>
                              </h:form>
                  



                  Thanks again,


                  Francois

                  • 6. Re: SelectOneMenu onchange
                    dan.j.allen

                    You shouldn't need to. Seam has a built-in filter that is automatically activated when Ajax4jsf is on the classpath. The only JAR files you need to add Ajax4jsf is:



                    • jboss-seam-ui.jar (this is where the filter is defined)

                    • richfaces-api.jar

                    • richfaces-impl.jar

                    • richfaces-ui.jar



                    Yes, RichFaces is Ajax4jsf. You can use Ajax4jsf alone, but its just easier to throw it all in together.

                    • 7. Re: SelectOneMenu onchange
                      dan.j.allen

                      Make sure you have the Seam filter configured (in web.xml).

                      • 8. Re: SelectOneMenu onchange
                        frer

                        Ok thanks, I'll try that if ever I find the need for ajax4jsf but for now your Javascript option is perfect.


                        Thanks again,


                        François