0
votes

I have a DataTable from the context menu to delete items DataTable, but when you get to this deleteting, I haven't selected a row as parameter removal method. Works only with a few clicks of the line. I think this is an error in the selection, but I can not find this error. Can somebody help me with this?

<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>
1

1 Answers

0
votes

try this

<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>

and your Managed Bean must have

 private Room selectedRoom;

 public Customer getselectedRoom()
 {
    return selectedRoom;
 }

 public void setselectedRoom(Room selectedCustomer)
 {
    this.selectedCustomer = selectedCustomer;
 }