java - i18n on dropdown menu using s:select tag -
this question has answer here:
i have dropdown menu in jsp page implemented <s:select>
tag
<s:select name="priortoapplyinginfo.userprofile.phonenumbers[0].type" listkey="key" listvalue="value" list="phonetypes" headerkey="0" headervalue=""/>
now values in dropdown menu list phonetypes
implemented hashmap
in .java
file.
phonetypes = new linkedhashmap<integer, string>(); phonetypes.put(new integer(1), gettext("home")); // phone contactbook category business phone phonetypes.put(new integer(daohelperfactory.owner_profile_phone_category), gettext("work")); phonetypes.put(new integer(3), gettext("mobile")); phonetypes.put(new integer(daohelperfactory.owner_profile_fax_category), gettext("fax")); phonetypes.put(new integer(5), gettext("other")); preferredcontact = new arraylist<string>(); preferredcontact.add(gettext("home")); preferredcontact.add(gettext("work")); preferredcontact.add(gettext("mobile")); preferredcontact.add(gettext("fax")); preferredcontact.add(gettext("email")); preferredcontact.add(gettext("other")); bestcontacttime = new arraylist<string>(); bestcontacttime.add(gettext("afternoon")); bestcontacttime.add(gettext("evening")); bestcontacttime.add(gettext("morning"));
the keys home=home
, work=work
, etc., in .properties
file working on internationalizing page , i'm unable find way translations values in dropdown menu.
to change locale in struts2 application need include requst_locale
parameter link or form.
<s:url var="urlen" includeparams="all" value=""> <s:param name="request_locale">en</s:param> </s:url> <s:a href="%{#urlen}">english</s:a>
if want change locale action class use actioncontext
set , put in http session.
actioncontext.getcontext().setlocale(locale); session.put(i18ninterceptor.default_session_attribute, locale);
you can call gettext
method in jsp in listvalue
attribute of <s:select>
tag.
<s:select name="priortoapplyinginfo.userprofile.phonenumbers[0].type" list="phonetypes" headerkey="0" headervalue="" listkey="key" listvalue="%{gettext(value)}"/>
Comments
Post a Comment