禁用大型项目中的组件 [英] Disable components in a large project
问题描述
有很多开发人员和大三学生,我想禁用某些组件,例如<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?
推荐答案
基本上,您可以通过提供自定义 ApplicationWrapper
),其中您覆盖了
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.primefaces.component.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>
这篇关于禁用大型项目中的组件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!