Amazon Contextual Product Ads

Wednesday, 27 November 2013

ADF - Using selectOneChoice in af:iterator

 

The following example replated to Jdeveloper 11g R3

af:iterator is a grate component when you need to with collections, but also design by yourself the UI for each row in the collection.

Here I will explain how can you put a selectOneChoice (combo box) with dynamic values in each row UI.

For this I will create 2 tables

create table XX_SAMPLE_DATA
(
ID number,
TITLE varchar2(100),
STATUS varchar2(100)
)

create table XX_STATUSES
(
CODE varchar2(100),
MEANING varchar2(100)
)



The “status” column in the XX_SAMPLE_DATA will be based on the values from XX_STATUSES table


I am not going to explain how to create the “Model” for this 2 tables, assuming that you are well recognized with this part. Eventually we will have the following structure


image


Now. Do not attempt to set XxStatusesView as LOV for “Status” attribute . It will give you nothing.


Ok, lets create our page .


Create whatever page you want (jsf or jspx) and go to page defintion


image


We need to add both View Objects to the binding


In the “binding” section, click plus sign and choose tree


image


Click on the “Add” and choose “XxSampleDataView1”


image


 


Add new rule (you will have only one option)


image


And pass all attributes to the “Display Attributes”


image


Create also “tree” binding for the second View Object “XxStatusesView1”.


This is how your binding should look at the end


image


Drop iterator component on the page


image


Set the following properties on the iterator


image


We will also put “output text” element inside iterator to display “Title” attribute


Add the following script as iterator child

 <af:selectOneChoice label="Status" id="soc1" value="#{row.Status}">
<af:forEach items="#{bindings.XxStatusesView1.children}"
var="status">
<af:selectItem value="#{status.Code}"
label="#{status.Meaning}"
id="si1"/>
</af:forEach>
</af:selectOneChoice>




Explanation about this part. The value that will be displayed is the current value in the row of XX_SAMPLE_DATA status column. But it will be displayed as a combo box with values based on the data from XX_STATUSES table


image


 


We are ready to run. We only need to put some dummy data into our tables

insert into XX_SAMPLE_DATA values (1,'First','OPEN')
/
insert into XX_SAMPLE_DATA values (2,'Second','CLOSED')
/
insert into XX_STATUSES values ('OPEN','Open')
/
insert into XX_STATUSES values ('CLOSED','Closed')
/
insert into XX_STATUSES values ('N_A','Not Available')
/



image


You can download the workspace from here Download Workspace

No comments:

Post a Comment