前面按照别人的想法做了一个,这次按照自己的想法自己做了一个。
tml如下
<t:form t:id&#61;"locale"><t:loop source&#61;"LocalesSource" value&#61;"selectedLocale" formState&#61;"ITERATION"><t:test server&#61;"currentLocale" client&#61;"${selectedLocale.locale.language}"><img src&#61;"${selectedLocale.asset}" class&#61;"currentFlag" /><p:else><a t:type&#61;"actionLink" t:id&#61;"changeLocale" context&#61;"${selectedLocale.locale.language}" href&#61;"#"><img src&#61;"${selectedLocale.asset}" class&#61;"notCurrentFlag" />a>p:else>t:test>t:loop><div class&#61;"message">${message:greeting_message}div>t:form>
java如下&#xff1a;
public class LocaleSwitcher2
{&#64;Inject&#64;Property&#64;Symbol(SymbolConstants.SUPPORTED_LOCALES)private String locales;&#64;Injectprivate PersistentLocale persistentLocale;&#64;Propertyprivate LocaleBean selectedLocale;&#64;Inject&#64;Path("context:images/country_zh.png")private Asset assetZh;&#64;Inject&#64;Path("context:images/country_it.png")private Asset assetIt;&#64;Inject&#64;Path("context:images/country_ja.png")private Asset assetJa;&#64;Inject&#64;Path("context:images/country_en.png")private Asset assetEn;public List
public class LocaleBean
{private Locale locale;private Asset asset;public Locale getLocale(){return locale;}public void setLocale(Locale locale){this.locale &#61; locale;}public Asset getAsset(){return asset;}public void setAsset(Asset asset){this.asset &#61; asset;}}
public class Test extends AbstractConditional
{&#64;Parameter(required &#61; true)private String client;&#64;Parameter(required &#61; true)private String server;&#64;Parameterprivate boolean negate;&#64;Overrideprotected boolean test(){return client.equalsIgnoreCase(server);}}
效果图&#xff1a;