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:
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)
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.
- 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>
Backing bean procedure is as follows
- public void viewOPSelOneLB( ActionEvent actionEvent) { //Get the specific binding Container
- BindingContainer bindings = BindingContext . getCurrent (). getCurrentBindingsEntry (); //Get the sepecific list binding using the binding name passed as argument to the get method of binding container
- JUCtrlListBinding listBinding = ( JUCtrlListBinding )bindings. get ("CountryEntityObjectView11"); //Get selected value
- Object sel = listBinding. getSelectedValue ();
- System.out. println (sel);
- outputBinding1. setVisible (true); //Set selected value to already binded property
- outputBinding1. setValue ("Output From SelectOneListBox [" + sel + "]");
- }
Multiple Selection Choice Elements:
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.
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.
- public void SelectInputLsnrForShuttle( ActionEvent actionEvent) { //Get Binding Conatiner
- BindingContainer bindings = BindingContext . getCurrent (). getCurrentBindingsEntry (); //Get the sepecific list binding
- JUCtrlListBinding listBinding = ( JUCtrlListBinding )bindings. get ("CountryEntityObjView_LOV1"); //Get all Selected Values
- Object[] str = ( Object[] )listBinding. getSelectedValues ();
- StringBuffer buf = new StringBuffer (); //Append all Selected objects to a buffer
- for ( int i =0;i<str. length ();i++){
- buf. append (" ");
- buf. append (str[i]);
- buf. append (" ");
- System.out. println (buf. toString() );
- }
- opBindingForShuttle. setVisible (true); //Set selected value
- opBindingForShuttle. setValue (buf. toString() );
- }