我正在使用PrimeFaces 3.5,并且正在实施DataTable - ContextMenu组件。 但是,我想通过单击行中的一个单元格来删除一行。在PrimeFaces数据表中删除行
我的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>
我已经实现了我的服务的删除方法,它应该工作。但是,当我按下我的上下文菜单中的删除按钮时,没有任何反应。问题的原因是什么?
public void delete() {
log.info("Deleting data:");
log.info(selectedRow.getId());
// productDAO.delete(selectedRow);
}
,我的数据表:
UPDATE
我做了它喜欢上了PF页
<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}">
然而,当我想要得到的ID从选择我得到一个NullPointerException
。我真的很感谢你的回答!
它是一个java bean方法'productService.delete();'你试图在你的js'onclick'回调中执行?如果是这样,你不能像这样做 – Daniel 2013-04-22 12:00:42