4 Replies Latest reply on Sep 1, 2013 8:01 AM by Maroof Ahmad

    Value change event called two times after dependent second lov changed

    Maroof Ahmad

      Hi,

       

      I am have  value change event on two LOV. First broader level selection while second on dependent first lov. My Bean scope is request.

       

      When i am changing First lov then first lov value change event called,

       

      Fist time when second lov changed then only second lov value change event called while if second lov value change again then first and second both value change event called.

       

      I want consistency because on behalf of first lov i am rending different - different form. Since if second lov not called first lov value change event then i lost setRendered valued and its taken default value

       

      What is the wrong with this see below code snippet.

       

      jspx Lovbean method

        <afh:cellFormat binding="#{docDownload.cellFormat3}"

                                        id="cellFormat3"  halign="start">                                

                          <af:selectOneChoice value="#{docDownload.SAppId}"

                                          label=""

                                          binding="#{docDownload.selectOneChoice2}"

                                          requiredMessageDetail="Please select an owner Application for filtering doc type"

                                          tip="This will point this folder to its owner application"

                                          autoSubmit="true" immediate="true" required="true"

                                          valueChangeListener="#{docDownload.getAppIdEvent}"

                                          id="selectOneChoice2" inlineStyle="width:50%">

                                              <af:selectItem value="0" label=""/>

                                              <af:selectItem value="CMAP" label="Common"/>

                                              <af:selectItem value="ADMS" label="Administration "/>

                                              <af:selectItem value="OED" label="Services-OED"/>

                                              <af:selectItem value="AMI" label="AMIFIC"/>

                                              <af:selectItem value="AUTO" label="Automotive"/>

                                              <af:selectItem value="FIMS" label="Finance"/>

                                              <af:selectItem value="HRMS" label="HR"/>

                          </af:selectOneChoice>

                        </afh:cellFormat>

                      </afh:rowLayout>

                      <afh:rowLayout binding="#{docDownload.rowLayout9}"

                                     id="rowLayout9">

                        <afh:cellFormat binding="#{docDownload.cellFormat4}"

                                        id="cellFormat4"

                                        valign="middle"

                                      styleClass="cell-field"

                                      inlineStyle="color:white; font-size: 90%;"

                                      width="20%" halign="end">

                          <f:verbatim>      Document Type :

                          </f:verbatim>

                        </afh:cellFormat>

                      

                        <afh:cellFormat binding="#{docDownload.cellFormat5}"

                                        id="cellFormat5" halign="start">

                                <af:selectOneChoice value="#{bindings.vwDmsApplMapDocType.inputValue}"

                                                label=""

                                                binding="#{docDownload.selectOneChoice3}" required="true"

                                                autoSubmit="true" immediate="true"  id="selectOneChoice3"

                                                valueChangeListener="#{docDownload.getApplMapDocType}"                                         

                                                inlineStyle="width:50%">

                              <f:selectItems value="#{bindings.vwDmsApplMapDocType.items}"/>

                            </af:selectOneChoice>                  

                        </afh:cellFormat>

       

          <afh:rowLayout binding="#{docDownload.rowLayout11}"

                                     id="rowLayout11"  halign="left" width="50%"

                                     rendered="#{docDownload.BAppsPageRendered}">

                        <afh:cellFormat binding="#{docDownload.cellFormat6}"

                                        id="cellFormat6"

                                        valign="middle"

                                      styleClass="cell-field"

                                      inlineStyle="color:white; font-size: 90%;"

                                      width="20%">

                          <f:verbatim>Sub Type:    </f:verbatim>

                        </afh:cellFormat>

                        <afh:cellFormat binding="#{docDownload.cellFormat7}"

                                        id="cellFormat7"

                                        valign="middle" columnSpan="2"

                                        width="30%"  >

                               <af:selectOneChoice value="#{bindings.vwDmsApplMapType.inputValue}"

                                                  label="" autoSubmit="true" immediate="true"

                                                  required="#{docDownload.BMandType}"

                                                 partialTriggers="selectOneChoice3 selectOneChoice2" inlineStyle="width:50%">

                                <f:selectItems value="#{bindings.vwDmsApplMapType.items}"/>

                              </af:selectOneChoice>

                        </afh:cellFormat>

           public void getAppIdEvent(ValueChangeEvent valueChangeEvent){  

               FacesContext fctx = FacesContext.getCurrentInstance();

               sAppId = null;

               try

               {

               if (valueChangeEvent != null && valueChangeEvent.getNewValue() != null) {

                       sAppId = valueChangeEvent.getNewValue().toString();

                       this.setSAppId(sAppId);

                       JSFUtils.putOnProcessScope("appid", sAppId);

                       if(sAppId.equals("ADMS")){

                           System.out.println("inside if condition");

                           this.setBAppsPageRendered(true);

                       }else if(!sAppId.equals("ADMS")){

                           System.out.println("inside else-if condition");

                           this.setBAppsPageRendered(false);

                       }

                   }

                   }catch (Exception e){

                   e.printStackTrace();

                   System.out.println("Error Occurs in " +e.getMessage());

               } 

         

               try {

                    operationBinding =

                           (OperationBinding)fctx.getApplication().createValueBinding("#{bindings.getDmsDocTypeLOV}").getValue(fctx);

                    operationBinding.getParamsMap().put("appid", sAppId);        

                    operationBinding.execute();

                 //  System.out.println("Result = "+operationBinding.getResult().toString());

                    //-----------------------------------------

               }

               catch (Exception e) {

                   System.out.println("-----------Application from onCreate :" +

                                      fctx.getApplication().toString());

                   e.printStackTrace();

                   }

           }

         

          /**

           * @Author MaroofA

           * @Date June 15 2013

           * @Desc Set required true or false value on forms.

           */

           public void getApplMapDocType(ValueChangeEvent valueChangeEvent){

           System.out.println("Its Called from others linka also? check it now ! ");

              //below line added by maroof

              //this.setBAppsPageRendered(true);

            

               FacesContext fctx = FacesContext.getCurrentInstance();

               setAppKey(JSFUtils.getProcessAttribute("appid").toString());

               Integer rowKey = null;

               String docAppId = null;

               try

               { 

                       ValueBinding vbinding = fctx.getApplication().createValueBinding("#{bindings.vwrDMSDocTypeIterator}");

                       DCIteratorBinding doctypeIterBinding = (DCIteratorBinding)vbinding.getValue(fctx);

                       if (valueChangeEvent != null && valueChangeEvent.getNewValue() != null) {

                           rowKey = ((Integer)valueChangeEvent.getNewValue()).intValue();

                           if (rowKey >= 0) {

                               if (appKey != null) {                         

                                   Row rw = doctypeIterBinding.getRowAtRangeIndex(rowKey);

                                   System.out.println("row key value means doc type:  = "+rowKey);

                                   docType = (String)rw.getAttribute("DocType");

                                   docAppId = (String)rw.getAttribute("AppId");

                                   docTypeDesc = (String)rw.getAttribute("DocTypeDesc");

                                   JSFUtils.putOnProcessScope("jsfdoctype", docType);

                                   this.setDocType(docType);

                                   this.setDocTypeDesc(docTypeDesc);

                                   System.out.println("\n getApplMapDocType =>>"

                                   +"\n doc type = "+docType

                                   +"\n doc app id = "+docAppId

                                   +"\n DocTypeDesc = "+docTypeDesc);

                               

                               }

                           }

                       }else{

                           JSFUtils.addFacesWarningMessage("Document type is Required");

                       }

       

       

       

      Maroof

        • 1. Re: Value change event called two times after dependent second lov changed
          Frank Nimphius-Oracle

          Hi,

           

          taking it from

           

            <af:selectOneChoice value="#{docDownload.SAppId}"

           

          and

           

            binding="#{docDownload.selectOneChoice2}"

           

          the docDownload bean in configured in request or backingbean scope (because component bindings must be to beans in scope not longer than request). This however means that he value of the select one choice is reset back to whatever the default setting in this bean is. Basically saying, when you set the second list, the first looses its value state due to backing bean re-instantiation. This then causes the value change listener to fire again because from a component perspective the value changes.

           

          So you need to correct your understanding of JSF lifecycle e.g. by saving component values in a bean in view scope and component bindings in a bean in backing bean scope

           

          Frank

          1 person found this helpful
          • 2. Re: Value change event called two times after dependent second lov changed
            Maroof Ahmad

            Hi Frank,

             

            Actually i have a form which corresponding bean is in request scope and have auto submit some lov and radio buttons when i fill form and selecting radio button or combo box, then data cleared from form.

             

            How can i stop to reset form data on selection of auto submit attributes.

             

             

            Maroof

            • 3. Re: Value change event called two times after dependent second lov changed
              Frank Nimphius-Oracle

              Maroof,

               

              thanks for the clarification, but trust me, I know how to read page source code and managed bean code.

               

              But, did you understand my answer ?

               

              Frank

              • 4. Re: Value change event called two times after dependent second lov changed
                Maroof Ahmad

                Hi Frank,

                 

                I understand your ans about JSF bean scope life cycle. That means if i want put auto submit on component for particular form then i need to change bean scope from request scope to session or application scope. I changed my bean scope from request to session now its working fine. But this is right practice for changing scope from request to session for auto summit components .

                 

                And as you mentioned below code

                 

                • <af:selectOneChoice value="#{docDownload.SAppId}"

                 

                and

                 

                •   binding="#{docDownload.selectOneChoice2}"

                 

                When i drag and drop my view object on for then default value was bind with bean later i change manually with bean objects for getting and setting values in bean for some operation before saving data in DB.

                 

                Maroof