我正在使用PrimeFaces 3.5,我正在实现DataTable - ContextMenu组件.但是,我想通过单击行中的一个单元格来删除一行.
我的JSF页面:
<h:form id="form">
<p:growl id="messages" showDetail="true" />
<p:contextMenu for="productID" widgetVar="cMenu">
<p:menuitem value="Edit Cell" icon="ui-icon-search"
onclick="productService.showCellEditor();return false;" />
<p:menuitem value="Delete Row" icon="ui-icon-search"
onclick="productService.delete();return false;" />
</p:contextMenu>
<p:dataTable id="productID" var="product"
value="#{productService.getListOrderedByDate()}"
editable="true" editMode="cell" widgetVar="productTable"
paginator="true" rows="10"
paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
rowsPerPageTemplate="5,10,15">
<f:facet name="header"> Airbnb Product </f:facet>
<p:ajax event="cellEdit"
listener="#{productService.onCellEdit}"
update=":form:messages" />
<p:column headerText="id" style="width:15%">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{product.id}" />
</f:facet>
<f:facet name="input">
<p:inputText value="#{product.id}" style="width:96%" />
</f:facet>
</p:cellEditor>
...
</p:column>
</p:dataTable>
</h:form>
Run Code Online (Sandbox Code Playgroud)
我在我的服务中实现了一个应该有效的删除方法.但是,当我在上下文菜单中按下删除按钮时没有任何反应.问题的原因是什么?
UPDATE
我在PF页面上做到了这样:
public void delete() {
log.info("Deleting data:");
log.info(selectedRow.getId());
// productDAO.delete(selectedRow);
}
Run Code Online (Sandbox Code Playgroud)
和我的数据表:
<p:contextMenu for="productID" widgetVar="cMenu">
<p:menuitem value="Edit Cell" icon="ui-icon-search"
onclick="productService.showCellEditor();return false;" />
<p:menuitem value="Delete" update="productID" icon="ui-icon-close"
actionListener="#{productService.delete}" />
</p:contextMenu>
<p:dataTable id="productID" var="product"
value="#{productService.getListOrderedByDate()}"
editable="true" editMode="cell" widgetVar="productTable"
paginator="true" rows="10"
paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
rowsPerPageTemplate="5,10,15"
selection="#{productService.selectedRow}" selectionMode="single" rowKey="#{product.id}">
Run Code Online (Sandbox Code Playgroud)
但是,当我想从选定的行中获取ID时,我会得到一个NullPointerException.我非常感谢你的回答!!
这是使用上下文菜单删除行的一种方法...
<p:menuitem value="Delete" update="productID" icon="ui-icon-close" action="#{productService.delete}"/>
Run Code Online (Sandbox Code Playgroud)
添加到您的表:
<p:dataTable selection="#{productService.selectedRow}" selectionMode="single"....
Run Code Online (Sandbox Code Playgroud)
在你的豆子里
public void delete() {
carsSmall.remove(selectedRow);
}
//declare selectedRow variable + getter/setter
Run Code Online (Sandbox Code Playgroud)
从primefaces展示中获取它:DataTable - ContextMenu
| 归档时间: |
|
| 查看次数: |
29620 次 |
| 最近记录: |