1 Reply Latest reply on Jul 25, 2013 9:23 AM by pbaker01

    Remove selected row in scrollabledatatable

    vargjohn

      Hi All,

       

      Can anybody help me if there is any way to remove the selected row in scrollabledatatable. I have a requirement in which i have three rows added to the scrollabledatatable which is an ArrayList in Java. When i remove any selected row in the scrollabledatatable, first row gets removed from list rather than the selected row and the list gets updated with the selected row value meaning when i navigate between rows in the scrollabledatatable the list gets updated with selected row value and all the elements which i added in the list is lost. My application is developed in JBoss Seam and Richfaces.

       

      Suppose i added three elements 'a','b','c' into the list

       

      1. When i remove 'c' from list.

      2. 'a' gets removed and after navigating between rows list gets updated with 'c','c','c' values

       

      Please give a solution to this problem. I am putting some code for reference.

       

      <rich:scrollableDataTable id="eChannelTable" columns="4" width="830px" height="160px" value="#{organisation.eChannels}" var="eChan" selectionMode="single"

       

                                                        <a4j:support event="onRowClick" status="ajaxProgressStatus" reRender="eChannelEditButton,eChannelRemoveButton">

                                                                  <f:setPropertyActionListener value="#{eChan}" target="#{eChannel}" />

                                                        </a4j:support>

       

                                                        <rich:column width="200px" sortExpression="#{eChan.partyRoleContactPurpose.contactMechanismPurpose.name}">

                                                                  <f:facet name="header"><h:outputText value="Channel"/></f:facet>

                                                                  <h:outputText value ="#{eChan.partyRoleContactPurpose.contactMechanismPurpose.name}" />

                                                        </rich:column>

       

                                                        <rich:column width="250px" sortExpression="#{eChan.partyRoleContactPurpose.partyRoleContactMechanism.name}">

                                                                  <f:facet name="header"><h:outputText value="Reference"/></f:facet>

                                                                  <h:outputText value ="#{eChan.partyRoleContactPurpose.partyRoleContactMechanism.name}" />

                                                        </rich:column>

       

                                                        <rich:column width="150px" sortExpression="#{eChan.partyRoleContactPurpose.partyRoleContactMechanism.validFromDate}">

                                                                  <f:facet name="header"><h:outputText value="From"/></f:facet>

                                                                  <h:outputText value ="#{eChan.partyRoleContactPurpose.partyRoleContactMechanism.validFromDate}" />

                                                        </rich:column>

       

                                                        <rich:column width="150px" sortExpression="#{eChan.partyRoleContactPurpose.partyRoleContactMechanism.validToDate}">

                                                                  <f:facet name="header"><h:outputText value="To"/></f:facet>

                                                                  <h:outputText value ="#{eChan.partyRoleContactPurpose.partyRoleContactMechanism.validToDate}" />

                                                        </rich:column>

                                              </rich:scrollableDataTable>

       

                                              <h:panelGrid columns="3">

      <a4j:commandButton id="eChannelAddButton"

                                                                      styleClass="addButton"

                                                                      value="Add"

                                                                      action="#{eChannelHandler.init()}"

                                                                            reRender="eChannelPopup"

                                                                      status="ajaxProgressStatus"

                                                                         ajaxSingle="true"

                                                                      oncomplete="Richfaces.showModalPanel('eChannelPopup')"

                                                                      disabled="#{disabled}" />

       

       

                                                                  <a4j:commandButton id="eChannelEditButton"

                                                                         styleClass="addButton"

                                                                         value="Edit"

                                                                         reRender="eChannelPopup"

                                                                         status="ajaxProgressStatus"

                                                                         ajaxSingle="true"

                                                                      oncomplete="Richfaces.showModalPanel('eChannelPopup')"

                                                                      disabled="#{disabled or empty eChannel.partyRoleContactPurpose.contactMechanismPurpose.code or organisation.eChannels.size() eq 0}" />

       

                                                               <a4j:commandButton id="eChannelRemoveButton"

                                                                         styleClass="remove"

                                                                         value="Remove"

                                                                         ajaxSingle="true"

                                                                         action="#{organisation.eChannels.remove(eChannel)}"

                                                                         reRender="eChannelTable,eChannelEditButton,eChannelRemoveButton"

                                                                         status="ajaxProgressStatus"

                                                                      disabled="#{disabled or empty eChannel.partyRoleContactPurpose.contactMechanismPurpose.code or organisation.eChannels.size() eq 0}"/>

       

                                               </h:panelGrid>

       


      Thanks & Regards,

      John Varghese

        • 1. Re: Remove selected row in scrollabledatatable
          pbaker01

          Hi Joh, Please post your backing been so I can get a better picture.  scrollableDataTable seem to be an older component, I don't see it in release  4.  I had a similiar problem using the extendeddatatable and I added the "selection" attribute to identify what was and was not selected.  It looks like you are using the var attribute to capture the row details. 

           

          <rich:extendedDataTable
                 id="inventoryTable"
                 var="inv"
                 sortMode="single"
                 iterationStatusVar="invIdx"
                 headerClass="noOverflow"
                 rows="#{inventoryItemDataModel.rowsPerPage}"
                 selection="#{inventoryItemDataModel.rowSelections}"
                 onrowdblclick="viewItemJs()"
                 selectionMode="multiple"
                 keepSaved="true"
                 value="#{inventoryItemDataModel}"
                 style="width:1100x;">
                 <f:facet name="noData">
                     <h:outputText
                         styleClass="LblNormal"
                         value="No records found." />
                 </f:facet>
                 <rich:column
                     id="itemID"
                     width="125px"
                     style="text-align: center; vertical-align: middle;"
                     filterExpression="#{inventoryItemDataModel.columnNameMap['itemID']}"
                     filterValue="#{inventoryItemDataModel.filterValues['itemID']}"
                     sortBy="#{inventoryItemDataModel.columnNameMap['itemID']}"
                     sortOrder="#{inventoryItemDataModel.sortOrders['itemID']}">
                     <f:facet name="header">#{lbl.itmIDColHdg}</f:facet>
                     <h:outputText value="#{inv.itemCode}" />
                 </rich:column>
              ...
          </rich:extendedDataTable>
          <!-- Context Menu for table -->
          <rich:contextMenu
               target="inventoryTable"
               mode="client">
               <rich:menuItem
                   label="View"
                   onclick="viewItemJs()"
                   render="popupContent"
                   mode="client"
                   icon="/resources/default/1_0/img/icons/View.gif" />
          </rich:contextMenu>
          
          <!-- Function to display selected item ->
          <a4j:jsFunction
               name="viewItemJs"
               execute="inventoryTable"
               action="#{inventoryController.displayManageInventoryItemFormAction}"></a4j:jsFunction>
          

           

           

          Now the trick for me was the be sure to "execute" the table so the selection details were saved for my action methods.

          Then I use the selecton together with my tableModel to get the details..


          From my backing bean

          /**
               * Open Inventory Type menu option selected
               * 
               * @return
               */
              public String displayManageInventoryItemFormAction() {
                  if (logger.isTraceEnabled()) {
                      logger.trace("Entering: " + this.getClass().getSimpleName() + ".displaySummaryInventoryItemListAction");
                  }
                  if (getInventoryItemDataModel().getRowSelections().size() == 0) {
                      FacesContext.getCurrentInstance().addMessage(
                              null,
                              new FacesMessage(FacesMessage.SEVERITY_INFO, JsfUtils.getInstance().getI18NMessage(
                                      MessageConstants.ERR_NO_SELECTION), null));
                      outcome = InventoryConstants.actionFailed;
                  } else if (getInventoryItemDataModel().getRowSelections().size() > 1) {
                      FacesContext.getCurrentInstance().addMessage(
                              null,
                              new FacesMessage(FacesMessage.SEVERITY_INFO, JsfUtils.getInstance().getI18NMessage(
                                      MessageConstants.ERR_MULTI_SELECTION_NOT_ALLOWED), null));
                      outcome = InventoryConstants.actionFailed;
                  } else {
                      // Get the ID of the selected inventory item.
                      Object holdRowKey = getInventoryItemDataModel().getRowKey();
                      getInventoryItemDataModel().setRowKey(getInventoryItemDataModel().getRowSelections().iterator().next());
                      if (getInventoryItemDataModel().isRowAvailable()) {
                          setInventoryItemId(getInventoryItemDataModel().getRowData().getId());
                          outcome = InventoryConstants.displayManageInventoryItemForm;
                      } else {
                          FacesContext.getCurrentInstance().addMessage(
                                  null,
                                  new FacesMessage(FacesMessage.SEVERITY_INFO, JsfUtils.getInstance().getI18NMessage(
                                          MessageConstants.ERR_INVALID_SELECTION), null));
                          outcome = InventoryConstants.actionFailed;
                      }
                      getInventoryItemDataModel().setRowKey(holdRowKey);
                  }
                  if (logger.isTraceEnabled()) {
                      logger.trace("Exiting: " + this.getClass().getSimpleName()
                              + ".displaySummaryInventoryItemListAction with id set to:" + getInventoryItemId());
                  }
                  return outcome;
          
          
          

           

           

           

          Post your backing bean and maybe it is something easy for you..

           

          Paul