Skip to main content

ADF Multi select LOV

1. In this approach all the selected values will be inserted in separate rows in table.Ex. if you select 3 value out of 10 in LOV then 3 rows will be inserted in table. No need to create the LOV in ViewObject.

Create Entity and View for the table in which you want to store the multiple selected LOV values. Also create the read only view which has the LOV values which user will select.
Ex. 1. PropertiesVO - VO in which value will be stored
       2.PropertiesAvailableValuesRVO - VO in which provide LOV value.

2. First of all add af:selectManyChoice component to your page.

3. As shown in the below code create the binding,value and valueChangeListner in your bean and associate with this component.

4. Also create the f:selectItems and create the binding and value in bean same as done above.

<af:selectManyChoice label="#{caseviewcontrollerBundle.PROPERTIES}"
                                 id="cp1"
                                 value="#{pageFlowScope.ManagePerfected.propertiesCode}"
                                 binding="#{pageFlowScope.ManagePerfected.smPropertiesCode}"
                                 contentStyle="width:200.0px;"
                                 disabled="#{pageFlowScope.IsEditable eq 'Y'}"                      valueChangeListener="#pageFlowScope.ManagePerfected.savePropertiesListener}"
                                 autoSubmit="true" immediate="true">
    <f:selectItems value="#pageFlowScope.ManagePerfected.availablePropertiesCode}"
                              binding="#{pageFlowScope.ManagePerfected.siPropertiesCode}"
                              id="cp12"/>
            </af:selectManyChoice>


private List propertiesCode;
private List availablePropertiesCode
private RichSelectManyChoice smPropertiesCode;
private UISelectItems siPropertiesCode;

public void setPropertiesCode(List propertiesCode) {
    this.propertiesCode= propertiesCode;
    }
 
public List getPropertiesCode() {
    if (propertiesCode== null) {
           propertiesCode= attributeListForIterator("PropertiesVOIterator","PropertiesCode");
    }
    return propertiesCode;
    }

public void setsmPropertiesCode(RichSelectManyChoice smPropertiesCode) {
        this.smPropertiesCode = smPropertiesCode;
    }

public RichSelectManyChoice getsmPropertiesCode() {
                return smPropertiesCode;
    }

public void setSiPropertiesCode(UISelectItems siPropertiesCode) {
        this.siPropertiesCode= siPropertiesCode;
    }

public UISelectItems getSiPropertiesCode() {
        return siPropertiesCode;
    }

public void saveCasePropertiesListener(ValueChangeEvent valueChangeEvent)
   {
        ADFUtils.setCurrentTabDirty(true);
        valueChangeEvent.getComponent().processUpdates(FacesContext.getCurrentInstance());
       DCBindingContainer bindings =(DCBindingContainer)BindingContext.getCurrent().getCurrentBindingsEntry();
       DCIteratorBinding iterator =bindings.findIteratorBinding("PropertiesVOIterator");
     
     for (Row specialCode : iterator.getViewObject().getAllRowsInRange()) {
            specialCode.remove();
        }
        DCIteratorBinding dcItr = ADFUtils.findIterator("ParentVOIterator");
        Row row = dcItr.getViewObject().getCurrentRow();
        Object parentId = row.getAttribute("ParentId");
        int rcount =this.getPropertiesCode().size();
        String[] propertiesCode =new String[this.getPropertiesCode().size()];
        if (rcount > 0) {
            for (int k = 0; k < rcount; k++) {
                propertiesCode[k] =getPropertiesCode().get(k).toString();
                Row r = iterator.getViewObject().createRow();
                r.setAttribute("ParentId ", parentId );
                r.setAttribute("PropertiesCode",propertiesCode[k]);
                iterator.getViewObject().insertRow(r);
            }
        }

    }


public void setAvailablePropertiesCode(List availablePropertiesCode ) {
        this.availablePropertiesCode = availablePropertiesCode ;
    }

public List getAvailablePropertiesCode() {
  availablePropertiesCode =selectUniqueItemsForIterator("PropertiesAvailableValuesRVOIterator",
                    // iterator for displaying all items
                    "Value", // internal code for list item
                    "ShortDescription"); // display value for list item
     
        return availablePropertiesCode ;
      }


 public List<SelectItem> selectUniqueItemsForIterator(String iteratorName,
                                                               String valueAttrName,
                                                               String displayAttrName) \
{
              List<SelectItem> selectItems = new ArrayList<SelectItem>();
              HashMap<String, String> itemsMap = new HashMap<String, String>();

              DCIteratorBinding tsriter = ADFUtils.findIterator(iteratorName);
              ViewObject tsrvo = tsriter.getViewObject();
              tsrvo.executeQuery();

              // for (Row row : tsrvo.getAllRowsInRange()) {
              while (tsrvo.hasNext()) {
                  Row row = tsrvo.next();
                  String lovCode = row.getAttribute(valueAttrName).toString();

                  if (!itemsMap.containsKey(lovCode)) {
                      itemsMap.put(lovCode, lovCode);

                      String value = lovCode;
                      String finalDisplayValue =
                          (String)row.getAttribute(displayAttrName);
                      selectItems.add(new SelectItem(value, finalDisplayValue));

                  }
              }
              return selectItems;
          }




Comments

  1. I wanted to thank you for this great read!! I definitely enjoying every little bit of it and I have you bookmarked to check out new stuff you post.
    Oracle Apps Technical Training in Bangalore

    ReplyDelete

Post a Comment

Popular posts from this blog

Passivation and Activation in ADF (Application Module )

1. For performance reasons, ADF keeps a pool of application modules in memory. It tries to give each session the same application module as the session used during the last request; however, this might not be possible during peak load of your application. 2. In this case, ADF saves the application modules state in a database table so the application module can be used by another session. This is called passivation . 3. When the first session needs the application module again, its state is retrieved from the database process known as activation . 4. If you have made an error in your code and depend on some variable that is not persisted correctly when your application module state is stored, you will experience mysterious errors under high load.   Enable/Disable Application Module Pooling : Right-click on your application module, choose Configurations.By default, each application module has two configurations. Ensure that the one ending in …Local is selected and then click

Get modified rows from Entitiy Cache

To get the modified rows from entity cache we have getEntityState() method at EntityImpl class. Refer to my previous blog  Accessing EO impl methods from VO impl  where i am overriding the getEntityState() in EOimpl and calling it in VOImpl. We can use methods written or overridden in VOImpl class to AMImpl class. There are different states associated with an entity object. STATUS_UNMODIFIED STATUS_MODIFIED STATUS_NEW STATUS_DELETED STATUS_DEAD We have to check the state or row in our AmImpl class by using the VOImpl method and through this we can distinguish the rows present at vo. Add below code in AMImpl class along with my previous post. public void geCachedRowsCount(){         JobsVOImpl jobsVo = (JobsVOImpl)this.getJobsVO();         RowSetIterator iter = jobsVo.createRowSetIterator(null);             while(iter.hasNext()){             Row row = iter.next();             byte state = jobsVo.getEntityState(row);             System.out.println("Job_id -&

The file store "WLS_DIAGNOSTICS" could not be opened

WLS_DIAGNOSTIC ERROR weblogic.store.PersistentStoreException: [Store:280073]The file store "WLS_DIAGNOSTICS" could not be opened because it contained a file with the invalid version 1. A file of version 2 was expected. When you get this error while running your application on internal weblogic server delete the following file WLS_DIAGNOSTICS000000.DAT search the file in following path C:\jdev_work\system11.1.1.5.37.60.13\DefaultDomain this file is in DefaultDomain folder of your jdev. and delete the WLS_DIAGNOSTICS000000.DAT file . and run your applicatuon