如何停用JSF标记(Primefaces)

Dan*_*ens 2 jsf blacklist primefaces jsf-2.2

我在我的UI中使用Primefaces 5.x(在myFaces 2.2.x上),我想禁用/停用一些JSF标签,以避免错误.

我可以使用黑名单或白名单吗?

Bal*_*usC 5

标准的JSF/PrimeFaces API中没有这样的东西.

Quick'n'dirty解决方法将覆盖webapp中的组件注册,faces-config.xml从而将组件类设置为非UIComponent类(它最终将ClassCastException用于使用),或者设置为UIComponent例如IllegalArgumentException在其构造函数中抛出的自定义.

如果你想如避免的使用<p:selectOneMenu> 部件具有的组件类型org.primefaces.component.SelectOneMenu:

<component>
    <component-type>org.primefaces.component.SelectOneMenu</component-type>
    <component-class>java.lang.Object</component-class>
</component>
Run Code Online (Sandbox Code Playgroud)

另一种方法是在构建组件树之后手动访问组件树,并根据a中的白/黑列表检查每个组件类Set<Class<UIComponent>>.

更干净的替代方法是覆盖Application#createComponent()以针对白/黑列表检查组件类型.

另一种方法是编辑PrimeFaces taglib/config XML以删除不需要的组件并重建JAR.

  • 或者你自己以前的答案:http://stackoverflow.com/questions/28560957/disable-components-in-a-large-project (2认同)