java - 如何显示primefaces布局的镜像

标签 java css jsf-2 primefaces

我遇到了一些关于 Primefaces 的问题。有一个要求,当我们将顶部面板的语言从英语更改为阿拉伯语时,整个布局应该从右到左的位置显示(就像镜像应用于所有内页)。请帮帮我。

我包括英文版布局、顶部面板和 Controller bean。

1.布局

<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:p="http://primefaces.org/ui">
<h:head>
 <title>Facelet Title</title>
        <style type="text/css">
            .ui-growl{
                left:20px;
            }
        </style>

</h:head>
<body>

    <ui:composition template="/home/template/common/commonLayout.xhtml">
        <ui:define name="content">




            <h:form enctype="multipart/form-data" dir="#{localeControllerBean.direction}" id="form1">
                <div id="add">
                <p:growl  id="msgs" autoUpdate="true" display="icon" style="left:20px"></p:growl>

                </div>
                <p:panel header="#{msg['sponsor_detail']}">
                    <h:panelGrid columns="2">
                    <f:event listener="#{localeControllerBean.islang}" type="preRenderView" />

                        <p:outputLabel for="sname" value="#{msg['sponsor_name']}"
                            styleClass="label" />
                        <p:inputText id="sname" value="#{sponsorBean.sponsor_name}"
                            required="true" requiredMessage="#{msg['sponsor_name_msg']}"
                            styleClass="input">
                            <f:validator validatorId="sponsorValidator" />
                        </p:inputText>

                        <p:outputLabel for="sadd" value="#{msg['sponsoraddress']}:"
                            styleClass="label" />
                        <p:inputText id="sadd" value="#{sponsorBean.s_address}"
                            required="true" requiredMessage="#{msg['Sponsor_address_msg']}"
                            styleClass="input" />

                        <p:outputLabel for="smb" value="#{msg['sponsor_mbno']}:"
                            styleClass="label" />
                        <p:inputText id="smb" value="#{sponsorBean.s_mobile_no}"
                            required="true" requiredMessage="#{msg['sponsor_mbno_msg']}"
                            styleClass="input" />

                        <p:outputLabel for="ss" value="#{msg['sponsor_status']}:" styleClass="label" />
                        <p:inputText id="ss" value="#{sponsorBean.status}" required="true"
                            requiredMessage="#{msg['sponsor_mbno_msg']}" styleClass="input" />

                    </h:panelGrid>
                    <p:commandButton id="submit" value="#{msg['save']}" ajax="false"
                        action="#{sponsorBean.save}" style="margin-bottom:50px;"
                        update="msgs" />

                    <p:commandButton type="reset" value="#{msg['reset']}"
                        style="margin-bottom:50px;margin-left:30px;" ajax="false" />
                </p:panel>
            </h:form>
        </ui:define>
    </ui:composition>
</body>
</html>

2.toppanel 在这里我改变语言..

<html xmlns="http://www.w3.org/1999/xhtml"   
        xmlns:h="http://java.sun.com/jsf/html"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:p="http://primefaces.org/ui">
<h:head>

</h:head>
    <body>
        <ui:composition>

<h:form>

  <p:growl id="messages" >

  <p:toolbar style="Font-size:small;"> 

  <p:toolbarGroup align="left"> 
       <h:outputText value="User : " style=" margin-left:15px;"  />  


    <h:outputText  value="#{loginBean.username}">


</h:outputText>



       <p:commandButton value="Logout" action="#{loginBean.doLogout}"  icon="ui-icon-extlink" />



    </p:toolbarGroup>


    <p:toolbarGroup align="right">
     <p:commandButton value="#{loginBean.toggleButton}" action="#{loginBean.goHome}"  icon="ui-icon-home"/>

 <p:inputText id="firstname" value="#{manageEmployee.search}" dir="ltr" styleClass="input"  style="margin-right:15px" />         


    <h:selectOneMenu  
            value="#{manageEmployee.searchFilter}" style="FONT-STYLE: plain; FONT-SIZE:small;margin-right:10px">
             <f:selectItem itemLabel="All" itemValue="All" />  
            <f:selectItem itemLabel="Search by company" itemValue="company" /> 
            <f:selectItem itemLabel="Search by sponsor" itemValue="sponsor" /> 
        </h:selectOneMenu>





      <p:commandButton id="submit" value="Search" ajax="false"
                action="#{manageEmployee.searchRecords}"  update="msgs" style="margin-left:10px" icon="ui-icon-search"  />


     <h:selectOneMenu value="#{localeBean.language}" onchange="submit()" style="margin-left:10px" >
                <f:selectItem itemValue="en" itemLabel="English" />
                <f:selectItem itemValue="ar" itemLabel="Arabic" />


    </h:selectOneMenu>
    </p:toolbarGroup>

  </p:toolbar></p:growl>
</h:form>
        </ui:composition>
    </body>
</html>

3.本地Bean Controller :

import java.util.Locale;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;
import javax.servlet.http.HttpSession;

@ManagedBean
@SessionScoped
public class LocaleBean {

    private Locale locale = FacesContext.getCurrentInstance().getViewRoot().getLocale();

    public Locale getLocale() {
        return locale;
    }

    public String getLanguage() {
        return locale.getLanguage();
    }

    public void setLanguage(String language) {
        locale = new Locale(language);
        FacesContext.getCurrentInstance().getViewRoot().setLocale(locale);
        FacesContext facesContext = FacesContext.getCurrentInstance();
        HttpSession session = (HttpSession) facesContext.getExternalContext().getSession(true);
        session.setAttribute("user", locale);
//        session.setAttribute("language", language);
    }


    public String save()
    {
        return "homePage";
    }
}

4.语言 Controller :

import java.util.Locale;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;
import javax.faces.event.ComponentSystemEvent;
import javax.servlet.http.HttpSession;

@ManagedBean
@SessionScoped
public class LocaleControllerBean {
    public static String dir="";
    private String direction="";

    public String getDirection() {
        return direction;
    }

    public void setDirection(String direction) {
        this.direction = direction;
    }

    public void islang(ComponentSystemEvent event)
    {
        FacesContext facesContext = FacesContext.getCurrentInstance();
        HttpSession session = (HttpSession) facesContext.getExternalContext().getSession(true);
        Locale l=(Locale) session.getAttribute("user");
        if(l.toString().equals("ar"))
        {
//          dir="rtl";
            setDirection("rtl");
        }
        else
        {
            setDirection("ltr");
//          dir="ltr";
        }
        System.out.println("locale"+l);
        facesContext.getViewRoot().setLocale(l);
    }

}

最佳答案

RTL 支持是 primefaces 中的新功能。我认为这是不可能的,只是让整个页面看起来像镜像而不实际重新创建页面。 css 本身可能不会执行此操作,因此您需要创建一个单独的页面(或一组页面),在更改语言环境后您将被重定向到该页面。

有关 primefaces 中的 RTL 支持的更多信息,请参见此处:http://code.google.com/p/primefaces/issues/detail?id=3890如您所见,它是逐个组件的组件,而不是全局的。

关于java - 如何显示primefaces布局的镜像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17360886/

相关文章:

java - 选择在扩展数据表、RichFaces 4 + JSF 2.0 中不起作用

javascript - JSF setPropertyActionListener 设置 javascript 整数值

java - 如何直接调用泛型方法?

java - 使用java的数组和链表的堆接口(interface)

html - IE 中的按钮颜色不会改变。 (背景图像 : linear-gradient)

设置转换属性后,CSS 模糊滤镜无法在边缘工作

javascript - 谷歌浏览器移动版 (Nexus 7) |表单提交不起作用

java - 奥利奥通知翻倍?

java - 非法参数异常 : Deserializing generated objects with @JsonString annotation

html - 使用从右到左的语言显示 Bootstrap 弹出窗口