7 Replies Latest reply on Aug 29, 2007 10:31 AM by yohann49

    SelectOneRadio

    yohann49

      hello !

      I have a page with radio buttons. But when I click on the submit button, I don't know what button has been selected.

      My bean :

      @Stateful
      @Scope(SESSION)
      @Name("PackageManager")
      public class PackageManager implements com.pingwy.web.front.PackageManagerLocal, Serializable {
      
       /**
       * Creates a new instance of PackageManager
       */
      
       @In
       private EntityManager em;
      
       @In(required = false) @Out(required = false) private List<Package> packages = new ArrayList<Package>();
      
       //@In(required = false) @Out(required = false) private List<Package> packageLine = new ArrayList<Package>();
      
       @In(required = false) @Out(required = false) private Package packageLine;
      
       @Factory(value ="packages")
       public void findPackage(){
      
       System.out.println("bonjour");
      
       Query query;
      
       query = em.createQuery("Select p From Package p");
       packages = (List<Package>) query.getResultList();
      
      
       }
      
       @Remove @Destroy
       public void destroy(){
       }
      
       public Package getPackageLine() {
       return packageLine;
       }
      
       public void setPackageLine(Package packageLine) {
       this.packageLine = packageLine;
       }
      
       public List<Package> getPackages() {
       return packages;
       }
      
       public void setPackages(List<Package> packages) {
       this.packages = packages;
       }
      
      }
      


      My jsf page :
      <html xmlns="http://www.w3.org/1999/xhtml"
       xmlns:ui="http://java.sun.com/jsf/facelets"
       xmlns:h="http://java.sun.com/jsf/html"
       xmlns:f="http://java.sun.com/jsf/core"
       xmlns:s="http://jboss.com/products/seam/taglib"
       xmlns:rich="http://richfaces.ajax4jsf.org/rich">
      
      
      
       <ui:composition template="templates/client.xhtml">
      
       <ui:define name="servicesclients">
      
       <h:form>
      
      
       <h:selectOneRadio value="#{PackageManager.packageLine}" layout="pageDirection" >
       <s:selectItems value="#{packages}" var="pack" label="#{pack.packName} : #{pack.descriptionPa.ck}"/>
       </h:selectOneRadio>
      
       <h:commandButton value="Next" type="submit"/>
      
       </h:form>
      
       </ui:define>
      
      
      
       </ui:composition>
      
      


      thanks in advance.
      Yohann

        • 1. Re: SelectOneRadio
          pmuir

          You'll need some sort of converter on the h:selectXXX - probably s:convertEntity should work.

          • 2. Re: SelectOneRadio
            yohann49

            I try, but packageLine is still empty.

            • 3. Re: SelectOneRadio
              yohann49

              In fact, when I look on the Debug page, in the session context, packageLine is not create but it'sinject and outject. Where is the problem ?

              • 4. Re: SelectOneRadio
                yohann49

                I'm so desperate. It works if I use selectManyCheckbox :

                <body>
                
                 <ui:composition template="templates/client.xhtml">
                
                 <ui:define name="servicesclients">
                
                 <h:form>
                
                 <h:selectOneRadio value="#{PackageManager.packageLine}" layout="pageDirection">
                 <s:selectItems value="#{packages}" var="pack" label="#{pack.packName} : #{pack.descriptionPack}"/>
                
                 </h:selectOneRadio>
                
                 <h:commandButton value="Next" type="submit"/>
                
                 </h:form>
                
                 </ui:define>
                
                 </ui:composition>
                
                 </body>
                


                When I click on the button, packageLine contain the selected rows, but I want to use selecetOneRadio, because the client must select one package.
                Somebody can help me ?
                Thanks

                • 5. Re: SelectOneRadio
                  matt.drees

                  I think you don't want to do things like

                  @Name("PackageManager")
                  public class PackageManager
                  {
                  ...
                   @In(required = false) ...
                  private Package packageLine;
                  }
                  
                  ...
                  #{PackageManager.packageLine}
                  


                  When jsf calls setPackageLine(), packageLine will be set, but immediately afterwards it will be nulled because of disinjection (from the @In). Maybe this is causing your problem.

                  • 6. Re: SelectOneRadio
                    yohann49

                    Since my first post, I removed @In from packageLine, and the misstacke is still there

                    • 7. Re: SelectOneRadio
                      yohann49

                      I found a solution, in fact I must declare PackageLine as a String and no as o Package. Now the problem is: I want a Package not a string how could I do to have this ?
                      Thanks

                      PS: sorry for my english