问题描述
我尝试了以下方法来隐藏 ADF 组件,但它不起作用,知道我做错了什么吗?
#{不是 mainBean.RequestBean.applyButton.selected}
我希望这行代码在单击 applyButton 时隐藏一个表格,但它什么也没做。
解决方法
您需要在单击按钮时刷新组件才能使条件为真。在按钮事件末尾添加:
UIComponent component = findComponentInRoot("YOUR_COMPONEND_ID");
AdfFacesContext.getCurrentInstance().addPartialTarget(component.getParent()); //This will ask adf to trigger an ajax refresh on your component
在你的 java bean 中查找组件:
/**
* Locate an UIComponent in view root with its component id. Use a recursive way to achieve this.
* @param id UIComponent id
* @return UIComponent object
*/
public static UIComponent findComponentInRoot(String id) {
UIComponent component = null;
if (id != null) {
FacesContext facesContext = FacesContext.getCurrentInstance();
if (facesContext != null) {
UIComponent root = facesContext.getViewRoot();
if (root != null) {
component = findComponent(root,id);
}
}
}
return component;
}