2 Replies Latest reply on Dec 22, 2011 3:16 AM by vata2999

    value becomes invalid (null) after posting form

    vata2999

      Hi,


      I have 2 comboboxes (City, Region) that one of them (region) fills based on another as below




      <h:selectOneMenu value="#{instituteHome.instance.city}">
          <s:selectItems value="#{cityQuery.resultList}" var="_city" label="#{_city.name}"/>
          <s:convertEntity />
          <a:support event="onchange" ajaxSingle="true" reRender="cityField" />
      </h:selectOneMenu>





      <h:selectOneMenu id="cityField" value="#{instituteHome.instance.region}">
          <s:selectItems value="#{regionQuery.resultList}" var="_region" label="#{_region.name}"/>
          <s:convertEntity />
      </h:selectOneMenu>



      RegionQuery.java




      @In(create = true)
      InstituteHome instituteHome;
      
      @Override
      public List<Region> getResultList(){
         if(instituteHome.instance.getCity() != null){ // after posting form turns into null
                return region where city = instituteHome.instance.getCity()
         }else{
           return null; //this is cause of invalid value 
         }
         
      }



      if i return super.getResultList() instead of null the problem will be solved but in this case
      user can see all regions without selecting a city


      I'm wondering why when i select city from combobox the instituteHome.instance.getCity() is not null but after posting form it turns into null


      Does anyone know how i can solve this problem ?


      Thanks in advanced





        • 1. Re: value becomes invalid (null) after posting form
          juanmiguelbg

          You can try:




          @Override
          public List<Region> getResultList(){
             if(instituteHome.instance.getCity() != null){
                    return region where city = instituteHome.instance.getCity()
             }else{
               return new ArrayList<Region>(); //this solve for us
             }
             
          }



          • 2. Re: value becomes invalid (null) after posting form
            vata2999

            This generates another problem after u select a value from combobox then post the form value will be lost
            and user has to select a value again


            try this :



            @Override
            @Begin(join = true)
            public List<Region> getResultList(){
               if(instituteHome.instance.getCity() != null){
                      return region where city = instituteHome.instance.getCity()
               }else{
                 return null;
               }
               
            }



            problem solved