1 Reply Latest reply: Nov 17, 2012 1:36 AM by Cvele_new_account RSS

    getting selected value from lov?

    925715
      Hi Everyone,

      i have 2lovs on selecting value from first lov the second lov gets filtered and didn't select anything from second lov. On clicking on submit button im getting the selected values from 2 lovs and printingit on the page.
      As i didnt select anything from second lov i should get null but im getting first value in the list.
      my code is:

      BindingContainer bindings2 = getBindings();
      DCIteratorBinding dcitorg2=(DCIteratorBinding)bindings2.get("BatchNoVO1Iterator") ;
      ViewObject vBatch=dcitorg2.getViewObject();
      if(vBatch!=null)
      {
      batchNo= vBatch.getCurrentRow().getAttribute(0).toString();
      batchId= vBatch.getCurrentRow().getAttribute(3).toString();
      System.out.println("batch number:"+batchNo+"and batch id:"+batchId);
      }
      else {
      System.out.println("Batch VO is null &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&");
      }

      BindingContainer bindings3 = getBindings();
      DCIteratorBinding dcitorg3=(DCIteratorBinding)bindings3.get("StatusLovVO1Iterator") ;
      ViewObject vBatch3=dcitorg3.getViewObject();
      if(vBatch3!=null)
      {
      String OperNum= vBatch3.getCurrentRow().getAttribute(1).toString(); // this value is getting printed but i need null if  i dont select any value.
      System.out.println("Status selected is :"+OperNum);
      }
      else{
      System.out.println("Operation Queue VO is null &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&");
      }

      How to handle this?
      Plz help me to get out of this.


      Thanks.
        • 1. Re: getting selected value from lov?
          Cvele_new_account
          Hi,

          1. Put this method in the your ViewRowImpl base class:
              public void resetAttributesAppliedByLOV(String listBindingName){
                  List attrsAppliedByLOV = getAttributesAppliedByLOV(listBindingName); 
                  resetAttributes(attrsAppliedByLOV);
              } // of resetAttributesNotSetsByLOV() method
              
          
              /**
               * @param listBindingName - the 'Uses' atribute value of <listOfValues> from the pageDef
               * @return the complete list of attrbutes applied by LOV (one on which it is LOV attached + set of 'List Return Values' attributes)
               */
              public List getAttributesAppliedByLOV(String listBindingName){
                          List result  = new ArrayList();
                          ListBindingDef lbd = getViewDef().findListBindingDef(listBindingName);
                          if (lbd != null) {
                              List<String> lovAttrNames = Arrays.asList(lbd.getAttrNames());
                              result.addAll(lovAttrNames);
                              String[] derivedAttrsNames = lbd.getDerivedAttrNames(); 
                              if (derivedAttrsNames != null) {
                                  List<String> lovListReturnValuesAttrs = Arrays.asList(derivedAttrsNames); 
                                  result.addAll(lovListReturnValuesAttrs);
                              }
                          }
                          return result;
                  }
          
              private void resetAttributes(List attrList){
                  Iterator it = attrList.iterator();
                  while (it.hasNext()){
                      String attrName = (String)it.next();
                      try{
                          setAttribute(attrName,null);
                      }catch(ReadOnlyAttrException roe) {
                          log.warn("**resetAttributes() ReadOnlyAttrException: " + roe.getMessage());
                          continue;
                      }       
                  }// of while
              }
          - Next, put this method in the Row Client interface, and add them to the your pageDef as <methodAction>

          Suppose in your pageDef, you have also
              <listOfValues StaticList="false"
                            IterBinding="VOIterator"
                            Uses="YOUR_LOV" id="..."/>
          The NamedData NDValue for your method action should be YOUR_LOV

          2. Finally, make valueChangeListener for master LOV, in which you should execute your methodAction from pageDef you previously added, AND reset value for SECOND lov UI components, something like this:
              public void firstLOV_VCL(ValueChangeEvent e){
                  executeOperationBinding("resetAttributesAppliedByLOV"); // get a point...
                  getSecondLOVUIComp().resetValue();
                  AdfFacesContext.getCurrentInstance().addPartialTarget(getSecondLOVUIComp());
              }
          Let me know what happens