0 Replies Latest reply on Jun 10, 2010 7:15 AM by Terseer Shaguy

    failing chained s: selectOneMenu

    Terseer Shaguy Newbie
      |Hi wonderful People, 

          I  have 3 selectOneMenus on a page apart from the first one the others depends on the value of the previous select to change and thus disable the next. the first One selects a country , then based on the value of the country selected the issuers Name selectOneMenu is enabled and the  issuers  in that country can be selected, which on selection will enable the   sub issuers  selectOneMenu to be selected . My challenge is that the country , and the issuers selectOneMenu works fine but that of the subIssuer fails. But when I remove the piece of code that disables the subIssuer selectOneMenu every sub Issuer is displayed in the menu irrespective of the Issuer and country. Pls see sample code below.


      facelet  scriptlet:

      ^<a:region>
                     <h:outputLabel for="countrySetup" >#{messages['countryName']} </h:outputLabel>

                        <h:selectOneMenu id="countrySetup" value="#{userHelper.newUser.eremitCountry}" required="true">

                       <s:selectItems  value="#{appUtils.countries}"   var="country"   label="#{country.countryName}"   noSelectionLabel="#{messages['noCountrySelected']}" />

                       <s:convertEntity/>

                        <a:support event="onchange"  reRender="issuerSetup" bypassUpdates="false" ajaxSingle="true" ></a:support>

                    </h:selectOneMenu>

                    <rich:message for="countrySetup" styleClass="messagesingle" errorClass="errormsg" infoClass="infomsg" warnClass="warnmsg"></rich:message>

                  

                    <h:outputLabel for="issuerSetup" >#{messages['issuerName']} </h:outputLabel>

                        <h:selectOneMenu id="issuerSetup" value="#{userHelper.newUser.eremitIssuers}"  disabled="#{userHelper.newUser.issuerDisabled}" >

                  <s:selectItems  value="#{issuersList}"   var="issuer"   label="#{issuer.issuerName}"   noSelectionLabel="#{messages['noIssuerSelected']}"  />

                     <s:convertEntity/>

                   

                   <a:support event="onchange"  reRender="subIssuerSetup"  bypassUpdates="false" ajaxSingle="true"></a:support>

                    </h:selectOneMenu>

                    <rich:message for="issuerSetup" styleClass="messagesingle" errorClass="errormsg" infoClass="infomsg" warnClass="warnmsg"></rich:message>

             

                  
                    <h:outputLabel for="subIssuerSetup"  >#{messages['subIssuerName']} </h:outputLabel>

                        <h:selectOneMenu id="subIssuerSetup" value="#{userHelper.newUser.eremitSubIssuer}"  disabled="#{userHelper.newUser.subIssuerDisabled}" >      

                    <s:selectItems   value="#{subIssuersList}"   var="sub" label="#{sub.subCodeName}"   noSelectionLabel="#{messages['noSubIssuerSelected']}"/>

           

                     <s:convertEntity/>

                    </h:selectOneMenu>

                    <rich:message for="subIssuerSetup" styleClass="messagesingle" errorClass="errormsg" infoClass="infomsg" warnClass="warnmsg"></rich:message>

                                          </a:region> `


      *

      Entity:
      @Entity

      @Name("eremitUsers")

      @Table(name = "eremit_users", uniqueConstraints = @UniqueConstraint(columnNames = "USERNAME"))

      public class EremitUsers implements java.io.Serializable {
            private Long userId;

            private EremitCountry eremitCountry;

            private EremitRoles eremitRoles;

            private EremitIssuers eremitIssuers;

            private EremitSubIssuer eremitSubIssuer;

           

           …………… ommitted for brevity
            private static boolean subIssuerDisabled = true;

            private static boolean issuerDisabled  = true;

             ……..

            @ManyToOne(fetch = FetchType.LAZY)

            @JoinColumn(name = "ISSUER_CODE")

            public EremitIssuers getEremitIssuers() {
                  System.out.println("ON OBJ GET : ISSUER_CODE :"+eremitIssuers);

                  return this.eremitIssuers;

            }
            @ManyToOne(fetch = FetchType.LAZY)

            @JoinColumn(name = "COUNTRY_ID", nullable = false)

            @NotNull

            public EremitCountry getEremitCountry() {

                  System.out.println("ON OBJ GET : COUNTRY_ID :"+eremitCountry);

                  return this.eremitCountry;

            }
            public void setEremitCountry(EremitCountry eremitCountry) {

                  System.out.println(":ABOUT TO SET COUNTRY :"+eremitCountry);

                  this.eremitCountry = eremitCountry;

                  issuerDisabled = false;

                  //subIssuerDisabled = false;

            }


            public void setEremitIssuers(EremitIssuers eremitIssuers) {

                  System.out.println(":ABOUT TO SET ISSUER :"+eremitIssuers);

                  this.eremitIssuers = eremitIssuers;

                  subIssuerDisabled = false;

            }

         

            @Transient

            ....... to enable sub issuer countrols on UI

            public boolean isSubIssuerDisabled() { 
                  System.out.println(" GET : isSubIssuerDisabled :"+subIssuerDisabled);

                 return(subIssuerDisabled);

            } 
            @Transient

            //to enable issuer countrols on UI

            public boolean isIssuerDisabled() { 
                  System.out.println(" GET : issuerDisabled :"+issuerDisabled);

                 return(issuerDisabled);

            } 
        

         /*

            public void setSubIssuerDisabled(boolean subIssuerDisabled) {

                  this.subIssuerDisabled = subIssuerDisabled;

            }
            public void setIssuerDisabled(boolean issuerDisabled) {

                  this.issuerDisabled = issuerDisabled;

            }

            */


      user helper


      import java.util.Date;

      import org.hibernate.validator.Valid;

      import org.jboss.seam.annotations.In;

      import org.jboss.seam.annotations.Name;

      import org.jboss.seam.captcha.Captcha;

      import org.jboss.seam.faces.FacesMessages;

      import org.jboss.seam.faces.Renderer;

      import org.jboss.seam.international.StatusMessage.Severity;

      import org.jboss.seam.security.Credentials;

      import org.jboss.seam.security.Identity;
      import com.etz.eRemit.EremitUsers;

      import com.etz.eRemit.modules.login.PasswordBean;

      import com.etz.eRemit.modules.login.PasswordManager;

      import com.etz.eRemit.options.AppOptions;

      import com.etz.eRemit.options.UserOptions;
      import javax.persistence.EntityManager;

      import javax.persistence.NoResultException;
      @Name("userHelper")

      public class UserHelper {

            @In (create=true)

            EntityManager entityManager;

            @In (create=true)

            Renderer renderer;
            @In

            FacesMessages facesMessages;

            @In

            Credentials credentials;
            @In

            Identity identity;
            @In (create=true)

            Captcha captcha;
            @In

          UserOptions userOptions;


            @In @Valid

            EremitUsers loggedInUser;
            private EremitUsers newUser;


            PasswordManager c = new PasswordManager();

            public void signUp() { 

                  // Save the user and send the emails

                  try {

                        entityManager.persist(getNewUser());   

           

                     facesMessages.add(Severity.INFO, "#{messages['userRegisteredThanks']}");

                

            // Empty the captcha

            Captcha.instance().setResponse(null);

            Captcha.instance().init();

           

                  } catch (NoResultException e) {

                        facesMessages.add(Severity.ERROR, "#{messages['emailNotFound']}");

              }

            }
            public void setNewUser(EremitUsers newUser) {

                  this.newUser = newUser;

            }


            public EremitUsers getNewUser() {

                  if (newUser==null) {

                        newUser=new EremitUsers();

                  newUser.setAuthorized(userOptions.getUserAuthorized());  // user authorized status on start up globally defined

                  newUser.setCreatedDate(new Date());

                  newUser.setEnforcePasswordChange(userOptions.getEnforcePasswordChange()); // enforce password change on first login globally defined

                  newUser.setPasswordChangeFreq(userOptions.getPasswordChangeFreq());// change password freq globally defined

                  newUser.setStatus("0");

                  newUser.setUserType("M"); //to change

                  newUser.setEremitUsersByCreatedBy(loggedInUser);

                  newUser.setLoggedIn("0");

                  newUser.setPasswordRetry(0);

                  //newUser.setPassword(c.hash(newUser.getPassword()));

                  }

                  return newUser;

            }

      }


      //intially I had this class load all my menu items on startup


      @Name("appUtils")

      //@Scope(ScopeType.CONVERSATION)     //SESSION

      @Scope(ScopeType.PAGE)

      //@Startup

      //@Synchronized

      public class AppUtils

      {

            @Logger

          private Log log;

          @In (create=true)

            EntityManager entityManager;

        

          private boolean isSubIssuerEnabled = true;

       

          List<EremitRoles> userRoles;

          List<EremitIssuers> issuers;

          List<EremitSubIssuer> subIssuer;

          List<EremitCountry> countries;

          EremitRoles eremitRoles ;

          EremitIssuers eremitIssuers;

          EremitSubIssuer eremitSubIssuers;

          EremitCountry eremitCountries;

        

         

            public List<EremitRoles> getUserRoles() {

          

          

           try

           {

            String query = "select r from EremitRoles r order by r.roleName";

                        System.out.println(": query :"+query);
                        userRoles = entityManager.createQuery(query).getResultList();


               } catch (NoResultException e) {
                userRoles = null;

            }

              return userRoles;

          }

          //@WebRemote

          public List<EremitSubIssuer> subIssuers(BigInteger issuerId)

          {

            System.out.println(": CALLED subIssuers  : passed :>>"+issuerId);

            try

            {

            //String query = "select s from EremitSubIssuer s where eremitIssuers=:issuerId";

             String query = "select s from EremitSubIssuer s where s.eremitIssuers="+issuerId+" ";

         System.out.println(": query :>>"+query);

         subIssuer = entityManager.createQuery(query).getResultList();

         //subIssuer = entityManager.createQuery(query).setParameter("issuerId", issuerId)  .getResultList();

            }

            catch (NoResultException e)

            {

         

             subIssuer = null;

                }

          

        

              return subIssuer;

         

          }

          //@Begin

          public List<EremitCountry> getCountries() {

          

          

           try

           {

            String query = "select c from EremitCountry c order by c.countryName";

                        System.out.println(": query :"+query);
                        countries = entityManager.createQuery(query).getResultList();


               } catch (NoResultException e) {
                countries = null;

                 }

              return countries;

          }

        

        

          public List<EremitIssuers> getIssuers() {

          

           System.out.println(": CALLED THE ISSUER LOADER :>"+issuers);

          

          

           try

           {

            String query = "select i from EremitIssuers i order by i.issuerName";

                        System.out.println(": query :"+query);
                        issuers = entityManager.createQuery(query).getResultList();


               } catch (NoResultException e) {
                issuers = null;

                 }

             

              return issuers;

          }

       

          //@End

          public List<EremitSubIssuer> getSubIssuers() {

          

           try

           {

            String query = "select s from EremitSubIssuer s order by s.subCodeName";

                        System.out.println(": query :>>"+query);
                        subIssuer = entityManager.createQuery(query).getResultList();


               } catch (NoResultException e) {
                subIssuer = null;

                 }

              return subIssuer;

          }



          ……….. // omiited for brevity

      }


      but inplace  of the subIssuer and Issuer Menu loader I now have  this defined in my components.xml


         <framework:entity-home name="issuerHome" entity-class="com.etz.eRemit.EremitIssuers"/>

         <factory name="issHome" value="#{issuerHome.instance}"/>

         <framework:entity-query name="issuersList" ejbql="select i from EremitIssuers i">

             <framework:restrictions>

                 <value>i.eremitCountry = #{userHelper.newUser.eremitCountry}</value>

             </framework:restrictions>

         </framework:entity-query>

       

       

         <framework:entity-home name="subIssuerHome" entity-class="com.etz.eRemit.EremitSubIssuer"/>

         <factory name="subHome" value="#{subIssuerHome.instance}"/>

         <framework:entity-query name="subIssuersList" ejbql="select s from EremitSubIssuer s">

             <framework:restrictions>

                 <value>s.eremitIssuers = #{userHelper.newUser.eremitIssuers}</value>

             </framework:restrictions>

         </framework:entity-query> ^

      Sorry my compliant is quite  lengthy . So sorry for taking all of your time.

      Pls can anyone give me a lead as to where I went wrong ?