Sunday, January 8, 2012

Master-Detail with One Iterator

I will show slightly different approach how to implement Master-Detail relationship just with one iterator in ADF Bindings. Detail row collection will be fetched directly through View Link Accessor. I guess such approach is especially good, when you need to display Master-Detail data in the same table and want to declare just one iterator in ADF Bindings.

Sample application implements View Link between Locations and Departments, Data Model contains Master-Detail relationship based on View Link:


Drag & drop Locations table into ADF UI, Locations iterator will be defined in ADF Bindings:


Add child Departments collection to the Locations iterator and set DepartmentName attribute to be visible:



We can reference detail rows by pointing to View Link Accessor (by View Link Accessor name - DepartmentsView). Iterator will retrieve all detail rows available and display Department Name for each:


DepartmentsView is View Link Accessor name (pointing to Departments and generated in Locations), you can double check this in View Link definition wizard:


Here how it looks on UI, one Location row comes with collection of Departments rows:


Sample application - MasterDetailInlineTableApp.zip.

5 comments:

SK said...

Andrejus,

This is nice article.
Can i do the samething with JavaDataControls? Especially what is the equivalent step for the relationship step?

Thanks
Sri

Anonymous said...

How can i show a selectonechoice or other lists instead of output labels ? af:iterator cannot be used inside of these components, and af:foreach doesnt work.

Thanks

Claudio

Anonymous said...

i achieved this with varStatus in foreach:

af:selectOneChoice id="soc1"
af:forEach begin="0" end="5" varStatus="tel"
af:selectItem label="#{row.telefones[tel.index].ddd} #{row.telefones[tel.index].numero}" value="#{row.telefones[tel.index].numero}" id="si3"/
/af:forEach

/af:selectOneChoice

but now i cant get the size of the nested collection. I tried row.telefones.estimateRowCout but gives me a numberformatexception. Any ideas ?

thanks

Claudio

Anonymous said...

Andrejus,


In this situation i can access the length of the nested collection

af:outputText value="total tels: #{fn:length(row.telefones)}" id="ds2" /

but in foreach statement

af:forEach begin="0" end="#{fn:length(row.telefones)}" ....

i can't...

Using the elresolver in a managed bean such as

List l = context.getApplication().evaluateExpressionGet(context, "#{row.telefones}", List.class));

gives me a null object.

I think that issue is related to the evaluation process or not ? How we can resolve this ?

thanks,

Claudio

Andrejus Baranovskis said...

You can write managed bean method, where you could convert into required type - call this method instead of accessing expression directly.

Andrejus