Monday, October 18, 2010

Working with ADF Choice Elements

Asking user to enter data based on ADF choice element is not a tricky one

where as capturing the data selected by user and use it to fulfill other purpose is really a tricky task. We can drag an exposed view object from Data control and drop it in our webpage then automatically we will be asked for the “Selection Type”. After Selecting a type it will create underlying iterator and Bindings and the page got displayed with proper selection types.But if user wants to display some other details based upon selected data then how we can use this selected data.

In this post I am trying to implement how entered data using choice element
got captured in backing bean.

Single Selection Choice Elements:

image

Figure 1

As above figure shows three types of single choice element is available in ADF and they are “select one list box”(refer figure 2),“select one choice” (refer figure 3) and “select one radio”(refer figure 4)

image  Figure 2

imageFigure 3 image Figure 4

I have used command link and as user clicks on it, backing bean method get invoked and selected data is shown as output. To achieve that we need to follow below steps.

  1. Define the action listener for command link where user needs to click to
    view the output

    <af:commandLink text="view Output"id="cmdlnk2" actionListener="#{viewScope.TestADFBean.viewOPSelOneLB}"/>

    Bind the element for showing output as a backing bean property using binding
    attribute

    <af:inputText value="" binding="#{viewScope.TestADFBean.outputBinding1}"label="Select Country"id="it1"></af:inputText>


  2. Backing bean procedure is as follows

    1. public void viewOPSelOneLB( ActionEvent actionEvent) { //Get the specific binding Container
    2. BindingContainer bindings = BindingContext . getCurrent (). getCurrentBindingsEntry (); //Get the sepecific list binding using the binding name passed as argument to the get method of binding container
    3. JUCtrlListBinding listBinding = ( JUCtrlListBinding )bindings. get ("CountryEntityObjectView11"); //Get selected value
    4. Object sel = listBinding. getSelectedValue ();
    5. System.out. println (sel);
    6. outputBinding1. setVisible (true); //Set selected value to already binded property
    7. outputBinding1. setValue ("Output From SelectOneListBox [" + sel + "]");
    8. }

Multiple Selection Choice Elements:

image

Figure 5

As above picture depicts ADF Multiple selection consists of “Select Many Choice” (refer to Figure 7), “Select Many Shuttle”(refer to Figure 6),”Select Many List Box”(refer to Figure2),Select Many Check Box is same as “Select One Radio” as shown in Figure 4 but the difference is Check Box(please refer the drop down element of Figure 7) occurs instead of Radio button and user can select more
than one value which is not possible in Radio button.
image image
Figure6 Select Many Shuttle                                        Figure 7 ADF select Many Choice

For displaying data selected by user using multiple choice selection is exactly same except the backing bean method(Step 1 and Step 2 is same as above).

Backing bean method is as follows.

  1. public void SelectInputLsnrForShuttle( ActionEvent actionEvent) { //Get Binding Conatiner
  2. BindingContainer bindings = BindingContext . getCurrent (). getCurrentBindingsEntry (); //Get the sepecific list binding
  3. JUCtrlListBinding listBinding = ( JUCtrlListBinding )bindings. get ("CountryEntityObjView_LOV1"); //Get all Selected Values
  4. Object[] str = ( Object[] )listBinding. getSelectedValues ();
  5. StringBuffer buf = new StringBuffer (); //Append all Selected objects to a buffer
  6. for ( int i =0;i<str. length ();i++){
  7. buf. append (" ");
  8. buf. append (str[i]);
  9. buf. append (" ");
  10. System.out. println (buf. toString() );
  11. }
  12. opBindingForShuttle. setVisible (true); //Set selected value
  13. opBindingForShuttle. setValue (buf. toString() );
  14. }

5 comments:

  1. hi Anindya,
    Nice Blog. I tried following the same process which you have described for a checkbox but am not able to understand what value to pass here
    JUCtrlListBinding listBinding = ( JUCtrlListBinding )bindings. get ("CountryEntityObjView_LOV1");
    I am new to this jdev 11g so please tell me whether i have to pass an iterator name or a list name

    ReplyDelete
    Replies
    1. Hi Priyanka,

      If your view/pagedefs/pagebinding.xml shows below entry

      list IterBinding="distinctDEPTList1Iterator" ListOperMode="multiSelect"
      ListIter="distinctDEPTList1Iterator" id="distinctDEPTListBinding"
      DTSupportsMRU="true"

      then your backing bean should have the "id" specified in JUCtrlListBinding.
      BindingContainer bc = BindingContext.getCurrent().getCurrentBindingsEntry();
      JUCtrlListBinding listBinding = (JUCtrlListBinding)bc.get("distinctDEPTListBinding");

      Delete
  2. pass the value of the binding object that you might have used in jspx page

    ReplyDelete
  3. Hi Anindya,
    It is a good way to implement SelectManyCheckbox. Thank you.
    The only issue I have is how to clear those Checkboxs (uncheck f:selectItems) after invoke SelectInputLsnrForShuttle method.
    Please advice.
    Adam

    ReplyDelete
    Replies
    1. Hi Adam,

      Please use below code

      JUCtrlListBinding listBinding = ( JUCtrlListBinding )bindings. get ("CountryEntityObjView_LOV1");
      //Code for access values
      //end code for access values
      listBinding.clearSelectedIndices();

      Delete