java ee - Struts2 locale session rewrite -
can rewrite session attribute ww_trans_i18n_locale in struts2? want set locale in cookies, future use, because default session have timeout of 30 minutes, small amount of time locale, if user isn't using site. trying set ww_trans_i18n_locale depending on cookies value, without luck, value remains same is.
i found here question mine, of jsp's pass through actions https://stackoverflow.com/questions/5291271/struts-2-internationalisation-problem , , not solution ..
so want change session value in action? i'm not clear on last line, implement sessionaware should straight forward. best place set value ever user logs in (if any).
something like...
import com.opensymphony.xwork2.actionsupport; import java.util.map; import org.apache.struts2.interceptor.sessionaware; public class myaction extends actionsupport implements sessionaware{ map<string, object> session; @override public string execute(){ session.put("ww_trans_i18n_locale", "fr"); return success; } @override public void setsession(map<string, object> session) { this.session = session; } }
should do. there aware interfaces other scopes see top of page: http://struts.apache.org/2.0.11/struts2-core/apidocs/org/apache/struts2/interceptor/package-summary.html
edit: thinking can't recommend using cookies store language preferences. if this... default i18n interceptor check if parameter called "request_locale" exists , set value on session value. don't want value stored on session. since how struts2 handles default following:
- create own i18n interceptor copy of existing removes language data saved session (thus value pushed session, exists request duration).
- create javascript function added every page (probably through template system), after page has loaded looks anchor tags , form tags. in case of anchor tags adds "request_local" parameter end value finds in cookie, , add hidden field every form set "request_local" parameter cookie.
- i'd put language selection drop down on every page too, sets cookie value , reload current page. idea of creating such list (although drop down better links): tiles2 struts switch locale
for information on i18n interceptor: http://struts.apache.org/2.1.2/struts2-core/apidocs/com/opensymphony/xwork2/interceptor/i18ninterceptor.html
for js function, since i'm partial jquery i'd start either this: http://plugins.jquery.com/project/jsper
or this...
Comments
Post a Comment