簡體   English   中英

如何使用 Primefaces 從一個 xhtml 頁面連接到另一個頁面中的數據

[英]How to conect from one xhtml page to data in another page with Primefaces

我正在將一些變量從 .xhtml 頁面發送到一個控制器,該控制器將數據發送到另一個頁面,該頁面具有另一個處理該頁面數據的控制器,我曾嘗試使用 setter 和 getter。 問題是我真的不知道與@PostConstruct 有什么關系。

XHTML 文件

<h:form id="frmStart">
 <p:growl id="growl" sticky="true" showDetail="true" />
 <p:panel id="pnlDatos">
 <p:dataTable id="tblObjeto" var="object" 
              value="#{parentControlador.listObjects}" 
              widgetVar="tblObjeto"
              emptyMessage="No hay datos">
  <f:facet name="header">
                            Objetos     
  </f:facet>




<p:column headerText="Contar" width="20">
 <p:commandButton class="pi pi-list" id="openDialogContar" value="Ver"
                                             action="#{parentControlador.FindItems(object)}"
                                             />
</p:column>
</p:dataTable>
</p:panel>
</h:form>

ParentControlador 控制器代碼

    @Inject Item item;

public String FindItems(ObjectParent objectParent) {
        String type="";
        String result="";
        //variable that i am going to send
                ItemControlador itemControlador = new ItemControlador();
                itemControlador.setCorte(objectParent);
        try {

       if(item.listarItemsA(objectParent.getCorte_id()).isEmpty()){
                    this.listaItems = item.listarItemsB(objectParent.getCorte_id());
                    type = "A";
                }else{
                    this.listaItems = item.listarItemA(objectParent.getCorte_id());
                    type = "B";
                } 
                this.objeto = objectParent;  

                result = type == "A"? "A.xhtml":"B.xhtml"; 
        } catch (Exception e) {
            FacesContext.getCurrentInstance().addMessage(null,
                    new FacesMessage(FacesMessage.SEVERITY_ERROR, "Error",
                            "The   objectParent doesnt have items "+e.getMessage()));
        }
        return result;
    }

這是處理“A.xhtml”、“B.xhtml”項目視圖的控制器

     @PostConstruct
     private Parent parent;
    public void init() {
    //From what i see, thos is ejecuted when a .xhtml page is using the controller to retrieve the dataTable
    //
                if(item.listarItemsB(objectParent.getCorte_id()).isEmpty()){
                    this.listaObjetos = item.listarItemA(objectParent.getCorte_id());
                }else{
                    this.listaObjetos = item.listarItemsA(objectParent.getCorte_id());
                }

    }

    public Parent getCorte() {
        return corte;
    }

    public void setCorte(Parent parent) {
        this.parent = parent;
    }

我如何從處理一個控制器 X 的 xhtml 視圖發送數據以查看數據,發送到另一個使用另一個控制器 Y 的 xhtml 頁面,並在使用 Y 控制器的另一個頁面中顯示發送的數據的數據。

如果您需要在兩個.xhtml視圖之間共享一些數據,您可以將數據放在@SessionScoped控制器中,該控制器在同一瀏覽器會話中的兩個視圖之間具有相同的狀態,並且對兩個視圖都可見。 只需從page1.xhtml提交您的數據到@SessionScoped控制器並從page2.xhtml訪問它

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM