7 Replies Latest reply on Jun 27, 2011 6:24 AM by atmohsin

    filter by is not working after opening rich:modalPanel

    atmohsin

      Hi,

       

       

      I have rich datatable in xhtml page

       

      <a4j:form id="dataform" binding="#{itemBean.form}">

      <rich:dataTable id="dataTable" binding="#{itemBean.dataTable}"

                              border="1" width="100%" value="#{itemBean.dataLists}" var="item"

                              rows="#{itemBean.pageSize}" rendered="#{itemBean.dataListSize>0}"

                              rowClasses="row1, row2">

          

      <rich:column width="20%" filterBy="#{item.itemName}" filterEvent="onkeyup">

       

                                  <h:outputText value="#{item.itemName}" />

                              </rich:column>

      </rich:dataTable>

      </a4j:form>

       

       

      In the page page i have modal panel

       

      <rich:modalPanel id="itemAddModal" style="background-color: #F2EAE9"

                      autosized="true" width="900"

                      onshow="document.getElementById('itemForm:name').focus();">               

                             <f:facet name="controls">    

      <a4j:form id="itemForm" binding="#{itemForm.form}"

                              ajaxSubmit="true">

          

      <a4j:commandButton id="cancel" value="#{msg.cancel}"

                                      onclick="Richfaces.hideModalPanel('itemAddModal');"

                                      reRender="dataTablePanel" ajaxSingle="true">

                                  </a4j:commandButton>

      </a4j:form>

                  </rich:modalPanel>

       

       

      Normally filter by is working fine.

       

      But when i open ModalPanle and close it then i do the filter, it is not working. If i remove the form from model panel then it works in this scenario.

      I need the form to submit the values.

       

      If any body has any information, plesae let me know.

       

      Thanks

      Mohsin

        • 1. Re: filter by is not working after opening rich:modalPanel
          jgomezp

          You must put you modalPanel outside of any form, thus you can add a form inside your modalpanel

          • 2. Re: filter by is not working after opening rich:modalPanel
            atmohsin

            Could you please give some more information

            • 3. Re: filter by is not working after opening rich:modalPanel
              atmohsin

              When i put rich:dataTable in a4j:outputPanel it is working fine like below

               

               

              <a4j:outputPanel id="dataTableOutputPanelId" ajaxRendered="true">

              <rich:dataTable id="dataTable" binding="#{itemBean.dataTable}"

              border="1" width="100%" value="#{itemBean.dataLists}" var="item"

              rows="#{itemBean.pageSize}" rendered="#{itemBean.dataListSize>0}"

              rowClasses="row1, row2">

              </rich:dataTable>

              </a4j:outputPanel>

               

              But it has one problem. after rendering the dataTableOutputPanelId the cursor focus get lost and user again has to select the filter by.

              • 4. Re: filter by is not working after opening rich:modalPanel
                ilya_shaikovsky

                http://livedemo.exadel.com/richfaces-demo/richfaces/filteringFeature.jsf?tab=ex-usage&cid=1507060 - there we shown the workaround to avoid focus loss.

                 

                Can't say more on original problem as not enough info. why you need binding on form? which scope itemBean has? If session - will be problems with sessions scoped binding in JSF, if request - rendered will not works as expected.. why you using ajaxSubmit on modapPanel form?.. what geting rendered from modalp panel button? And so on..

                • 5. Re: filter by is not working after opening rich:modalPanel
                  atmohsin

                  Hi Ilya

                   

                  Thanks for the replay.

                   

                  I did what you have suggested. Filter is working fine.

                   

                  We have datatable which has list of records, there is edit link in each record which opens modal panel to edit that record.

                  When i edit the record the data table is not getting rendered if i give reRender  the id of datatable.

                  If i put the data in side rich:panel and reRender panel id then the rich:dataTable getting reRender. then filter wont work.

                   

                   

                  <a4j:form id="dataform">                       

                                      <rich:message for="dataform" infoClass="successMessageStyle"

                                          errorClass="errorMessageStyle" />

                                      <rich:message for="itemForm" infoClass="successMessageStyle"

                                          errorClass="errorMessageStyle" />       

                                                              

                                      <rich:dataTable id="dataTable" binding="#{itemBean.dataTable}"

                                          border="1" width="100%" value="#{itemBean.dataLists}" var="item"

                                          rows="#{itemBean.pageSize}" rendered="#{itemBean.dataListSize>0}"

                                          rowClasses="row1, row2">                       

                                          <f:facet name="header">

                                              <rich:columnGroup>

                                                  <rich:column>

                                                  </rich:column>

                                                  <rich:column>

                                                      <h:commandLink actionListener="#{itemBean.sortDataList}">

                                                          <f:attribute name="sortField" value="getItemCode" />

                                                          <h:outputText value="#{msg.itemcode}" styleClass="sortableColumnStyle"/>

                                                          <h:outputText value="&#0160;&#9650;" escape="false" styleClass="sortableColumnStyle"

                                                              rendered="#{!itemBean.sortAscending}" />

                                                          <h:outputText value="&#0160;&#9660;" escape="false" styleClass="sortableColumnStyle"

                                                              rendered="#{itemBean.sortAscending}" />

                                                      </h:commandLink>

                   

                                                  </rich:column>

                   

                                                  <rich:column>

                                                      <h:commandLink actionListener="#{itemBean.sortDataList}">

                                                          <f:attribute name="sortField" value="getItemName" />

                                                          <h:outputText value="#{msg.itemname}" styleClass="sortableColumnStyle"/>

                                                          <h:outputText value="&#0160;&#9650;" escape="false" styleClass="sortableColumnStyle"

                                                              rendered="#{!itemBean.sortAscending}" />

                                                          <h:outputText value="&#0160;&#9660;" escape="false" styleClass="sortableColumnStyle"

                                                              rendered="#{itemBean.sortAscending}" />

                                                      </h:commandLink>

                   

                                                  </rich:column>

                                                 

                                                  <rich:column>

                                                      <h:commandLink actionListener="#{itemBean.sortDataList}">

                                                          <f:attribute name="sortField" value="itemCategory.getType" />

                                                          <h:outputText value="#{msg.type}" styleClass="sortableColumnStyle"/>

                                                          <h:outputText value="&#0160;&#9650;" escape="false" styleClass="sortableColumnStyle"

                                                              rendered="#{!itemBean.sortAscending}" />

                                                          <h:outputText value="&#0160;&#9660;" escape="false" styleClass="sortableColumnStyle"

                                                              rendered="#{itemBean.sortAscending}" />

                                                      </h:commandLink>

                   

                                                  </rich:column>

                                                 

                                                  <rich:column>

                                                      <h:outputText value="#{msg.description}" />

                                                  </rich:column>

                   

                                                  <rich:column>

                   

                                                      <h:commandLink actionListener="#{itemBean.sortDataList}">

                                                          <f:attribute name="sortField"

                                                              value="itemCategory.getCategoryName" />

                                                          <h:outputText value="#{msg.category}" styleClass="sortableColumnStyle"/>

                                                          <h:outputText value="&#0160;&#9650;" escape="false" styleClass="sortableColumnStyle"

                                                              rendered="#{!itemBean.sortAscending}" />

                                                          <h:outputText value="&#0160;&#9660;" escape="false"

                                                              styleClass="sortableColumnStyle"

                                                              rendered="#{itemBean.sortAscending}" />

                                                      </h:commandLink>

                                                  </rich:column>

                                                  <rich:column rendered="#{loginForm.roleId==1 || loginForm.roleId==6}">

                                                      <h:outputText value="#{msg.edit}" />

                                                     

                                                  </rich:column>

                                                  <rich:column rendered="#{loginForm.roleId==4}">

                                                      <h:outputText value="#{msg.view}" />

                                                     

                                                  </rich:column>

                                                 

                                                  <rich:column rendered="#{loginForm.roleId==5}">

                                                      <h:outputText value="#{msg.view}" />

                                                  </rich:column>

                   

                                              </rich:columnGroup>

                                          </f:facet>

                                          <rich:column width="5%">

                                              <f:facet name="header">

                                              </f:facet>

                                              <h:selectBooleanCheckbox type="checkbox" value="#{item.selected}" />

                                          </rich:column>

                   

                                          <rich:column width="10%">

                   

                                              <h:outputText value="#{item.itemCode}" />

                                          </rich:column>

                   

                                          <rich:column width="20%" filterBy="#{item.itemName}" filterEvent="onkeyup">

                                              <h:outputText value="#{item.itemName}" />

                                          </rich:column>

                                         

                                          <rich:column width="10%" align="center" filterBy="#{item.itemCategory.type}" filterEvent="onkeyup">

                                              <h:outputText value="#{msg.material}" rendered="#{item.itemCategory.type == 'M'}" />

                                              <h:outputText value="#{msg.product}" rendered="#{item.itemCategory.type == 'P'}" />

                                          </rich:column>

                   

                                          <rich:column width="30%" >

                   

                                              <h:outputText value="#{item.description}" />

                                          </rich:column>

                   

                                      <rich:column width="20%" filterBy="#{item.itemCategory.categoryName}" filterEvent="onkeyup">

                   

                                              <h:outputText value="#{item.itemCategory.categoryName}" />

                                          </rich:column>

                   

                                          <rich:column width="5%" align="center" rendered="#{(loginForm.roleId==1) || (loginForm.roleId==6)}">

                                              <a4j:commandLink id="editlink" action="#{itemForm.loadItem}"

                                                  reRender="itemModalForm"

                                                  oncomplete="Richfaces.showModalPanel('itemAddModal');">

                                                  <h:graphicImage value="/images/Edit_Button.gif" alt="Edit"

                                                      styleClass="imageStyle" />

                                                  <f:setPropertyActionListener target="#{itemForm.updatedId}"

                                                      value="#{item.id}" />

                                              </a4j:commandLink>

                                              <rich:toolTip for="editlink" value="Edit" />

                                          </rich:column>                                                                       

                                                                 

                                      </rich:dataTable>

                   

                              <rich:modalPanel id="itemAddModal" style="background-color: #F2EAE9"

                                  autosized="true" width="900"

                                  onshow="document.getElementById('itemForm:name').focus();">               

                                         <f:facet name="controls">

                                          <h:panelGroup>

                                              <h:graphicImage value="../../images/close.png" styleClass="hidelink" id="hidelink"/>

                                              <rich:componentControl for="itemAddModal" attachTo="hidelink" operation="hide" event="onclick"/>

                                          </h:panelGroup>

                                      </f:facet>

                                  <rich:panel id="itemModalForm" style="background-color:#F2EAE9">

                                  <f:facet name="header">

                                          #{itemForm.formHeader}

                                         </f:facet>

                                      <a4j:form id="itemForm" binding="#{itemForm.form}"

                                          ajaxSubmit="true">

                                          <h:inputHidden id="id" value="#{itemForm.item.id}" />

                                          <h:inputHidden id="itemCode" value="#{itemForm.item.itemCode}" />

                                          <fieldset><h:panelGrid columns="6">

                                             

                                              <h:outputLabel for="name" value="#{msg.itemname}"

                                                  styleClass="outputTextStyle" >

                                                  <span class="required">*</span>

                                              </h:outputLabel>

                                              <h:inputText id="name" size="24" required="true"

                                                  value="#{itemForm.item.itemName}" label="#{msg.itemname}" />

                                              <rich:message for="name" styleClass="errorMessageStyle"/>

                                          </h:panelGrid></fieldset>

                                          <div><h:panelGrid columns="2">

                                              <a4j:commandButton id="save" value="#{msg.save}"

                                                  action="#{itemForm.saveItem}" reRender="dataTable"

                                                  oncomplete="if (#{itemForm.isValidForm}) #{rich:component('itemAddModal')}.hide();">

                                              </a4j:commandButton>

                                              <a4j:commandButton id="cancel" value="#{msg.cancel}"

                                                  onclick="Richfaces.hideModalPanel('itemAddModal');"

                                                  ajaxSingle="true">

                                              </a4j:commandButton>

                                          </h:panelGrid></div>

                                      </a4j:form>

                                  </rich:panel>

                              </rich:modalPanel>

                  • 6. Re: filter by is not working after opening rich:modalPanel
                    atmohsin

                    I am not able to solve this, dont why it is not working,

                     

                    But going with the work around suggested by Ilya

                     

                    Now it is working fine.

                     

                    Thanks a lot

                    Mohsin

                    • 7. Re: filter by is not working after opening rich:modalPanel
                      atmohsin

                      Hi

                       

                      I have one more problem now.

                       

                      After doing the paginatin like next and last, the filter is not working. it display empty table. It is working fine for first and previous button

                       

                      <rich:dataTable id="dataTable" binding="#{itemBean.dataTable}"

                                              border="1" width="100%" value="#{itemBean.dataLists}" var="item"

                                              rows="#{itemBean.pageSize}" rendered="#{itemBean.dataListSize>0}"

                                              rowClasses="row1, row2">

                       

                      <rich:column width="20%" filterMethod="#{itemBean.filterItemName}">

                                                  <f:facet name="header">

                                                      <h:inputText value="#{itemBean.filterItemNameValue}" id="itemNameId">

                                                          <a4j:support event="onkeyup"

                                                              ignoreDupResponses="true" requestDelay="700"

                                                              oncomplete="setCaretToEnd(event);"

                                                              />

                                                      </h:inputText>

                                                  </f:facet>

                                                  <h:outputText value="#{item.itemName}" />

                                              </rich:column>

                       

                      <f:facet name="footer">

                                                  <h:panelGroup>

                                                      <a4j:commandButton value="#{msg.first}"

                                                          action="#{itemBean.pageFirst}"

                                                          disabled="#{itemBean.dataTable.first == 0}"

                                                          reRender="dataTablePanel" />

                                                      <a4j:commandButton value="#{msg.prev}"

                                                          action="#{itemBean.pagePrevious}"

                                                          disabled="#{itemBean.dataTable.first == 0}"

                                                          reRender="dataTablePanel" />

                                                      <a4j:commandButton value="#{msg.next}"

                                                          action="#{itemBean.pageNext}"

                                                          disabled="#{itemBean.dataTable.first + itemBean.dataTable.rows>=itemBean.dataTable.rowCount}"

                                                          reRender="dataTablePanel" />

                                                      <a4j:commandButton value="#{msg.last}"

                                                          action="#{itemBean.pageLast}"

                                                          disabled="#{itemBean.dataTable.first +itemBean.dataTable.rows>=itemBean.dataTable.rowCount}"

                                                          reRender="dataTablePanel" />

                                                      <h:outputText

                                                          value="Page: #{itemBean.currentPage} / #{itemBean.totalPages}" />

                                                      <rich:spacer width="10" />

                                                      <h:outputText

                                                          value="#{msg.total} #{itemBean.totalNumberOfRecords}" />

                                                  </h:panelGroup>

                                              </f:facet>

                                          </rich:dataTable>

                       

                       

                      Backing Bean methods

                       

                      private HtmlDataTable dataTable;

                       

                      public void pageFirst() {

                              dataTable.setFirst(0);

                          }

                       

                          /**

                           * set the previous page

                           */

                          public void pagePrevious() {

                              dataTable.setFirst(dataTable.getFirst() - dataTable.getRows());

                          }

                       

                          /**

                           * set the next page

                           */

                          public void pageNext() {

                              dataTable.setFirst(dataTable.getFirst() + dataTable.getRows());

                          }

                       

                          /**

                           * set the last page of to the list

                           */

                          public void pageLast() {

                              int count = dataTable.getRowCount();

                              int rows = dataTable.getRows();

                              dataTable.setFirst(count - ((count % rows != 0) ? count % rows : rows));

                          }

                       

                       

                      if any one has information please let me know

                       

                      Thanks

                      Mohsin