1

这是我的第一篇文章。这个网站和所有参与的人都很棒。谢谢大家。我的问题:我有一个带有对话框的数据表,其中显示了有关所选寄存器的信息。这很好用。但是,如果我尝试使用对话框来修改信息,则该字段不会显示信息。Eclipse Juno 2EE、带 jsf2 的 Primefaces 3.5 和 Tomcat 7.0.39。Java 7.0.07 64 位。

页面 admin.xhtml ....

<h:form id="adminform" preempId="false">
....
<div id="datos">
<p:panel id="panelData" style="height: 100%; width: 100%; margin-left: auto; margin-right: 0; border: none; background: transparent;">
    <ui:include src= "#{adminBean.pageSelected}" />
</p:panel>
</div>
</div>
</h:form>

由 ui:include 加载的页面 adminusers.xhtml

<p:panel id="usuarios" header="USUARIOS" style="background: transparent; border: 1; width: 850px;">
    <p:commandButton value="Nuevo usuario" type="button" onclick="newuser.show()" immediate="true"/>
    <br /><br />
    <p:dataTable id="usertable" var="data" value="#{DTableCustomerBean.datos}" emptyMessage="Sin datos."
                resizableColumns="true" style="text-align: center; align: center; border-radius: 1.6em;"
                selection="#{DTableCustomerBean.selectedCustomer}" selectionMode="single" rowKey="#{data.id}" >
        <p:columns value="#{DTableCustomerBean.columns}" var="column" columnIndexVar="colIndex" 
                        width="#{column.width}">
            <f:facet name="header">#{column.header}</f:facet>
            <h:outputText value="#{data[column.property]}" />
        </p:columns>
        <p:column style="width: 80px;">
            <p:commandLink update=":adminform:showuserform" oncomplete="showuser.show()" immediate="true" 
                            title="Ver" style="margin-right: 10px;">
                <img src="images/info.png" style="width: 20px; height: 20px; border: 0px;"/>
                <f:setPropertyActionListener value="#{data}" target="#{DTableCustomerBean.selectedCustomer}" />
            </p:commandLink>  
            <p:commandLink update=":adminform:edituserform" oncomplete="edituser.show()" immediate="true" 
                            title="Modificar" style="margin-right: 10px;">
                <img src="images/modificar.png" style="width: 20px; height: 20px; border: 0px;"/>
                <f:setPropertyActionListener value="#{data}" target="#{DTableCustomerBean.selectedCustomer}" />
            </p:commandLink>
            <p:commandLink update=":adminform:showuserform" oncomplete="showuser.show()" immediate="true" 
                            title="Borrar" style="margin-right: 10px;">
                <img src="images/delete.png" style="width: 20px; height: 20px; border: 0px;"/>
                <f:setPropertyActionListener value="#{data}" target="#{DTableCustomerBean.selectedCustomer}" />
            </p:commandLink> 
        </p:column>
    </p:dataTable>



<p:dialog id="edituserdlg" header="Modificar datos" widgetVar="edituser" resizable="FALSE" modal="TRUE">
        <h:messages errorClass="errorMessage" infoClass="infoMessage" warnClass="warnMessage" />
        <h:panelGrid id="edituserform" columns="2"  cellpadding="4" cellspacing="4" 
                                                    style="font-size:16px; align: center; margin: 0 auto;" >
            <h:outputText value="Identificador:" />
            <h:outputText value="#{DTableCustomerBean.selectedCustomer.id}" style="font-weight: bold;" />
            <h:outputText value="Nombre:" />
            <p:inputText id="edtnombre" value="#{DTableCustomerBean.selectedCustomer.nombre}" size="20" maxlength="20" 
                                style="font-weight: bold;" />
            <h:outputText value="Apellido:" />
            <h:outputText value="#{DTableCustomerBean.selectedCustomer.apellido}" style="font-weight: bold;" />
            <h:outputText value="Empresa:" />
            <h:outputText value="#{DTableCustomerBean.selectedCustomer.empresa}" style="font-weight: bold;" />
            <h:outputText value="Dirección:" />
            <h:outputText value="#{DTableCustomerBean.selectedCustomer.direccion}" style="font-weight: bold;" />
            <h:outputText value="Rut:" />
            <h:outputText value="#{DTableCustomerBean.selectedCustomer.rut}" style="font-weight: bold;" />
            <h:outputText value="Teléfonos:" />
            <h:outputText value="#{DTableCustomerBean.selectedCustomer.telefonos}" style="font-weight: bold;" />
            <h:outputText value="Usuario:" />
            <h:outputText value="#{DTableCustomerBean.selectedCustomer.usuario}" style="font-weight: bold;" />
            <h:outputText value="Permisos:" />
            <h:outputText value="#{DTableCustomerBean.selectedCustomer.tipoUsuario}" style="font-weight: bold;" />

        </h:panelGrid>
        <p:panel style="margin-left: 30px; display: block; margin: 0 auto; text-align: center; background: transparent; border: 0;">
            <p:commandButton value="Modificar" type="submit" oncomplete="edituser.hide()" update="usuario" />
            <p:commandButton value="Cancelar" type="button" onclick="edituser.hide()" style="margin-left: 30px;"/>
        </p:panel>

……

回豆

@ManagedBean(name="DTableCustomerBean")
// @RequestScoped
// @SessionScoped
@ViewScoped
public class DTableCustomerBean implements Serializable {

    private static final long serialVersionUID = 1L;
    private List<ColumnModel> columns;
    private List<Customer> datos;

    private String columnName;
    private Customer selectedCustomer;

    public DTableCustomerBean() {
        System.out.println("Inicia DTableCustomerBean");
        createColumns();
        addData();
    }



    // Getters and Setters
    public List<ColumnModel> getColumns() {
        return columns;
    }
    public void setColumns(List<ColumnModel> columns) {
        this.columns = columns;
    }
    public List<Customer> getDatos() {
        return datos;
    }
    public void setDatos(List<Customer> datos) {
        this.datos = datos;
    }
    public String getColumnName() {
        return columnName;
    }
    public void setColumnName(String columnName) {
        this.columnName = columnName;
    }
    public Customer getSelectedCustomer() {
        return selectedCustomer;
    }
    public void setSelectedCustomer(Customer selectedCustomer) {
        this.selectedCustomer = selectedCustomer;
    }

    // Fin Getters and Setters


    private void createColumns() {

        System.out.println("DTableCustomerBean createColumns");
        columns = new ArrayList<ColumnModel>();
        columns.add(new ColumnModel("Nombre", "nombre", 100));
        columns.add(new ColumnModel("Apellido", "apellido", 100));
        columns.add(new ColumnModel("Empresa", "empresa", 150));
        columns.add(new ColumnModel("Teléfonos", "telefonos", 150));
        columns.add(new ColumnModel("Usuario", "usuario", 50));
    }



    static public class ColumnModel implements Serializable {
        private static final long serialVersionUID = 1L;

        private String header;
        private String property;
        private int width;

        public ColumnModel(String header, String property, int width) {
            this.header = header;
            this.property = property;
            this.width = width;
        }

        public String getHeader() {
            return header;
        }

        public String getProperty() {
            return property;
        }

        public int getWidth() {
            return width;
        }
    }

    private void addData() {
        UserDAO userdao;

        System.out.println("DTableCustomerBean addData");
        userdao = new UserDAO();
        datos = new ArrayList<Customer>();
        datos = userdao.getAllCustomers();
    }
}

outputText 字段中的数据正确显示。字段 inputText id="edtnombre" 显示为空而不是名称。当然,如果我将 inputText 更改为 outputText 就可以了。

我在谷歌上搜索了一个解决方案,但一无所获。我尝试了不同的想法,但没有奏效。

任何人都可以帮忙吗?谢谢!

4

1 回答 1

1

您将 dataTable 和对话框合二为一form。它行不通。

将您的对话框放在表单之外(但如果您“包含”整个文件,则不能)。

你应该有: - 一个表格里面有dataTable - 第一个表格外面的对话框 - 对话框里面的第二个表格 - 更新属性引用对话框里面的表格和那个表格里面的panelGrid。

于 2013-07-31T13:36:37.437 回答