2 Replies Latest reply on Oct 11, 2008 5:38 PM by Dean Hiller

    selecOneMenu and post or save how to?

    Dean Hiller Expert

      When someone selects something from my selectOneMenu, I want to save the current form to the beans and then mgr.flush them and continue the conversation.  Is there a way to do this with selectOneMenu?


      I figured this would be simple but not sure what to google for examples...selectOneMenu just brings up lots of how to change another menu when one changes and I know how to do that.


      thanks,
      Dean

        • 1. Re: selecOneMenu and post or save how to?
          System Administrator Expert

          depends what you mean by the beans.  post your facelet code.


          but it's something like this:


          <h:selectOneMenu value="#{myBean.selectedValue}">
               <f:selectItems .../>
               <a4j:support event="onchange" action="#{myBean.submit}"/>
          </h:selectOneMenu>
          



          in your myBean component (JavaBean or SFSB, typically):


          public void submit()
          {
              //if myBean is an entity class...
              Customer customer = new Customer();  //transient
              customer.setWhateverValue();
              customer.merge(customer);  //now managed in persistence context
              entityManager.flush()
              
          }
          
          public void setSelectedValue(String theValue)
          {...}
          
          public String getSelectedValue()
          {...}
          



          if you use an entity class for the value binding of h:selectOneMenu, you will simply need to inject the entity into your SFSB and then call entityManager.flush().  Seam automatically instantiates the entity when a method is called on it (if it already doesn't exist in one of the contexts) and is managed in the persistence context.  so there is no need to merge() it.


          be sure to use SMPC (via @In entityManager EntityManager) and use @Begin and @End annotations (or equivalent in the xhtml or pages.xml) to use a LRC.  Seam also has a s:convertEntity tag that is typically used with radio buttons or drop-downs.  check that out as well.


          NOTE: I have not tested this but it's pretty easy to get this to work.

          • 2. Re: selecOneMenu and post or save how to?
            Dean Hiller Expert

            That looks like an ajax request when I want it to not be ajax and refresh the entire page in this case.


            The top selectOneMenu is what I have right now and when I select a node in that list, I want all the below inputText fields to be applied to their beans(essentially a post) and want the page to navigate according to pages.xml but not sure how to define that yet as your example was ajax when I want an action method and a potential page change here.


            <s:decorate id="yesDec" template="../../web/zlogin/errorTemplate.xhtml">
                 <ui:define name="label">Navigate to Question:</ui:define>
                 <h:selectOneMenu value="#{editScript.currentNode}" required="true">
                        <s:selectItems value="#{allNodes.nodeList}" var="node" label="#{node.name}" noSelectionLabel="Please Select..." />
                     <s:convertEntity />
                 </h:selectOneMenu>
            </s:decorate>
            
            <s:decorate id="nameDecorate" template="../../web/zlogin/errorTemplate.xhtml">
                 <ui:define name="label">Question Name:</ui:define>
                 <h:inputText id="name" value="#{node.name}" required="true">
                                      <a:support event="onblur" reRender="nameDecorate" ajaxSingle="true" bypassUpdates="true"/>
                               </h:inputText>
            </s:decorate>
                      
            <s:decorate id="textDecorate" template="../../web/zlogin/errorTemplate.xhtml">
                 <ui:define name="label">Text:</ui:define>
                 <h:inputTextarea id="text" value="#{node.text}"
                      rows="5" cols="50" required="true">
                      <a:support event="onblur" reRender="textDecorate" ajaxSingle="true" bypassUpdates="true"/>
                 </h:inputTextarea>
            </s:decorate>
            
            <s:decorate id="typeDec" template="../../web/zlogin/errorTemplate.xhtml">
                 <ui:define name="label">Question Type:</ui:define>
                 <h:selectOneMenu value="#{node.type}" required="true">
                        <s:selectItems value="#{textTypes}" var="type" label="#{type.label}" noSelectionLabel="Please Select..." />
                     <s:convertEnum />
                     <a:support event="onchange" action="#{pathActions.setupPaths()}" reRender="typeDec,widgets" bypassUpdates="false" ajaxSingle="true"/>
                 </h:selectOneMenu>
            </s:decorate>