Those who are constantly working in adf/webcenter framework,then are acquainted with skin changing by selecting some kind of drop down list.Steps and some sort of code is documented by Oracle in the following link http://docs.oracle.com/cd/E21764_01/web.1111/b31973/af_skin.htm (To conditionally configure a component to set the skin family:) Now this is the base of what I am going to show you.
Skins will be changing based on user clicks on link.
Step 1:Under WEB-INF folder,create trinidad-skins.xml. where you will mention your skins.
just like below -(Assuming you have two skins redSkin.css and yellowSkin.css in your application.
<?xml version="1.0" encoding="ISO-8859-1"?>
<skins xmlns="http://myfaces.apache.org/trinidad/skin">
<skin>
<id>redSkin.desktop</id>
<family>redSkin</family>
<extends>blafplus-rich.desktop</extends>
<render-kit-id>org.apache.myfaces.trinidad.desktop</render-kit-id>
<style-sheet-name>skins/redSkin.css</style-sheet-name>
</skin>
<skin>
<id>yellowSkin.desktop</id>
<family>yellowSkin</family>
<extends>blafplus-rich.desktop</extends>
<render-kit-id>org.apache.myfaces.trinidad.desktop</render-kit-id>
<style-sheet-name>skins/yellowSkin.css</style-sheet-name>
</skin>
</skins>
Step 2 :Create a managed bean to change skins dynamically and register the managed bean in adfc-config.xml or faces-config.xml (whatever you prefer).This bean will populate list of skins in trinidad-config.xml.
Skins will be changing based on user clicks on link.
Step 1:Under WEB-INF folder,create trinidad-skins.xml. where you will mention your skins.
just like below -(Assuming you have two skins redSkin.css and yellowSkin.css in your application.
<?xml version="1.0" encoding="ISO-8859-1"?>
<skins xmlns="http://myfaces.apache.org/trinidad/skin">
<skin>
<id>redSkin.desktop</id>
<family>redSkin</family>
<extends>blafplus-rich.desktop</extends>
<render-kit-id>org.apache.myfaces.trinidad.desktop</render-kit-id>
<style-sheet-name>skins/redSkin.css</style-sheet-name>
</skin>
<skin>
<id>yellowSkin.desktop</id>
<family>yellowSkin</family>
<extends>blafplus-rich.desktop</extends>
<render-kit-id>org.apache.myfaces.trinidad.desktop</render-kit-id>
<style-sheet-name>skins/yellowSkin.css</style-sheet-name>
</skin>
</skins>
Step 2 :Create a managed bean to change skins dynamically and register the managed bean in adfc-config.xml or faces-config.xml (whatever you prefer).This bean will populate list of skins in trinidad-config.xml.
- package hoque.skin;
- import javax.faces.context.FacesContext;
- public class SkinBean {
- private String[] skins = new String[] {"redSkin","yellowSkin","Portal" };
- private String currentSkin = null;
- public String[] getSkins() {
- return skins;
- }
- public void setCurrentSkin(String currentSkin) {
- this.currentSkin = currentSkin;
- }
- public String getCurrentSkin() {
- if(currentSkin==null){
- FacesContext ctx = FacesContext.getCurrentInstance();
- String skinPreference=(String)ctx.getApplication().evaluateExpressionGet(ctx, "#{preferenceBean.defaultTrinidadSkin}", Object.class);
- currentSkin = skinPreference;
- }
- return currentSkin;
- }
- }
Step 3:Change the default skin preferencebean in trinidad-config.xml.
?xml version="1.0" encoding="windows-1252"?>
<trinidad-config xmlns="http://myfaces.apache.org/trinidad/config">
<skin-family>#{SkinBean.currentSkin}</skin-family>
<skin-version>v1.1</skin-version>
</trinidad-config>
<trinidad-config xmlns="http://myfaces.apache.org/trinidad/config">
<skin-family>#{SkinBean.currentSkin}</skin-family>
<skin-version>v1.1</skin-version>
</trinidad-config>
Step 4: Add CommandLinks with actionListeners in jspx page.
<af:commandLink text="Red"
id="cl1"
actionListener="#{skinChangeBean.change}"/>
id="cl1"
actionListener="#{skinChangeBean.change}"/>
<af:commandLink text="Yellow"
id="cl2"
actionListener="#{skinChangeBean.change}"/>
id="cl2"
actionListener="#{skinChangeBean.change}"/>
Step 5: Create SkinChangeBean managed bean to change the skins and register it in adfc-config.xml or faces.xml.
- package hoque.skin;
- import javax.faces.context.FacesContext;
- import javax.faces.event.ActionEvent;
- public class SkinChangeBean{
- private SkinSelectorBean preferencebean;
- public void change(ActionEvent actionEvent) {
- FacesContext ctx = FacesContext.getCurrentInstance();
- String skinvalue="redSkin";
- preferencebean =
- (SkinBean )ctx.getApplication().evaluateExpressionGet(ctx, "#{SkinBean }", Object.class);
- if(preferencebean!=null){
- if(skinvalue.equalsIgnoreCase(preferencebean.getCurrentSkin())){
- skinvalue = "yellowSkin";
- }
- preferencebean.setCurrentSkin(skinvalue);
- }
- // Add event code here...
- }
- }
Step 6:Run you application and observe the changes.
No comments :
Post a Comment