我采用了一种简单的方法,遍历JSF组件树并将组件禁用。(这样用户就无法更改值)。但是这种方法对于复合组件不起作用。我该如何至少检测到复合组件?然后我可以尝试将特殊属性设置为禁用。
我采用了一种简单的方法,遍历JSF组件树并将组件禁用。(这样用户就无法更改值)。但是这种方法对于复合组件不起作用。我该如何至少检测到复合组件?然后我可以尝试将特殊属性设置为禁用。
UIComponent
类有一个isCompositeComponent()
帮助方法,可以实现这个目的。for (UIComponent child : component.getChildren()) {
if (UIComponent.isCompositeComponent(child)) {
// It's a composite child!
}
}
对于对“底层操作”感兴趣的人,这里是Mojarra 2.1.25的实现源代码:
public static boolean isCompositeComponent(UIComponent component) {
if (component == null) {
throw new NullPointerException();
}
boolean result = false;
if (null != component.isCompositeComponent) {
result = component.isCompositeComponent.booleanValue();
} else {
result = component.isCompositeComponent =
(component.getAttributes().containsKey(
Resource.COMPONENT_RESOURCE_KEY));
}
return result;
}
因此,它通过具有由Resource.COMPONENT_RESOURCE_KEY
定义的名称的组件属性进行识别,该属性的值为"javax.faces.application.Resource.ComponentResource"
。
NamingContainer
接口是组合组件后端 bean 类型的唯一限制,但有很多其他实现该接口的东西。 - rdcrng