Sunday, September 29, 2013

Retrieve selected value from selectOneChoice without writing a single line of code

While using selectOneChoice in the page to implement drop downs, it becomes very cumbersome to get the selected value from the list. One often has to write some lines of code in the managed bean to get the selected value from the drop down.


So in this post we will see how to get the selected value from the drop down list (af:seclectOneChoice) without writing a single line of code and without using any bean.

This uses the use of Variable Iterator which we discussed in the previous post.Variable Iterator in ADF to store values between requests




The application can be downloaded from Here
So lets get started and create a ADF application in jdev with a jspx page named test.jspx as below.


Now go to bindings of this page and inside variables , add a new variable of type string and give it a name. regionName for this example.




Now in bindings section create a new list binfing.

Select the following option


Now select the base data source as variables. Select list data source as the RegionsVO. Data Mapping section tells that the variable regionName is being mapped to the regionName from the list. Set the settings like below.



Now create a attributeValues for the variable inside Variables Iterator like below.


We are done with the bindings part.
Now lets create two UI components on the test page. selectOneChoice and input text like below.


Set the input value for the selectOneChoice from the el and make it refer to the list binding variable regionName1.


And select the value of inputTest as input value for attributeValues binding regionName2 which refers to the variable.

Below is the source code of the page. Autosubmit and partial triggers have been set.


That's it. Lets run the pages.

Now select value from the drop down.


And you can see the value in inputText as same as selected value from the list.


So we achieved to retrieve the selected value from the list without writing of the single line of code.


Happy Learning !!






6 comments:

  1. Hi Rohan, thanks a lot for this post, I have learnt a new concept of what variable iterating can do. I was trying using the selected value say, Americans, this value I am trying to use in setCurrentRowWithKeyValue to navigate to the corressponding row in the next page, but does not work. Could you please help.

    ReplyDelete
  2. Thank you a lot .. great job man the real solve to SOC problem

    ReplyDelete
  3. Hi Rohan,
    Very Nice post.
    I have a requirement where in a page there are two regions. If we select(select one choice) department id in 1st region then all the employees of that department id should be displayed in region 2. can you suggest solution for this scenario.

    I followed your post for getting selected value from select one choice.
    But what steps do i need to implement for achieving my requirement.

    ReplyDelete