我从上下文菜单中有一个DataTable来删除DataTable项,但是当你进行这个删除时,我没有选择一行作为参数删除方法。只需点击几行即可工作。我认为这是选择中的错误,但我找不到这个错误。 有人可以帮我吗?
<ui:composition template="../adminTemplates/layout.xhtml"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui">
<ui:define name="content">
<h:form id="form">
<p:growl id="messages" showDetail="true" />
<p:contextMenu for="dataTable">
<p:menuitem value="Delete" update=":form:dataTable"
icon="ui-icon-close" actionListener="#{roomMB.deleteRoom}" />
</p:contextMenu>
<p:dataTable id="dataTable" var="room" styleClass="DataTableRooms"
rowKey="#{room.room_id}" value="#{roomMB.roomList}" paginator="true"
rows="5" selection="#{roomMB.selectedRoom}" selectionMode="single"
paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
rowsPerPageTemplate="5,10,15">
<p:ajax event="rowEdit" listener="#{roomMB.onEdit}"
update=":form:messages, dataTable" />
<p:ajax event="rowEditCancel" listener="#{roomMB.onCancel}"
update=":form:messages" />
<p:column sortBy="number" filterBy="number" id="number"
headerText="Room Number">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{room.number}" />
</f:facet>
<f:facet name="input">
<h:inputText value="#{room.number}" />
</f:facet>
</p:cellEditor>
</p:column>
<p:column sortBy="capacity" filterBy="capacity" id="capacity"
headerText="Room Capacity">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{room.capacity}" />
</f:facet>
<f:facet name="input">
<h:inputText value="#{room.capacity}" />
</f:facet>
</p:cellEditor>
</p:column>
<p:column sortBy="room_description" filterBy="room_description"
id="room_description" headerText="Room Localization">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{room.room_description}" />
</f:facet>
<f:facet name="input">
<h:inputText value="#{room.room_description}" />
</f:facet>
</p:cellEditor>
</p:column>
<p:column style="width:6%" headerText="Edit">
<p:rowEditor />
</p:column>
<f:facet name="footer">
<p:commandButton value="New Room" oncomplete="newRoomDialog.show()"
icon="ui-icon-star" title="Creates new room" />
</f:facet>
</p:dataTable>
</h:form>
<p:dialog header="Create New Room" widgetVar="newRoomDialog"
resizable="false" id="newRoomDlg">
<h:form id="newRoomForm">
<p:panelGrid id="displayNewRoom" columns="2" cellpadding="4"
style="margin:0 auto;">
<h:outputText value="Number :"></h:outputText>
<p:inputText id="name" value="#{roomMB.number}" required="true"
requiredMessage="Please Enter room number" />
<h:outputText value="Capacity :"></h:outputText>
<p:inputText value="#{roomMB.capacity}" required="true"
requiredMessage="Please Enter Capacity" />
<h:outputText value="Room localization :"></h:outputText>
<p:inputText value="#{roomMB.room_description}" required="true"
requiredMessage="Please Enter room Description" />
<f:facet name="footer">
<p:commandButton value="Submit" actionListener="#{roomMB.addRoom}"
oncomplete=" handleSubmitRequest(xhr, status, args, 'newRoomDlg','newRoomForm');"
update=":form:dataTable, :growl" />
<p:commandButton type="reset" value="Reset"></p:commandButton>
</f:facet>
</p:panelGrid>
</h:form>
</p:dialog>
<p:growl id="growl" showDetail="true" life="5000" />
<script type="text/javascript">
function handleSubmitRequest(xhr, status, args, dialogName,
formName) {
dialog = jQuery('#' + dialogName);
if (args.validationFailed) {
dialog.effect("shake", {
times : 3
}, 100);
} else {
clearForm(formName);
newRoomDialog.hide();
roomDialog.hide();
}
}
function clearForm(formName) {
jQuery('#' + formName).each(function() {
this.reset();
});
}
</script>
</ui:define>
</ui:composition>
答案 0 :(得分:0)
试试这个
<p:menuitem value="Delete" update=":form:dataTable"
icon="ui-icon-close" onclick="#{roomMB.deleteRoom()}" immediate="true" >
<f:setPropertyActionListener value="#{room}"
target="#{roomMB.selectedRoom}" />
</p:menuitem>
并且您的Managed Bean必须
private Room selectedRoom;
public Customer getselectedRoom()
{
return selectedRoom;
}
public void setselectedRoom(Room selectedCustomer)
{
this.selectedCustomer = selectedCustomer;
}