如何停用JSF标记(Primefaces)

时间:2022-05-13 19:59:46

I use Primefaces 5.x (on myFaces 2.2.x) for my UI and I want to disable / deactivate some JSF tags like to avoid mistakes.

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

Is there a blacklist or whitelist I can use?

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

1 个解决方案

#1


There's no such thing in standard JSF/PrimeFaces API.

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

Quick'n'dirty workaround would be overriding the component registration in webapp's faces-config.xml whereby you set the component class to a non-UIComponent class (it will ultimately throw ClassCastException on usage), or to a custom UIComponent which throws e.g. IllegalArgumentException in its constructor.

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

E.g. if you'd like to avoid usage of <p:selectOneMenu> component which has a component type of org.primefaces.component.SelectOneMenu:

例如。如果您想避免使用组件类型为org.primefaces.component.SelectOneMenu的 组件:

<component>
    <component-type>org.primefaces.component.SelectOneMenu</component-type>
    <component-class>java.lang.Object</component-class>
</component>

An alternative would be to manually visit the component tree after it's being built and check every single component class against a white/black list in a Set<Class<UIComponent>>.

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

A more clean alternative would be to override Application#createComponent() to check the component type against a white/black list.

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

Yet another alternative would be to edit the PrimeFaces taglib/config XML to remove the undesired components and rebuild the JAR.

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

#1


There's no such thing in standard JSF/PrimeFaces API.

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

Quick'n'dirty workaround would be overriding the component registration in webapp's faces-config.xml whereby you set the component class to a non-UIComponent class (it will ultimately throw ClassCastException on usage), or to a custom UIComponent which throws e.g. IllegalArgumentException in its constructor.

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

E.g. if you'd like to avoid usage of <p:selectOneMenu> component which has a component type of org.primefaces.component.SelectOneMenu:

例如。如果您想避免使用组件类型为org.primefaces.component.SelectOneMenu的 组件:

<component>
    <component-type>org.primefaces.component.SelectOneMenu</component-type>
    <component-class>java.lang.Object</component-class>
</component>

An alternative would be to manually visit the component tree after it's being built and check every single component class against a white/black list in a Set<Class<UIComponent>>.

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

A more clean alternative would be to override Application#createComponent() to check the component type against a white/black list.

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

Yet another alternative would be to edit the PrimeFaces taglib/config XML to remove the undesired components and rebuild the JAR.

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