10 Replies Latest reply on Apr 18, 2010 6:43 PM by leonardinius

    Is there any way in seam to change richfaces skin at runtime

    valatharv

      Hi,


      I already have a project created using seam gen.


      On of the user asked if there is any way in seam, to change the richfaces skin at runtime. So that each user can have it own richfaces skin as desired.


      Thanks
      Val

        • 1. Re: Is there any way in seam to change richfaces skin at runtime
          kukeltje.ronald.jbpm.org

          I would think it is not different from how it is done in richfaces without seam.... One addition is that you have to store the selection somewhere. Either in a profile or in a cookie or something.


          btw... google is great (at least for searching... for other things I have my doubts).... http://leonardinius.blogspot.com/2008/05/richfaces-how-to-cahnge-skin-dropdown.html

          • 2. Re: Is there any way in seam to change richfaces skin at runtime
            valatharv
            Great... :))

            Article seems to be very good, I followed the steps, it worked like a charm

            Here are the steps, which might be useful for anyone else who wants to try this, though it is almost same, but I have included all my files, it is very-very useful...

            THANKS THANKS THANKS a lot.

            Web.xml
                <context-param>
                    <param-name>org.richfaces.SKIN</param-name>
                    <param-value>#{skinBean.skin}</param-value>
                </context-param>
            Component.xml
                <component name="skinBean">
                 <property name="skin">blueSky</property>
               </component>

            Test.xhtml
            ----------
            <!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
                                         "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

            <ui:composition xmlns="http://www.w3.org/1999/xhtml"
                  xmlns:ui="http://java.sun.com/jsf/facelets"
                  xmlns:h="http://java.sun.com/jsf/html"
                  xmlns:f="http://java.sun.com/jsf/core"
                  xmlns:a4j="http://richfaces.org/a4j"
                  xmlns:rich="http://richfaces.org/rich"
                  xmlns:s="http://jboss.com/products/seam/taglib"
                  template="layout/template.xhtml">

            <ui:define name="body">
            <s:remote include="skinBean" />

            <script type='text/javascript'>
                 //<![CDATA[
                 function setSkinValue(skinName){
                 Seam.Component.getInstance('skinBean').setSkin(skinName, function(){
                 Seam.Remoting.log('reloading window');
                 window.location.reload(false);
                 });
                 }
                 //]]>
            </script>


            <h:form id="myform"> 
                 <h:selectOneMenu id="skinSelector" value="#{skinBean.skin}"
                 onchange="javascript: setSkinValue(this.value);">
                 <f:selectItem itemValue="DEFAULT" itemLabel="Default" />
                 <f:selectItem itemValue="plain" itemLabel="Plain" />
                 <f:selectItem itemValue="blueSky" itemLabel="Blue Sky" />
                 <f:selectItem itemValue="classic" itemLabel="Classic" />
                 <f:selectItem itemValue="deepMarine" itemLabel="Deep Marine" />
                 <f:selectItem itemValue="emeraldTown" itemLabel="Emerald Town" />
                 <f:selectItem itemValue="japanCherry" itemLabel="Japan Cherry" />
                 <f:selectItem itemValue="ruby" itemLabel="Ruby" />
                 <f:selectItem itemValue="wine" itemLabel="Wine" />
                 </h:selectOneMenu>
            </h:form>

            </ui:define>
            </ui:composition>

            SkinBean.java
            -------------
            import org.jboss.seam.ScopeType;
            import org.jboss.seam.annotations.Create;
            import org.jboss.seam.annotations.Destroy;
            import org.jboss.seam.annotations.Logger;
            import org.jboss.seam.annotations.Name;
            import org.jboss.seam.annotations.Scope;
            import org.jboss.seam.annotations.remoting.WebRemote;
            import org.jboss.seam.log.Log;
            import java.io.Serializable;
            import javax.ejb.Remove;

            @Name("skinBean")
            @Scope(ScopeType.SESSION)
            public class SkinBean implements SkinSelector, Serializable {
                 private static final long serialVersionUID = 7477768262527797286L;

                 @Logger
                 Log log;
                 private String skin;

                 @Create
                 public void create() {
                      log.info("Created");
                 }

                 @WebRemote
                 public String getSkin() {
                      return skin;
                 }

                 @Remove
                 @Destroy
                 public void remove() {
                      log.info("Removed");
                 }

                 @WebRemote
                 public void setSkin(String skinName) {
                      log.info("Setting skin #0", skinName);
                      this.skin = skinName;
                 }
            }

            SkinSelector.java
            -----------------
            import javax.ejb.Local;
            @Local
            public interface SkinSelector {
                 
                 public String getSkin();
                 public void setSkin(String skinName);

            }
            • 3. Re: Is there any way in seam to change richfaces skin at runtime
              kukeltje.ronald.jbpm.org

              You are welcome... I hope next time you do a little bit of searching... oh and btw.... don't forget to rate my answer ;-)

              • 4. Re: Is there any way in seam to change richfaces skin at runtime
                valatharv
                Oops, by mistake, I clicked the 2nd. star, it should be 100%, how can I change it...

                Actually long time back I implemented this (using Swing)allowing user to change look & feel at runtime. I was not sure for seam & rich faces..
                • 5. Re: Is there any way in seam to change richfaces skin at runtime
                  johnodonovan

                  Thanks for this- its great.


                  I'm new, sort of. -can someone tell me where in the project should SkinBean.java go?  Is it with my ejbs (business side) or should it go with my session beans in my WebContent folder?


                  Also- should SkinSelector.java go in the same place?


                  If it helps anyone: i had an error with the @WebRemote annotation. I had to right-click and select 'fix project setup' in eclipse to add the Seam-remoting jar to my build path.

                  • 6. Re: Is there any way in seam to change richfaces skin at runtime
                    yevon

                    thanks alot this is very useful.


                    • 7. Re: Is there any way in seam to change richfaces skin at runtime
                      leonardinius

                      Wow. It did actually help someone. I might to rethink/reconsider to restart blogging activities :)

                      • 8. Re: Is there any way in seam to change richfaces skin at runtime

                        I got:



                        Caused by: org.richfaces.skin.SkinNotFoundException: Skin with name laguna not found
                                at org.richfaces.skin.SkinFactoryImpl.loadProperties(SkinFactoryImpl.java:315)
                                at org.richfaces.skin.SkinFactoryImpl.buildSkin(SkinFactoryImpl.java:277)
                                at org.richfaces.skin.SkinFactoryImpl.getSkinByName(SkinFactoryImpl.java:133)
                                at org.richfaces.skin.SkinFactoryImpl.getSkin(SkinFactoryImpl.java:150)
                                at org.ajax4jsf.resource.TemplateCSSRenderer.getData(TemplateCSSRenderer.java:161)
                                at org.ajax4jsf.resource.InternetResourceBase.getDataToStore(InternetResourceBase.java:236)
                                at org.ajax4jsf.resource.InternetResourceBase.getUri(InternetResourceBase.java:218)
                                at org.ajax4jsf.resource.BaseResourceRenderer.encodeBegin(BaseResourceRenderer.java:64)
                                at org.ajax4jsf.resource.OneTimeRenderer.encodeBegin(OneTimeRenderer.java:48)
                                at org.ajax4jsf.resource.BaseResourceRenderer.encode(BaseResourceRenderer.java:47)




                        • 9. Re: Is there any way in seam to change richfaces skin at runtime

                          Then I added



                          <context-param>
                                  <param-name>org.richfaces.SKIN</param-name>
                                  <param-value>#{skinBean.skin}</param-value>
                              </context-param>


                          in web.xml and I got:




                          Caused by: org.richfaces.skin.SkinNotFoundException: Name for current Skin calculated as null
                                  at org.richfaces.skin.SkinFactoryImpl.getSkinByName(SkinFactoryImpl.java:113)
                                  at org.richfaces.skin.SkinFactoryImpl.getSkin(SkinFactoryImpl.java:150)
                                  at org.ajax4jsf.resource.TemplateCSSRenderer.getData(TemplateCSSRenderer.java:161)
                                  at org.ajax4jsf.resource.InternetResourceBase.getDataToStore(InternetResourceBase.java:236)
                                  at org.ajax4jsf.resource.InternetResourceBase.getUri(InternetResourceBase.java:218)



                          Did anyone got this to work ?????




                          • 10. Re: Is there any way in seam to change richfaces skin at runtime
                            leonardinius

                            See the article http://leonardinius.blogspot.com/2008/05/richfaces-how-to-cahnge-skin-dropdown.html.




                            You can see there is no default value present in the code. That to do and what way to go? I decided to provide the default value in the components.xml - just to allow to change default without recompiling. See the snippet:

                            <component name="skinBean">
                            <property name="skin">japanCherry</property>
                            </component>
                            




                            This will provide a default value .


                            Please update the list of skins name to be up-da-date, The article was written for seam 1.x and skin names might differ in different Seam version.