Display Selected Value from Cascaded LOV in ADF Page

To implement cascaded LOV in ADF its quite easy , but to display its values Id's  and selected values  are bit tricky. For example , Lets suppose you have have a Select One choice LOV which holds Employee Name as its display  , where as its List Attribute is Employee id , if you try printing Employee id in your manage bean code it displays Index number  , rather than employee id . I gone through various forums and posts  , but unable to find the direct solution related to it .  Finally after going through many forums and guides , i able to find a way for it . This article will guides with steps to display Select One Choice Values and its corresponding Id's


Please go through the below article , to create cascaded List of Values 


As we are pretty much aware that , we are using DualVO attributes to Implement cascading Select One Choices .  Now to display Select On Choice display value. We need to create two transient attributes with "Updatable"  property with "Yes".

This two transient attributes will going to hold the Display attributes of Select One Choices. 

First  will create two Transient Attributes with names
  "BusinessTransient" and "PracticeTransient"   by following below steps 


Click on Green Plus Icon to create a Transient Attribute


Set its Property to "Updateable"


So with this "BusinessTransient" Attribute has been created.
 Now similarly by following above steps we will  create another transient attribute with "PracticeTransient" Name  and then sets its "Updatable" Property to "Always"


Once creation of Transient Attributes are complete then it needs to be mapped with the Select one Choice Display Value.

 First we will Map BusinessUnit Select one choice with BusinessTransient Attribute.

Go to DualVO  Ã  Click on Attributes à  Click on Pencil icon of LOV_BusinessUnit



Provide "View Attribute" name as "BusinessTransient" & select List Attribute as "BusinessUnitName"



Similarly follow the below steps to Map PracticeTransient  attribute 

  





After Mapping done , now next step is to drag this Transient Attributes from DataControl onto the Page to Display Select One Choice Values. 

Go to the DataControls and Drag the BusinessTransient onto the Page as Output Text With Label




Now set Partial Triggers Property of newly Added output text to "soc1" ,  by referring soc1 in output text , will give correct display value upon every new selection of Select One choice value.

After that  Set its  inlinesytle to
color:Purple; font-family:'Courier New', Courier, monospace; font-size:medium;



Similary Drage PracticeTransient Attribute from DataControl and set its Partial Trigger Property to "soc2" and this Transient variable will going to hold values for Practice Select one choice Lov.


After that  Set its Set inlinesytle to 
color:Fuchsia; font-family:'Times New Roman', 'Arial Black', times, Serif; font-size:medium;





Now if you want to display ids  or List Attributes of selected List choice
We need to drag to just Output text with labels and assign attribute binding to it.

As shown below steps , Two output Text labels created with names Business Unit Id and Practice Id.



After creating Output text   and create a value binding by click on expression builder  and select appropriate Attribute value 




 For Business Unit Id the Attribute value  #{bindings.BusinessUnit,attributeValue}



After creating value bindings , set its   Partial Triggers Property to "soc1" , so that when first select one choice been selected it will display correct Business Unit id pertaining to selected value in Select one Choice 


Follow the same steps for Practice Id Output Variables , assign its values bindings as #{bindings.Practice,attributeValue} and also sets it  Partial Triggers Property to "soc1"




Once all steps  completed  then just run the page and try selecting different select one choice to display both Values and Id's  




























Getting both Values and Ids in Manage Bean Code 


Create ManageBean for Page by following below steps

Go to the Page and Click on Submit Button


After click on Submit Button a popup will appear , click on new


Provide below details

Bean Name  CasacadedManageBean
Class Name CascadedLovClass
Package Demo.adf.CascadedLOVApp.Bean
Scope  Session


Click on OK


This is how java class looks with an Action Listener Method cb1_action , which will responsible for Submit Button Actions.


Similarly we create ValueChangeListner Method for each select one choice, to capture value when each of the SelectChoice Values gets changed.




This is how Java Classes looks after  adding Value Change Listener.



Now copy the below code in each of the listener methods.



    public Object resolveExpression(String el) {     
      FacesContext facesContext = FacesContext.getCurrentInstance();  
      ELContext elContext = facesContext.getELContext();  
      ExpressionFactory expressionFactory = facesContext.getApplication().getExpressionFactory();      
      ValueExpression valueExp = expressionFactory.createValueExpression(elContext,el,Object.class);  
      return valueExp.getValue(elContext);  
    }  

    public void setValueToEL(String el, Object val) {  
      FacesContext facesContext = FacesContext.getCurrentInstance();  
      ELContext elContext = facesContext.getELContext();  
      ExpressionFactory expressionFactory =  facesContext.getApplication().getExpressionFactory();  
      ValueExpression exp = expressionFactory.createValueExpression(elContext, el, Object.class);  
      exp.setValue(elContext, val);  
    }

    public String cb1_action() {
        // Add event code here...
        String inputText1Value =
            (String)resolveExpression("#{bindings.BusinessTransient.inputValue}");
        String inputText2Value =
            (String)resolveExpression("#{bindings.PracticeTransient.inputValue}");


        System.out.println("inputText1Value" + inputText1Value);
        System.out.println("inputText2Value" + inputText2Value);

        return null;
        //return null;
    }


    public void BusinessVCE(ValueChangeEvent valueChangeEvent) {
        // Add event code here...
        this.setValueToEL("#{bindings.BusinessUnit.inputValue}",
                          valueChangeEvent.getNewValue()); //Updates the model
        System.out.println("valueoflist" + valueChangeEvent.getNewValue());

        if (valueChangeEvent.getNewValue() != null) {
            try {
                String i =
                    (String)resolveExpression("#{bindings.BusinessUnit.attributeValue}");
                j = Integer.parseInt(i);
                System.out.println("valueoflist" + i + "-" + j);
                String inputText1Value =
                    (String)resolveExpression("#{bindings.BusinessTransient.inputValue}");

                System.out.println("inputText1Value" + inputText1Value);

            } catch (Exception e) {
                // TODO: Add catch code
                e.printStackTrace();
            }

        }

    }



    public void PracticeVCE(ValueChangeEvent valueChangeEvent) 
{
        // Add event code here...
        this.setValueToEL("#{bindings.Practice.inputValue}",
                          valueChangeEvent.getNewValue()); //Updates the model
        System.out.println("valueoflist" + valueChangeEvent.getNewValue());

        if (valueChangeEvent.getNewValue() != null) {
            try {
                String i =
                    (String)resolveExpression("#{bindings.Practice.attributeValue}");
                j = Integer.parseInt(i);

                System.out.println("valueoflist" + i + "-" + j);
                String inputText2Value =
                    (String)resolveExpression("#{bindings.PracticeTransient.inputValue}");
                System.out.println("inputText2Value" + inputText2Value);


            } catch (Exception e) {
                // TODO: Add catch code
                e.printStackTrace();
            }

        }



    }

Run the Page , to get the values in Manage Bean






Comments

Popular posts from this blog

Sample HZ API's script to Create Contacts and Contact Points in Oracle

REST integration built-in OIC to read Large files with size more than 10MB