现在的位置: 首页 > 综合 > 正文

Find an UIComponent in an ADF Task Flow Region

2014年01月18日 ⁄ 综合 ⁄ 共 1128字 ⁄ 字号 评论关闭

When you want to find an UIComponent (like a Tree) inside an ADF Region you can not use findComponent on the ViewRoot because this will only search for the component in the JSF page and not in the JSF page fragments ( Task Flows). And off course you can use
a backing bean to make a binding but I want to find the component by first searching for the right Region in the JSF page and then searching the component inside the Region.

First I need to have some common methods.

// find a jsf component inside the JSF page
private UIComponent getUIComponent(String name) {
FacesContext facesCtx = FacesContext.getCurrentInstance();
return facesCtx.getViewRoot().findComponent(name) ;
}

// find a UIComponent inside a UIComponent
private UIComponent getUIComponent(UIComponent component,String name ){
List items = component.getChildren();
for ( UIComponent item : items ) {
UIComponent found = getUIComponent(item,name);
if ( found != null ) {
return found;
}
if ( item.getId().equalsIgnoreCase(name) ) {
return item;
}
}
return null;
}

Now we can find the right Region and then search inside the Region for the ADF Tree

// get the dymamic region of the main page
RichRegion region = (RichRegion)getUIComponent("dynam1");

if ( region != null) {
// find tree 2
RichTree rt = (RichTree)getUIComponent(region,"t2");
if ( rt != null ) {
// do your thing
}
}

抱歉!评论已关闭.