2013-05-10 65 views
1

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

页admin.xhtml ....由UI加载

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

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

我已经为了解决方案走了过去,什么也没找到。我尝试过不同的想法,但它没有奏效。

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

+0

好吧。我发现了这个问题。在这种情况下,Eclipse Web浏览器无法正常工作。现在它工作正常。在数据表显示在页面中后,似乎需要一段时间才能正常工作。也许是Eclipse的一些问题。 – Augusto 2013-05-21 17:34:46

回答

1

你有你的dataTable和对话框在一个form。它不会工作。

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

你应该有: - 一种形式与形式 内的dataTable - 对话框 内第二种形式 - - 第一种形式 之外对话更新属性指的内部形成对话和panelGrid的这种形式里面。