jsf - How to do ThemeSwitcher using Primefaces -
this demo i'm trying do. http://www.primefaces.org/showcase/ui/misc/themeswitcher.xhtml
my html code:
<h:form > <h:panelgrid columns="2" cellpadding="10"> <h:outputtext value="basic:"></h:outputtext> <p:themeswitcher effectspeed="normal" effect="fade" style="width:165px" id="defaultswitcher" value="#{themeswitcherbean.theme}"> <f:selectitem itemlabel="choose theme" itemvalue="" /> <f:selectitems value="#{themeswitcherbean.themes}" /> <p:ajax global="false" listener="#{themeswitcherbean.savetheme}" /> </p:themeswitcher> </h:panelgrid> <p:separator /> <p:dialog header="dialog" widgetvar="dlg" minheight="40" modal="true"> <h:outputtext value="resistance primefaces futile!" /> </p:dialog> <p:commandbutton value="dialog" onclick="pf('dlg').show()" type="button" style="display:block;"/> <p:panel header="panel" style="margin:20px 0px"> panel content </p:panel> <p:spinner /> <p:separator /> <p:accordionpanel> <p:tab title="tab1">tab1 content</p:tab> <p:tab title="tab2">tab2 content</p:tab> <p:tab title="tab3">tab3 content</p:tab> </p:accordionpanel>
my web.xml:
<context-param> <param-name>primefaces.theme</param-name> <param-value>#{themeswitcherbean.theme}</param-value> </context-param>
themeswithcherbean.java:
package com.beans; import java.io.serializable; import java.util.map; import java.util.treemap; import javax.annotation.postconstruct; import javax.faces.bean.managedbean; import javax.faces.bean.sessionscoped; import javax.faces.event.ajaxbehaviorevent; import org.primefaces.component.themeswitcher.themeswitcher; @managedbean(name = "themeswitcherbean") @sessionscoped public class themeswitcherbean implements serializable{ /** * */ private static final long serialversionuid = 7448888248791054139l; private map<string, string> themes; private string theme= "south-street"; public map<string, string> getthemes() { return themes; } public string gettheme() { return theme; } public void settheme(string theme) { this.theme = theme; } @postconstruct public void init() { themes = new treemap<string, string>(); themes.put("aristo", "aristo"); themes.put("black-tie", "black-tie"); themes.put("blitzer", "blitzer"); themes.put("bluesky", "bluesky"); themes.put("casablanca", "casablanca"); themes.put("cupertino", "cupertino"); themes.put("dark-hive", "dark-hive"); themes.put("dot-luv", "dot-luv"); themes.put("eggplant", "eggplant"); themes.put("excite-bike", "excite-bike"); themes.put("flick", "flick"); themes.put("glass-x", "glass-x"); themes.put("hot-sneaks", "hot-sneaks"); themes.put("humanity", "humanity"); themes.put("le-frog", "le-frog"); themes.put("midnight", "midnight"); themes.put("mint-choc", "mint-choc"); themes.put("overcast", "overcast"); themes.put("pepper-grinder", "pepper-grinder"); themes.put("redmond", "redmond"); themes.put("rocket", "rocket"); themes.put("sam", "sam"); themes.put("smoothness", "smoothness"); themes.put("south-street", "south-street"); themes.put("start", "start"); themes.put("sunny", "sunny"); themes.put("swanky-purse", "swanky-purse"); themes.put("trontastic", "trontastic"); themes.put("ui-darkness", "ui-darkness"); themes.put("ui-lightness", "ui-lightness"); themes.put("vader", "vader"); } public void savetheme(ajaxbehaviorevent ajax) { settheme((string) ((themeswitcher)ajax.getsource()).getvalue()); } }
i have all-themes-1.0.9.jar , primefaces-3.5.jar have research , try code dropdown list themes doesn't come out.
the outcome capture below:
how solve it?any idea?
another problem current code quite long, want short have tried change code , doesn't work.
current code:
<f:selectitem itemlabel="afterdark" itemvalue="afterdark" /> <f:selectitem itemlabel="afternoon" itemvalue="afternoon" /> <f:selectitem itemlabel="afterwork" itemvalue="afterwork" /> <f:selectitem itemlabel="aristo" itemvalue="aristo" /> <f:selectitem itemlabel="black-tie" itemvalue="black-tie" /> <f:selectitem itemlabel="blitzer" itemvalue="blitzer" /> <f:selectitem itemlabel="bluesky" itemvalue="bluesky" /> <f:selectitem itemlabel="bootstrap" itemvalue="bootstrap" /> <f:selectitem itemlabel="casablanca" itemvalue="casablanca" /> <f:selectitem itemlabel="cupertino" itemvalue="cupertino" /> <f:selectitem itemlabel="cruze" itemvalue="cruze" /> <f:selectitem itemlabel="dark-hive" itemvalue="dark-hive" /> <f:selectitem itemlabel="delta" itemvalue="delta" /> <f:selectitem itemlabel="dot-luv" itemvalue="dot-luv" /> <f:selectitem itemlabel="eggplant" itemvalue="eggplant" /> <f:selectitem itemlabel="excite-bike" itemvalue="excite-bike" /> <f:selectitem itemlabel="flick" itemvalue="flick" /> <f:selectitem itemlabel="glass-x" itemvalue="glass-x" /> <f:selectitem itemlabel="home" itemvalue="home" /> <f:selectitem itemlabel="hot-sneaks" itemvalue="hot-sneaks" /> <f:selectitem itemlabel="humanity" itemvalue="humanity" /> <f:selectitem itemlabel="le-frog" itemvalue="le-frog" /> <f:selectitem itemlabel="midnight" itemvalue="midnight" /> <f:selectitem itemlabel="mint-choc" itemvalue="mint-choc" /> <f:selectitem itemlabel="overcast" itemvalue="overcast" /> <f:selectitem itemlabel="pepper-grinder" itemvalue="pepper-grinder" /> <f:selectitem itemlabel="redmond" itemvalue="redmond" /> <f:selectitem itemlabel="rocket" itemvalue="rocket" /> <f:selectitem itemlabel="sam" itemvalue="sam" /> <f:selectitem itemlabel="smoothness" itemvalue="smoothness" /> <f:selectitem itemlabel="south-street" itemvalue="south-street" /> <f:selectitem itemlabel="start" itemvalue="start" /> <f:selectitem itemlabel="sunny" itemvalue="sunny" /> <f:selectitem itemlabel="swanky-purse" itemvalue="swanky-purse" /> <f:selectitem itemlabel="trontastic" itemvalue="trontastic" /> <f:selectitem itemlabel="ui-darkness" itemvalue="ui-darkness" /> <f:selectitem itemlabel="ui-lightness" itemvalue="ui-lightness" /> <f:selectitem itemlabel="vader" itemvalue="vader" />
i tried:
<f:selectitems value="[afterdark, afternoon, afterwork, aristo, black-tie, blitzer, bluesky, bootstrap, casablanca, cupertino, cruze, dark-hive, delta, dot-luv, eggplant, excite-bike, flick, glass-x, home, hot-sneaks, humanity, le-frog, midnight, mint-choc, overcast, pepper-grinder, redmond, rocket, sam, smoothness, south-street, start, sunny, swanky-purse, trontastic, ui-darkness, ui-lightness, vader]" var="theme" itemlabel="" itemvalue=""/>
and
<f:selectitems value="#{themeswitcherbean.themes}" />
i tried above 2 , doesn't work.any idea?
why using treemap
store themes , list them? in example linked, must use list
instead of map
in <f:select>
tag
in themeswithcherbean.java
private list<theme> themes; @postconstruct public void init() { themes = new arraylist<theme>(); themes.add(new theme(0, "afterdark", "afterdark")); themes.add(new theme(1, "afternoon", "afternoon")); // , many more }
and results in view dropbox.
Comments
Post a Comment