禁用大型项目​​中的组件

编程入门 行业动态 更新时间:2024-10-27 19:21:44
本文介绍了禁用大型项目​​中的组件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

有很多开发人员和大三学生,我想禁用某些组件,例如<p:spacer>,以禁止将组件用于html/css问题.我想将诸如omnifaces/primefaces/richfaces之类的库的可用组件基本上限制为白名单/黑名单.

with a lot of developers and plenty of juniors I want to disable certain components such as <p:spacer> to prohibit using components for html/css issues. I want to limit the available components for libraries like omnifaces / primefaces / richfaces to a whitelist / blacklist thing basically.

这对于像omnifaces这样的库来说是合理的功能要求吗?还是很难构建/本地化?

Would this be a reasonable feature request for a library like omnifaces or is it to hard to build / to localized?

推荐答案

基本上,您可以通过提供自定义 Application 实现(基于 ApplicationWrapper ),其中您覆盖了所需的createComponent()方法并抛出例如IllegalArgumentException传递了列入黑名单的组件类型和/或渲染器类型时.

Basically, you can achieve this by providing a custom Application implementation (based on ApplicationWrapper) wherein you override the desired createComponent() method and throw e.g. IllegalArgumentException when a blacklisted component type and/or renderer type is passed.

这是一个开球示例:

public class YourApplication extends ApplicationWrapper { private static final Set<String> BLACKLISTED_COMPONENT_TYPES = unmodifiableSet(new HashSet<>(asList( "org.primefacesponent.Spacer", "com.example.SomeComponentType", "com.example.OtherComponentType" // Etc.. ))); private final Application wrapped; public YourApplication(Application wrapped) { this.wrapped = wrapped; } @Override public UIComponent createComponent(FacesContext context, String componentType, String rendererType) { if (BLACKLISTED_COMPONENT_TYPES.contains(componentType)) { throw new IllegalArgumentException("You are not allowed to use this component."); } return super.createComponent(context, componentType, rendererType); } @Override public Application getWrapped() { return wrapped; } }

您可以使其在此工厂中运行:

You can get it to run with this factory:

public class YourApplicationFactory extends ApplicationFactory { private final ApplicationFactory wrapped; public YourApplicationFactory(ApplicationFactory wrapped) { this.wrapped = wrapped; } @Override public Application getApplication() { return new YourApplication(wrapped.getApplication()); } @Override public void setApplication(Application application) { wrapped.setApplication(application); } }

在faces-config.xml中注册的地址如下:

<factory> <application-factory>com.example.YourApplicationFactory</application-factory> </factory>

更多推荐

禁用大型项目​​中的组件

本文发布于:2023-11-23 05:16:36,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1620221.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:组件   项目

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!