问题
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. 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. 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. 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);
where this.skin
is a String variable which I get the value for like this: this.skin = s.getName();
and if you see above s
is just the Skin object I get back from this.buildSkin
. This comes to a SkinNotFound Exception
because I am assuming my skin isn't getting place in my class path or something.
EDIT 2: Using JSF 2.1.17, Richfaces 4.3.0, and Tomcat7
EDIT 3: Is there a way to tell richfaces to look in a different directory for the myskin.skin.properties
file?
Thanks
回答1:
To implement something like this RichFaces source code is your best friend.
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
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):
public class CustomSkinFactoryImpl extends SkinFactoryImpl {
public Skin getSkin(FacesContext context) {
return new CompositeSkinImpl(new CustomSkin(), super.getSkin(context));
}
}
来源:https://stackoverflow.com/questions/15098394/possible-to-have-an-applicationscoped-bean-that-skins-a-jsf-2-application-with-a