adf:tree做的树菜单如何过滤子节点的数据?
2012-06-26(Tuesday) 00:00
需求:项目中的树菜单需要权限用户的权限过滤显示子菜单,通过用户所在的用户组可以查看的页面ID(List)过滤子节点
解决方案:
因为树是通过viewLink关联自身的VO生成的,想在AM里添加方法,对VO进行过滤处理把结果返回。
但实现起来比较麻烦,调用方法之后要刷新页面,初始化的树数据过滤处理困难。
于是想重写VO的方法看能不能在VO层就过滤掉子节点。重写createViewLinkAccessorRS,此方法返回ViewLink的结果,也就是菜单的子节点数据
@Override
protected ViewRowSetImpl createViewLinkAccessorRS(AssociationDefImpl associationDefImpl,
ViewObjectImpl viewObjectImpl,
Row row,
Object[] object) {
ViewRowSetImpl viewRowSetImpl =
super.createViewLinkAccessorRS(associationDefImpl, viewObjectImpl,
row, object);
int count = 0;
// getList()拿到可以查看的pageId的列表,对比Row中的pageId属性,如果在List中存在,就取该Row,如果不存 //在,表示此子节点不予以显示,remove掉
if (this.getList() != null && this.getList().size() != 0 &&
viewRowSetImpl != null) {
for (int m = 0; m < viewRowSetImpl.getRowCount(); m++) {
if (viewRowSetImpl.getRow(m).getAttribute("pageId") ==
null) {
continue;
} for (int i = 0; i < this.getList().size(); i++) {
if (this.getList().get(i).equals(viewRowSetImpl.getRow(m).getAttribute("pageId"))) {
count++;
} }
if (count == 0) {
viewRowSetImpl.removeRowAt(m);
//因为remove掉一行之后,viewRowSetImpl的RowCount就少了1,需要给m也减一,不然可漏掉一行数据未处理。
m--;
} count = 0;
} }
return viewRowSetImpl;
}
如此重写了这个方法之后,在调用的时候需要给List赋值,以方便过滤。因此需要给List的 SetList()方法生成Client接口。
在VO中为setList()添加clientInterface.
<ClientInterface>
<Method
Name="setList">
<Return
Type="void"/>
<Parameter
Name="list"
Type="java.util.ArrayList"
IsGeneric="true">
<Element
Type="java.lang.String"/>
</Parameter>
</Method>
</ClientInterface>
DCIteratorBinding it2 = ADFUtils.findIterator("MenuVO1Iterator");
MenuVOImpl vo2 = (MenuVOImpl)it2.getViewObject();
vo2.setList(list); //给VO的List赋值。
vo2.executeQuery();