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

Atleapstruts 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";

}

Ø LookupManagerImpllistActiveContentLocales方法

    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;

    }

 

ØLookupDAOHibernatelistActiveContentLocales方法

    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;

    }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值