无法在 Primefaces 的弹出对话框中显示值?

Unable to show values in Pop Up Dialog in Primefaces?

我在 primefaces.I 中的数据表中显示数据有 5 columns.In 最后一列我正在显示编辑和删除 button.On 单击编辑按钮我正在显示对话框弹出窗口但我无法在弹出对话框中显示所选行的数据?

xhtml代码

  <!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:p="http://primefaces.org/ui"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:ui="http://java.sun.com/jsf/facelets">
<h:head>
    <title>Sale Item</title>
    <link rel="stylesheet" href="css/style.css" media="screen"
        type="text/css" />

</h:head>
<h:body>

    <h:form id="form1">
        <p:dataTable var="transection" value="#{trans.getTransections()}"
            paginator="true" rows="10"
            paginatorTemplate="{FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink}"
            paginatorPosition="bottom">
            <p:column headerText="number">
                <h:outputText value="#{transection.number}" />

            </p:column>

            <p:column headerText="Amount" width="200">
                <h:outputText value="#{transection.amount}" />
            </p:column>

            <p:column headerText="Type" width="200">
                <h:outputText value="#{transection.type}" />
            </p:column>

            <p:column headerText="Date/Time" width="200">
                <h:outputText value="#{transection.date}" />
            </p:column>
            <p:column headerText="Action" width="200">
                <h:panelGrid columns="2" border="0">
                    <p:commandButton oncomplete="PF('TransDialog').show()"
                        icon="edit-icon">

                        <f:setPropertyActionListener value="#{transection}"
                            target="#{trans.selectedTrans}" />
                    </p:commandButton>
                    <p:commandLink>
                        <p:graphicImage value="images/delete.png"></p:graphicImage>
                    </p:commandLink>

                </h:panelGrid>

            </p:column>
        </p:dataTable>
        <p:dialog header="Transection Detail" widgetVar="TransDialog"
            resizable="false" width="400" showEffect="explode"
            hideEffect="explode">

            <p:panelGrid id="display" columns="2">
                <h:outputText value="Number:" />
                <p:inputText value="#{trans.selectedTrans.number}"/> 

                <h:outputText value="Amount:" />
                <p:inputText value="#{trans.selectedTrans.amount}"/> 

                <h:outputText value="Type:" />
                <p:inputText value="#{trans.selectedTrans.type}"/> 
            </p:panelGrid>
            <h:panelGrid style="margin:0 auto" columns="1">
            <p:commandButton value="Update" actionListener="#{trans.printcal()}"></p:commandButton>

            </h:panelGrid>
        </p:dialog>

    </h:form>
</h:body>
</html>

ManagedBean代码

   package com.loteria.controller;

import java.util.ArrayList;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.faces.bean.SessionScoped;
import javax.servlet.http.HttpSession;

import com.loteria.beans.Transection;
import com.loteria.model.DBaction;
import com.loteria.util.Util;
@ManagedBean(name="trans")
@SessionScoped
public class TransController {

    ArrayList<Transection> list;
    public ArrayList<Transection> getList() {
        return list;
    }

    public void setList(ArrayList<Transection> list) {
        this.list = list;
    }

    private Transection selectedTrans;

    public Transection getSelectedTrans() {
        return selectedTrans;
    }

    public void setSelectedTrans(Transection selectedTrans) {
        this.selectedTrans = selectedTrans;
    }

    public ArrayList<Transection> getTransections()
    {
    list=new ArrayList<Transection>();
         DBaction db=new DBaction();
         HttpSession session = Util.getSession();
         int uid=Integer.parseInt(session.getAttribute("uid").toString());
         list=db.getAllTransections(uid);
         return list;

    }
    public void printcal()
    {
        System.out.print("princal");
    System.out.print("num is:"+selectedTrans.number);
        System.out.print("amount is"+selectedTrans.amount);
        System.out.print("type is"+selectedTrans.type);

    }
}

bean 类代码

   package com.loteria.beans;

public class Transection
{

    public String amount;
    public String number;
    public String date;
    public String type;
    public String status;
    public String tran_num;

    public String getAmount() {
        return amount;
    }
    public void setAmount(String amount) {
        this.amount = amount;
    }
    public String getNumber() {
        return number;
    }
    public void setNumber(String number) {
        this.number = number;
    }
    public String getDate() {
        return date;
    }
    public void setDate(String date) {
        this.date = date;
    }
    public String getType() {
        return type;
    }
    public void setType(String type) {
        this.type = type;
    }
    public String getStatus() {
        return status;
    }
    public void setStatus(String status) {
        this.status = status;
    }
    public String getTran_num() {
        return tran_num;
    }
    public void setTran_num(String tran_num) {
        this.tran_num = tran_num;
    }



}

我遇到异常

javax.el.PropertyNotFoundException: /User/Records.xhtml @63,57 value="#{trans.selectedTrans.number}": 目标无法到达,'selectedTrans' 返回 null

TechGuy,p:dialog 会在页面加载时呈现,即使用户不会立即看到它(检查 HTML 来源)。这意味着当页面首次呈现时 selectedTrans 为 null,从而导致 PropertyNotFoundException。您应该能够简单地通过初始化支持 bean 中的字段来修复此错误:

private Transection selectedTrans = new Transection();

当你点击按钮时,这将被 setPropertyActionListener 覆盖,这很好。