6 Replies Latest reply on Apr 6, 2009 5:31 PM by frer

    h:selectOneMenu(s:selectItems and f:converter) problem

    ericji

      I can't get the value of selectItems in stateless ejb as below:


      <h:selectOneMenu id="selOrg" value="#{MyBean.selOrg}" >
          <s:selectItems value="#{OrgBean.allOrg}" var="org" label="#{org.name}" noSelectionLabel=" -- Select --" />
          <f:converter converterId="orgConverter"/>
      </h:selectOneMenu>



      and I can get it from:


      <h:selectOneMenu id="selOrg" value="#{MyBean.selOrg}" >
          <f:selectItem itemLabel="-- select --" itemValue=""/>  
          <f:selectItem itemLabel="Myorg" itemValue="1"/>
      </h:selectOneMenu>



      But I need to the dynamic list, how to fix it? thanks.

        • 1. Re: h:selectOneMenu(s:selectItems and f:converter) problem
          dhinojosa

          What's orgConverter? and can't you use


          <s:convertEntity>
          




          ?

          • 2. Re: h:selectOneMenu(s:selectItems and f:converter) problem
            ericji

            orgConverter is my converter class,it works fine, my issue is:
            When I submit the page, invoke a MyBean method, in this method, I need the selected value from s:selectItems, but I can't get it, it's null, the set method doesn't work.
            
            set method as below:
            public void setSelOrg(String selOrg) {    
                    this.selOrg = selOrg;
            }
            


            • 3. Re: h:selectOneMenu(s:selectItems and f:converter) problem

              I am facing the same issue dude... did u get the solution ??

              • 4. Re: h:selectOneMenu(s:selectItems and f:converter) problem

                Hi!


                I am guessing your OrgBean.getAllOrg() method does not return a list of strings, but a list of object of type Org therefore, you should be using <s:convertEntity> (as Daniel suggested) and you set method (setSelOrg) should not receive a string, it should receive an object of Org type.


                Regards,

                • 5. Re: h:selectOneMenu(s:selectItems and f:converter) problem
                  ritchierd
                  Hello,

                  What if your list of items you are passing to s:selectItems is not an enumeration OR a POJO annotated with @Entity?

                  <s:convertEntity/> throws an exception if the items in the list aren't an entity.

                  What I am trying to do is similar to what the original post in this thread stated:

                  <h:selectOneMenu value="#{value}">
                                 <s:selectItems value="#{bean.choices}"
                                                var="choice"
                                                label="#{choice.label}" />
                                 <s:convertEntity/>
                  </h:selectOneMenu>

                  The issue is that #{bean.choices} returns a list of "choice" objects that have a few attributes and a getLabel() method.  The "choice" class, however, is not an Entity and has no table behind it.

                  The #{bean.choices} list is populated by a service call.

                  Do you know of any way to make a POJO an Entity without mapping it to a table so I can use the s:convertEntity tag?

                  OR

                  Do you know of any way to force the s:selectItems to use a specific converter?

                  Thanks,
                  #25
                  ~BOB~
                  • 6. Re: h:selectOneMenu(s:selectItems and f:converter) problem
                    frer

                    Hi Bob,


                    I had the same problem and had trouble formulating it.  Did you get to solve your problem?


                    I also have a list of not-entity objects and would like to iterate it.


                    For now my temp solution is to use a4j:repeat with a seletItem inside but I need to bind my result to a string instead of an object which I find annoying.  Its a workaround but its rather unclean.


                    If anyone knows of a way to solve this I'd be really interested of knowing how.


                    Thanks,


                    François