localization - JSF render dir="rtl" when language is arabic -
i want render text direction rtl (right-to-left) in inputtext when browser's accept-language arabic in jsf application. when accept-language english text introduced user dir="ltr" (left-to-right). how can it?
the client's accept-language indirectly available via uiviewroot#getlocale(). uiviewroot in turn in el available #{view}. so, should do:
<h:inputtext ... dir="#{view.locale.language eq 'ar' ? 'rtl' : 'ltr'}" /> note dir supported on other components , html elements, such <h:form> , <html>.
<html ... dir="#{view.locale.language eq 'ar' ? 'rtl' : 'ltr'}"> it applied on children unless overridden differently set dir. save repeating same attribute on child components/elements.
also note jsf accept locales explicitly registered in <locale-config> in faces-config.xml. if don't have ar in there, 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> move if necessary logic managed bean can end below:
<h:inputtext ... dir="#{localemanager.dir}" />
Comments
Post a Comment