7 Replies Latest reply on Feb 28, 2008 3:54 PM by wachtda.scsi.gmx.ch

    passing value from selectOneMenu

    boki

      Hi all,
      I am trying to use selectOneMenu to pass an id back to my action. That id will then be used to look up an entity and associate it to another entity.

      <h:selectOneMenu id="categories"required="true">
         <s:selectItems value="#{prodManager.allCategories}" var="category" label="#{category.name}" />
      </h:selectOneMenu>


      prodManager has a selectedId that is used to link a Product to a Category.
      What is the proper way to pass
      #{category.catId}

      to prodManager as selectedId?

        • 1. Re: passing value from selectOneMenu
          pmuir
          <h:selectOneMenu id="categories"required="true" value="#{prodManager.selectedId}">
             <s:selectItems value="#{prodManager.allCategories}" var="category" label="#{category.name}" itemValue="#{category.catId}" />
          </h:selectOneMenu>



          And, take a look at <s:convertEntity />

          • 2. Re: passing value from selectOneMenu
            boki

            Thanks, Pete.
            Is there a way to simply pass that id w/o convertEntity? In case of convertEntity, I believe I would need to use TransactionalSeamPhaseListener, right? For now, I'd like to avoid that. 

            • 3. Re: passing value from selectOneMenu
              pmuir

              If you are using Seam 2.0.1 then what I posted will work, otherwise, you are better off using <f:selectItems /> I guess. If you are using Seam2, then you are using Seam Managed Transactions anyway.

              • 4. Re: passing value from selectOneMenu
                wachtda.scsi.gmx.ch

                Hello Pete


                If I try to implement your example, I get this error:



                13:32:05,234 WARN  [lifecycle] executePhase(PROCESS_VALIDATIONS 3,com.sun.faces.context.FacesContextImpl@8ce5fe) threw exception
                javax.faces.FacesException
                at com.sun.faces.lifecycle.ProcessValidationsPhase.execute(ProcessValidationsPhase.java:108)
                




                13:32:05,250 ERROR [ExceptionFilter] exception root cause
                java.lang.IllegalArgumentException
                        at javax.faces.component.SelectItemsIterator.next(SelectItemsIterator.java:166)
                



                My View:


                <h:form>
                <h:selectOneMenu id="functions" required="true" value="#{facilityAction.functionID}">
                   <s:selectItems value="#{facility.functions}" var="function" label="#{function.functionIndication.labelKey}" itemValue="#{function.ID}" />
                </h:selectOneMenu>
                <h:commandLink action="#{facilityAction.selectFunction}">Test</h:commandLink>
                </h:form>




                My Bean:


                private String m_FunctionID;
                
                public void selectFunction() {
                   System.out.println("Function: " + m_FunctionID);
                }
                     
                public String getFunctionID() {
                   return m_FunctionID;
                }
                     
                public void setFunctionID(String p_FunctionID) {
                   m_FunctionID = p_FunctionID;
                }



                What could be the reason for this error?
                Any hints? Thank you for helping...


                • 5. Re: passing value from selectOneMenu
                  pmuir

                  Whole stack trace please.

                  • 6. Re: passing value from selectOneMenu
                    boki

                    I implemented Pete's suggestion without any problems, so I can only assume it is something else in your code, but without looking at the stack trace or the whole code it is not easy to see what it may be.

                    • 7. Re: passing value from selectOneMenu
                      wachtda.scsi.gmx.ch

                      Hello Pete and Bojan


                      Thank you for answering...
                      I just get it working now.
                      It was a mistake in the Bean.


                      Greetings