primefaces数据表对话框,用于数据修改

时间:2013-05-10 16:12:47

标签: jsf-2 primefaces datatable

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

Page 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>

...

Back bean

@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”显示为空,而不是名称。当然,如果我为outputText更改inputText,它可以正常工作。

我已经找到了一个解决方案而没有找到任何结果。我尝试了不同的想法,但没有奏效。

任何人都可以提供帮助?谢谢!

1 个答案:

答案 0 :(得分:1)

您在一个form中拥有dataTable和对话框。它不起作用。

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

你应该: - 表单中包含dataTable的一个表单 - 第一个表单之外的对话框 - 对话框内的第二个表单 - 更新属性,在该窗体中引用对话框和panelGrid中的窗体。