3 Replies Latest reply on Jun 10, 2008 6:46 PM by Rob Allen

    selectOneMenu & Richfaces help please?

    Rob Allen Newbie

      Hi all -

      I'm brand spanking new to JSF and RichFaces. I have a task I need to accomplish and I'm certain RichFaces will do it for me, but I'm not sure how or even where to look.

      Here's what I need to do: I have a page that has two select lists, right now implemented as <h:selectOneMenu> items. Each currently works independently. What I need to happen is when the user selects a value in the first pull-down, the options in the second pull-down should change based on the selection.

      Can anyone direct me where to look? I'm a pretty good software plagarist, so a link to an example would help.

      -- Rob

        • 1. Re: selectOneMenu & Richfaces help please?
          Sergey Smirnov Master

          Just do what you want. I.e. add a4j:support with event="onchange" to the first selectOneMenu and point to to the second selectOneMenu's id with reRender attribute.
          If you have a validation rules on the other fields at the same form, add ajaxSingle="true" attribute to the a4j:support to prevent those unnecessary validations fired.
          In case you still have a problem or/and misunderstanding, post the code snippet of the current page code you have problem with.

          • 2. Re: selectOneMenu & Richfaces help please?
            Rob Allen Newbie

            Thanks, Sergey -- that should head me in the right direction. I'll post back either if I have trouble, or I'll post my solution.

            -- Rob

            • 3. Re: selectOneMenu & Richfaces help please?
              Rob Allen Newbie

              That worked great!

              The tag I added to my selectOneMenu item was:

              <a4j:support event="onchange" reRender="toGeneralist" ajaxSingle="true"/>

              ...where the selectOneMenu I wanted to affect had an id="toGeneralist".

              One little thing I had to work out on my own was that within the bean method that generates the list for my "toGeneralist" pull-down menu, in order to modify the query with the selected item from the first menu I had to inject the seam component that was the target of the selected value.

              In other words, my selectOneMenu was:
              <h:selectOneMenu id="projectDistrict" value="#{esrsList.esrs.projectDistrict}" required="false">

              So in the bean method I needed a declaration:
              @In EsrsList esrsList;

              I could then reference the component as a parameter to my query as follows:

              query.setParameter("district", "#{esrsList.esrs.projectDistrict}");

              That's all standard Seam stuff, though. The RichFaces thing worked perfectly.

              Thanks very much (and I hope this thread helps some other n3wbi3 down the road)!

              -- Rob