简体   繁体   English

可能有一个ApplicationScoped bean,该bean使JSF 2应用程序具有丰富的皮肤外观?

[英]Possible to have an ApplicationScoped bean that skins a JSF 2 application with a richfaces skin?

In production want the user to be able to write a properties file and upload that file to our production server. 在生产中,希望用户能够写入属性文件并将该文件上传到我们的生产服务器。 Once this is in place it will contain the properties needed for a richfaces skin. 一旦安装到位,它将包含Richfaces皮肤所需的属性。 This file can be named whatever. 该文件可以命名为任何名称。

In development I want the properties file to be read from inside WEB-INF/myprop.properties where all my other properties files are. 在开发中,我希望从所有其他属性文件所在的WEB-INF/myprop.properties内部读取属性文件。 This file can be named whatever. 该文件可以命名为任何名称。

So far I have done this: 到目前为止,我已经做到了:

@ManagedBean(name="myCustomSkin ")
@ApplicationScoped
public class MyCustomSkin extends SkinFactoryImpl {
    /*
     * In here I call 
     * Skin s = this.buildSkin(context, "skin"); in my constructor
     * I am also overriding the loadProperties() method so it load my properties just fine
     * For some reason I can't get my app to actually use the properties I have loaded
     */
}

Any ideas? 有任何想法吗? Basically I want to dynamically skin my richfaces application via an ApplicationScoped ManagedBean that gets initialized on startup of my Tomcat 7 server. 基本上,我想通过ApplicationScoped ManagedBean动态为Richfaces应用程序添加外观,该属性在启动Tomcat 7服务器时进行了初始化。 Ideally the name of the skin file would be dynamic user input possibly read from the database or a different properties file. 理想情况下,外观文件的名称应该是动态用户输入,可以从数据库或其他属性文件中读取。

EDIT 1: I have gotten it to load the properties file and then I manually (through java code) tried to insert a context-param by using servletContext.setInitParameter("org.richfaces.skin", this.skin); 编辑1:我已经得到它来加载属性文件,然后我手动(通过java代码)尝试通过使用servletContext.setInitParameter("org.richfaces.skin", this.skin);插入一个上下文参数servletContext.setInitParameter("org.richfaces.skin", this.skin); where this.skin is a String variable which I get the value for like this: this.skin = s.getName(); 其中this.skin是一个String变量,我得到这样的值: this.skin = s.getName(); and if you see above s is just the Skin object I get back from this.buildSkin . 如果您在s上方看到s只是Skin对象,我将从this.buildSkin This comes to a SkinNotFound Exception because I am assuming my skin isn't getting place in my class path or something. 这是一个SkinNotFound Exception因为我假设我的皮肤在类路径或其他内容中没有位置。

EDIT 2: Using JSF 2.1.17, Richfaces 4.3.0, and Tomcat7 编辑2:使用JSF 2.1.17,Richfaces 4.3.0和Tomcat7

EDIT 3: Is there a way to tell richfaces to look in a different directory for the myskin.skin.properties file? 编辑3:有没有办法告诉richfaces在myskin.skin.properties文件的不同目录中myskin.skin.properties

Thanks 谢谢

To implement something like this RichFaces source code is your best friend. 实现这样的RichFaces源代码是您最好的朋友。

Here is what I have found how you can do what you want: 这是我发现您可以如何做自己想做的事情:

Add a file to a jar (or anywhere so it will appear in classpath) META-INF/services/org.richfaces.application.Module Content of the file should be com.example.CustomModule 将文件添加到jar中(或将其添加到类路径中的任何位置) META-INF/services/org.richfaces.application.Module文件内容应为com.example.CustomModule

Implementation of the custom module can be like this: 自定义模块的实现可以是这样的:

public class CustomModule implements Module {
    public void configure(ServicesFactory factory) {
        factory.setInstance(SkinFactory.class, new CustomSkinFactoryImpl());
    }
}

And then implement SkinFactory according to your needs, for example (if you want to extend default behavior with your CustomSkin): 然后根据您的需要实现SkinFactory,例如(如果您想使用CustomSkin扩展默认行为):

public class CustomSkinFactoryImpl extends SkinFactoryImpl {
    public Skin getSkin(FacesContext context) {
        return new CompositeSkinImpl(new CustomSkin(), super.getSkin(context));
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM