【发布时间】:2013-11-29 09:52:23
【问题描述】:
以下代码是关于一个表的,我可以在其中添加(commandButton)或删除(commandLink)行。两个按钮都在工作并调用相应的 bean 方法。但是,虽然每次单击添加按钮都会更新表格并立即添加一行,但对于删除按钮,我必须单击它两次才能删除该行。即使第一次没有删除该行,也会调用 bean 方法。我该怎么办?谢谢!
<h:form id="form">
<table>
<tr>
<td>
<h:panelGrid columns="2" width="100%">
<p:dataTable id="univertitiesTable" value="#{universityBean.universityList}" var="university"
editable="true" editMode="cell" style="align:center;" >
<p:column headerText="Name" style="width:80px" >
<p:inputText value="#{university.name}" style="width:25px;" id="nameField" label="name" />
</p:column>
<p:column headerText="" style="width:20px; ">
<p:commandLink actionListener="#{universityBean.deleteUniversity}" update="univertitiesTable" id="removeButton" ajax="true">
<h:graphicImage value="/resources/icones/delete.gif" />
<f:setPropertyActionListener value="#{university}"
target="#{universityBean.university}" />
</p:commandLink>
</p:column>
</p:dataTable>
<p:commandButton value="+" update="univertitiesTable" id="addButton" ajax="true"
actionListener="#{universityBean.addUniversity}"
styleClass="ui-priority-primary" />
</h:panelGrid>
</td>
</tr>
<tr>
<td colspan="2" align="center">
<h:commandButton id="save" value="Save"
action="#{universityBean.save}" binding="#{save}" />
</td>
</tr>
</table>
</h:form>
【问题讨论】:
-
尝试从commandButton中删除
ajax=true并将process=@this添加到commandButton
标签: jsf-2 primefaces datatable commandlink