问题描述
单击"添加员工"按钮后,我需要在数据表中添加一行.
I need to add a row to my datatable on click of a button - "Add Employee".
数据表显示了与bean中固定的Employees列表相对应的记录.
The datatable shows the records corresponding to a fixed list of Employees in the bean.
我正在做的是,单击"添加员工"按钮,将一个空的Employee记录添加到empList.
What I am doing is, on click of the "Add Employee" button , I am adding an empty record of Employee to the empList.
还有更好的方法吗?
谢谢.
推荐答案
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>
单击 New 按钮时,在myBean的prepareForInsert例程中创建newRec的emty实例.因此, myPanel 在字段中填充为空白.在Submit上,将newRec添加到由于 myTable 上的更新,因此list_Recs和新记录已在数据表中显示.希望这会有所帮助.
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 tolist_Recs and the new record is diplayed in the data table because of the update on myTable.Hope this helps.
这篇关于动态地向素数数据表添加一行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!