通过单击按钮更改语言 [英] Changing language by clicking a button

查看:175
本文介绍了通过单击按钮更改语言的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个JSF/RichFaces设置,并且找到了教程.我一步一步地遵循了它,但是我无法设法得到它.

I have a JSF/RichFaces setup, and I found this tutorial. I followed it step by step, but I can't manage to get it.

还:本教程中提到了language.jsp,有人可以告诉我这是什么技巧吗?

Also: language.jsp is mentioned in the tutorial, can anybody tell me what exaclty it is?

或者,如果您认为这不是一个合适的教程,并且有一个更好的教程,请告诉我.

Or if you think this is not an appropiate tutorial and have a better one, please, let me know.

推荐答案

并不需要本教程中的所有步骤.
我所做的(并且有效)是:
1.例如,在 loging.xhtm 中:

All the steps in the tutorial are not really needed.
What I did (And it works) is:
1. In loging.xhtm, for instance:

    <f:view locale="#{languageDetails.locale}" >
    <head>
    .....
    <f:loadBundle basename="messages.Messages" var="msg1"/>
    .....
<f:view>
     <h:form>
          <h:panelGrid columns="2">
                <h:outputText value="Select Language"></h:outputText>
                <h:selectOneMenu id="dropdown" value="#{languageDetails.locale}">
                      <f:selectItem itemValue="en" itemLabel="English" />
                      <f:selectItem itemValue="es" itemLabel="Spanish" />
                      <f:selectItem itemValue="de" itemLabel="German" />
                </h:selectOneMenu>
          </h:panelGrid>
          <p><h:commandButton id="change" value="Change Language"
           action="#{languageDetails.changeLanguage}" /></p>


      </h:form>
</f:view>


    </body>
    </f:view>

2.在Java源代码中,我还进行了一些更改:

2.In java source code I also made some changes:

public class LanguageDetails {

    private static String locale = Locale.getDefault().getDisplayLanguage();

      public void setLocale(String locale1) {
        this.locale = locale1;
      }

      public synchronized String getLocale() {
        return locale;
      }

      public synchronized String changeLanguage() {
        return "changed";
      }
}

仅此而已.
希望这可以帮助

And that's all.
Hope this could help

这篇关于通过单击按钮更改语言的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆