JSF render dir =“rtl”当语言是阿拉伯语时 [英] JSF render dir="rtl" when language is arabic

查看:223
本文介绍了JSF render dir =“rtl”当语言是阿拉伯语时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我的JSF应用程序中的浏览器的Accept-Language是阿拉伯语时,我想在inputText中呈现文本方向rtl(从右到左)。当接受语言是英文时,用户引入的文本将是dir =ltr(从左到右)。如何做?

I want to render the text direction rtl (Right-To-Left) in an inputText when the browser's Accept-Language is arabic in my JSF application. When Accept-Language is english the text introduced by the user would be dir="ltr" (Left-To-Right). How can I do it?

推荐答案

客户端的 Accept-Language 可以通过 UIViewRoot#的getLocale() UIViewRoot 依次为EL,可用作#{view} 。所以,这应该是:

The client's Accept-Language is indirectly available via UIViewRoot#getLocale(). The UIViewRoot is in turn in EL available as #{view}. So, this should do:

<h:inputText ... dir="#{view.locale.language eq 'ar' ? 'rtl' : 'ltr'}" />

请注意,还支持 dir 所有其他组件和HTML元素,例如< h:form> 甚至< html> p>

Note that the dir is also supported on all other components and HTML elements, such as <h:form> and even <html>.

<html ... dir="#{view.locale.language eq 'ar' ? 'rtl' : 'ltr'}">

它将应用于其所有子项,除非被不同的设置目录覆盖。这将节省您对所有子组件/元素重复相同的属性。

It would be applied on all its children unless overridden by a differently set dir. That would save you from repeating the very same attribute over all child components/elements.

另请注意,JSF将仅接受在<$ c $中明确注册的语言环境 faces-config.xml 中的c>< locale-config> 。所以如果你还没有 ar ,那么上述不行,不管 Accept-Language 标题。

Also note that the JSF will only accept locales which are explicitly registered in <locale-config> in faces-config.xml. So if you don't already have ar in there, then the above wouldn't work irrespective of Accept-Language header.

<application>
    <locale-config>
        <default-locale>en</default-locale>
        <supported-locale>ar</supported-locale>
        ...
    </locale-config>
</application>

如果需要,将逻辑移动到托管bean,以便您可以如下所示结束:

Move if necessary the logic to a managed bean so that you can end up like below:

<h:inputText ... dir="#{localeManager.dir}" />



另请参见:



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