read-Atleap-2-动态改变页面显示语言

王朝java/jsp·作者佚名  2006-01-31
窄屏简体版  字體: |||超大  

Atleap中struts tiles主模板页面是:/WEB-INF/pages/layouts/core/coreLayout.jsp

Ø 改变页面显示语言

<definition name=".switchLocaleForm" extends=".blockLayout"

controllerClass="com.blandware.atleap.webapp.action.core.contentLocale

.LocaleListController"> (1)

<put name="blockBody"

value="/WEB-INF/pages/core/contentLocale/switchLocaleForm.jsp" />(2)

</definition>

(1)的说明,取得locale表中的本地化信息,形成List,存入request中

Ø 进入修改语言页面之前执行的操作

public final class LocaleListController extends ControllerSupport {

/**

* Retrieves all locales and puts them into request

*/

public void execute(ComponentContext tilesContext, HttpServletRequest request, HttpServletResponse response, ServletContext servletContext)

throws Exception {

WebApplicationContext ctx = WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext);

LookupManager lookupManager = (LookupManager) ctx.getBean(Constants.LOOKUP_MANAGER_BEAN);

List localesList = lookupManager.listActiveContentLocales();

request.setAttribute(WebappConstants.LANGUAGES_COLLECTION_KEY, localesList);

}

// public static final String LANGUAGES_COLLECTION_KEY = //"com.blandware.atleap.LANGUAGES_COLLECTION";

}

Ø LookupManagerImpl的listActiveContentLocales方法

public List listActiveContentLocales() {

List contentLocales = lookupDAO.listActiveContentLocales();

List result = new ArrayList();

for ( Iterator i = contentLocales.iterator(); i.hasNext(); ) {

Object[] values = (Object[]) i.next();

String label = (String) values[0];

String value = (String) values[1];

LabelValue labelValue = new LabelValue(label, value);

result.add(labelValue);

}

return result;

}

ØLookupDAOHibernate的listActiveContentLocales方法

public List listActiveContentLocales() {

return executeFind("select l.name, l.identifier from ContentLocale l where l.active = 'T' order by l.identifier", true, null);

}

+------------+---------+----------------+------------------+--------+

| identifier | version | name | default_instance | active |

+------------+---------+----------------+------------------+--------+

| en | 0 | English | T | T |

| ru | 0 | 袪褍褋褋泻懈泄 | F | T |

+------------+---------+----------------+------------------+--------+

Ø lookupManager bean

<!-- Lookup Manager Implementation -->

<bean id="lookupManager" class="com.blandware.atleap.service.core.impl.LookupManagerImpl">

<property name="lookupDAO">

<ref bean="lookupDAO"/>

</property>

<property name="localizableDAO">

<ref bean="localizableDAO"/>

</property>

</bean>

Ø lookupDAO bean

<bean id="lookupDAO" class="com.blandware.atleap.persistence.hibernate.core.LookupDAOHibernate">

<property name="sessionFactory">

<ref local="sessionFactory"/>

</property>

</bean>

Ø localizableDAO bean

<!-- LocalizableDAO: Hibernate implementation -->

<bean id="localizableDAO" class="com.blandware.atleap.persistence.hibernate.core.LocalizableDAOHibernate">

<property name="sessionFactory">

<ref local="sessionFactory"/>

</property>

</bean>

(2)的说明,

Ø Struts-config.xml设置

<action

path="/switchLocale"

type="com.blandware.atleap.webapp.action.core.contentLocale.SwitchLocaleAction"

name="switchLocaleForm"

scope="request"

unknown="false"

validate="false"

>

Ø switchLocaleForm.jsp中调用的struts action

public ActionForward execute(ActionMapping mapping, ActionForm form,

HttpServletRequest request, HttpServletResponse

response) throws Exception {

SwitchLocaleForm switchLocaleForm = (SwitchLocaleForm) form;

Locale newLocale = new Locale(switchLocaleForm.getLocaleIdentifier());

String redirectUrl = switchLocaleForm.getRedirectUrl();

request.getSession().setAttribute(Globals.LOCALE_KEY, newLocale);

ActionForward redirect = new ActionForward();

redirect.setRedirect(true);

redirect.setPath(redirectUrl);

return redirect;

}

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航