动态添加一行到素数数据表 [英] Dynamically adding a row to primefaces dataTable

查看:24
本文介绍了动态添加一行到素数数据表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要通过单击按钮添加员工"向我的数据表添加一行.

I need to add a row to my datatable on click of a button - "Add Employee".

数据表显示了对应于 bean 中固定员工列表的记录.

The datatable shows the records corresponding to a fixed list of Employees in the bean.

我正在做的是,单击添加员工"按钮,将员工的空记录添加到 empList.

What I am doing is, on click of the "Add Employee" button , I am adding an empty record of Employee to the empList.

有没有更好的方法来做到这一点?

Is there any better way to do this?

谢谢.

推荐答案

list_Recs 是记录列表,显示在数据表中.

list_Recs is list of records and shown in the data table.

<p:dataTable id="myTable" value="#{myBean.list_Recs}" selectionMode="single" var="myTableVar" selection="#{myBean.currentRec}">
    <p:ajax event="rowSelect" listener="#{myBean.handleRowSelect}" update=":myForm:myPanel"/>
    <p:column>
        <f:facet name="header">
            <h:outputLabel value="Field 1" />
        </f:facet>
        <h:outputLabel value="#{myTableVar.Field1}"/>
     </p:column>

     <p:column>
         <f:facet name="header">
             <h:outputLabel value="Field 2" />
         </f:facet>
         <h:outputLabel value="#{myTableVar.Field2}" />
     </p:column>

     <f:facet name="footer">
         <p:commandButton value="New" action="#{myBean.prepareForInsert}" update=":myForm:myPanel"/>
     </f:facet>
</p:dataTable>

<h:panelGrid id="myPanel" columns="2" >
    <h:outputLabel value="Field 1"/>
    <p:inputText id="fld1" value="#{myBean.newRec.field1}" />
    <h:outputLabel value="Field 2"/>
    <p:inputText id="fld2" value="#{myBean.newRec.field2}" />
    <p:commandButton action="#{myBean.createAction}" value="Submit" update="myGrowl myTable" />
</h:panelGrid>

新建按钮被点击时,在myBean的prepareForInsert例程中创建newRec的一个空实例.以便 myPanel 在字段中填充空白.在提交时,将 newRec 添加到list_Recs 并且由于myTable 上的更新,新记录显示在数据表中.希望这会有所帮助.

When New button is clicked, create an emty instance of newRec in prepareForInsert routine of myBean. So that myPanel is filled with blanks in the fields. On Submit, add the newRec to list_Recs and the new record is diplayed in the data table because of the update on myTable. Hope this helps.

这篇关于动态添加一行到素数数据表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆