5 Replies Latest reply on Apr 25, 2007 4:55 PM by Gledson Rabelo

    EntityHome, ajax4JSF and Pagination

    Gledson Rabelo Newbie

      Hi,

      I'm using the Seam EntityHome and Ajax4JSF for developing ajax enabled CRUDs with pagination.

      The data table has checkboxs that the user can select to delete many entities.

      When I go to the next page (>), the listPanel is rerendered and the checkboxs should be cleaned for the new entities of current page.

      But when I selected one checkbox and go to the next page, it remains checked in the next page.

      And when I clicked in the Remove button ("Excluir") and I'm in the middle page, the ids of the first are sended for the removeChecked operation.

      My Code is listed below.

      Please, Could somebody help me?


      
      <a4j:form>
       ...
      
       <a4j:outputPanel id="listPanel" ajaxRendered="true" layout="block">
      
       <!-- search results -->
      
       <rich:dataTable value="#{questionarios.resultList}" var="questionario"
       id="table">
       <!-- Table Header -->
       <f:facet name="header">
       <rich:columnGroup>
       <rich:column>
       <h:outputText value="Seleção" />
       </rich:column>
       <rich:column>
       <h:outputText value="Id" />
       </rich:column>
       <rich:column>
       <a4j:commandLink value="-" reRender="listPanel">
       <f:param name="querySorting" value="descricao" />
       </a4j:commandLink>
       <h:outputText value="Descrição" />
       </rich:column>
       <rich:column>
       <a4j:commandLink value="-" reRender="listPanel">
       <f:param name="querySorting" value="exercicio" />
       </a4j:commandLink>
       <h:outputText value="Exercício" />
       </rich:column>
       </rich:columnGroup>
       </f:facet>
       <!-- Table Rows -->
       <rich:column>
       <h:selectBooleanCheckbox value="#{questionarioHome.selection[questionario.idQuestionario]}"/>
       </rich:column>
       <rich:column>
       <h:outputText value="#{questionario.idQuestionario}" />
       </rich:column>
       <rich:column>
       <s:link view="/viewQuestionario.xhtml" value="#{questionario.descricao}">
       <f:param name="questionarioId" value="#{questionario.idQuestionario}" />
       </s:link>
       </rich:column>
       <rich:column>
       <h:outputText value="#{questionario.exercicio}" />
       </rich:column>
       </rich:dataTable>
      
       <h:outputText
       value="Não h&aacute; question&aacute;rios para seram exibidos."
       rendered="#{empty questionarios.resultList}" class="message" />
      
       <div class="tableControl">
      
       <h:outputText value="Total de Registros: ${questionarios.resultCount}" />
      
       <a4j:commandLink value="&lt;&lt;" reRender="listPanel" rendered="#{questionarios.previousExists}">
       <f:param name="firstResult" value="0" />
       <f:param name="querySorting" value="#{questionarios.order}" />
       </a4j:commandLink>
      
       <a4j:commandLink value="&lt;" reRender="listPanel" rendered="#{questionarios.previousExists}">
       <f:param name="firstResult" value="#{questionarios.previousFirstResult}" />
       <f:param name="querySorting" value="#{questionarios.order}" />
       </a4j:commandLink>
      
       <a4j:commandLink value="&gt;" reRender="listPanel" rendered="#{questionarios.nextExists}">
       <f:param name="firstResult" value="#{questionarios.nextFirstResult}" />
       <f:param name="querySorting" value="#{questionarios.order}" />
       </a4j:commandLink>
      
       <a4j:commandLink value="&gt;&gt;" reRender="listPanel" rendered="#{questionarios.nextExists}">
       <f:param name="firstResult" value="#{questionarios.lastFirstResult}" />
       <f:param name="querySorting" value="#{questionarios.order}" />
       </a4j:commandLink>
       </div>
      
       <div class="actionButtons">
       <a4j:commandLink reRender="listPanel" value="Excluir" action="#{questionarioHome.removeChecked}"/>
       </div>
      
       </a4j:outputPanel>
      </a4j:form>
      
      
      


      
      @Name("questionarioHome")
      public class FramexEntityHome<E> extends EntityHome<E> {
      
       private static final long serialVersionUID = -1322828158520981636L;
      
       @Override
       public Object getId() {
       return super.getId();
       }
      
       Map<Object, Boolean> selection = new HashMap<Object, Boolean>();
      
       public Map<Object, Boolean> getSelection() {
       return selection;
       }
      
       public void setSelection(Map<Object, Boolean> selection) {
       this.selection = selection;
       }
      
       public void removeChecked() {
       System.out.println("CALL REMOVE CHECKED");
       if (selection != null) {
       System.out.println("### SIZE ###" + selection.keySet().size());
       for (Object id : selection.keySet()) {
       System.out.println("---> " + id + ":" + selection.get(id));
       }
       }
       }
      }
      
      



        • 1. Re: EntityHome, ajax4JSF and Pagination
          Pete Muir Master

          Are you in a conversation?

          • 2. Re: EntityHome, ajax4JSF and Pagination
            Gledson Rabelo Newbie

             

            "petemuir" wrote:
            Are you in a conversation?



            I'm using the Default conversation Scope in the questionarioHome.

            But I'm not using a long conversation.







            • 3. Re: EntityHome, ajax4JSF and Pagination
              Pete Muir Master

              I'm not sure, it would definitely be worth asking this on the RichFaces/Ajax4jsf forums as well.

              • 4. Re: EntityHome, ajax4JSF and Pagination
                Gledson Rabelo Newbie

                I replaced all AJAX4JSF tags for non-ajax Tags and it remains with the same behavior.

                The stranger is that the list of dataTable (# {questionarios.resultList}) is loaded before calling the method # {questionarioHome.removeChecked}.

                I am making made a mistake?

                My Non-Ajax Page is Listed below.


                Any help is very appreciated.

                Thanks in Advanced



                
                <?xml version="1.0" encoding="ISO-8859-1"?>
                <!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
                <html xmlns="http://www.w3.org/1999/xhtml"
                 xmlns:ui="http://java.sun.com/jsf/facelets"
                 xmlns:h="http://java.sun.com/jsf/html"
                 xmlns:f="http://java.sun.com/jsf/core"
                 xmlns:s="http://jboss.com/products/seam/taglib"
                 xmlns:rich="http://richfaces.ajax4jsf.org/rich"
                 xmlns:a4j="https://ajax4jsf.dev.java.net/ajax"
                 template="template.xhtml">
                
                <head>
                <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
                <title>Questionario List</title>
                <link href="css/screen.css" rel="stylesheet" type="text/css" />
                <script language="JavaScript" src="js/JSCookMenu.js"
                 type="text/javascript" />
                <script language="JavaScript" src="js/theme.js" />
                <link rel="stylesheet" href="css/theme.css" type="text/css" />
                </head>
                <body>
                <div class="body">
                
                <h1>Questionário - Pesquisa</h1>
                
                
                
                
                <h:form id="searchform">
                
                 <h:messages styleClass="message" />
                
                 <!-- search box -->
                
                 <div class="dialog"><span class="prop"> <span class="name">Descricao
                 :</span> <span class="value"><h:inputText
                 value="#{questionarioSearch.descricao}" /></span> </span> <br />
                 <span class="prop"> <span class="name">Exercicio :</span> <span
                 class="value"><h:inputText
                 value="#{questionarioSearch.exercicio}" /></span> </span> <br />
                
                 <div class="actionButtons">
                
                 <s:link view="/searchQuestionario.xhtml" value="Pesquisar" />
                
                 <s:link view="/editQuestionario.xhtml" value="Incluir" /></div>
                 </div>
                
                 <!-- search results -->
                
                 <rich:dataTable value="#{questionarios.resultList}" var="questionario"
                 id="table">
                 <f:facet name="header">
                 <rich:columnGroup>
                 <rich:column>
                 Seleção
                 </rich:column>
                
                 <rich:column>
                 <h:commandLink value="-" >
                 <f:param name="querySorting" value="descricao" />
                 </h:commandLink>
                 <h:outputText value="Descrição" />
                 </rich:column>
                 <rich:column>
                 <h:commandLink value="-" >
                 <f:param name="querySorting" value="exercicio" />
                 </h:commandLink>
                 <h:outputText value="Exercício" />
                 </rich:column>
                 </rich:columnGroup>
                 </f:facet>
                
                
                 <rich:column>
                 <h:selectBooleanCheckbox value="#{questionarioHome.selection[questionario.idQuestionario]}" />
                 </rich:column>
                
                 <rich:column>
                 <s:link view="/viewQuestionario.xhtml"
                 value="#{questionario.descricao}">
                 <f:param name="questionarioId"
                 value="#{questionario.idQuestionario}" />
                 </s:link>
                 </rich:column>
                
                 <rich:column>
                 <h:outputText value="#{questionario.exercicio}" />
                 </rich:column>
                
                 </rich:dataTable>
                
                 <h:outputText
                 value="Não há questionários para seram exibidos."
                 rendered="#{empty questionarios.resultList}" class="message" />
                
                
                 <div class="tableControl"><h:outputText
                 value="Total de Registros: ${questionarios.resultCount}" />
                
                 <!-- Pagination Buttons -->
                
                 <h:commandLink
                 value="<<"
                 rendered="#{questionarios.previousExists}">
                 <f:param name="firstResult" value="0" />
                 <f:param name="querySorting" value="#{questionarios.order}" />
                 </h:commandLink>
                
                 <h:commandLink value="<"
                 rendered="#{questionarios.previousExists}">
                 <f:param name="firstResult"
                 value="#{questionarios.previousFirstResult}" />
                 <f:param name="querySorting" value="#{questionarios.order}" />
                 </h:commandLink>
                
                 <h:commandLink value=">"
                 rendered="#{questionarios.nextExists}">
                 <f:param name="firstResult" value="#{questionarios.nextFirstResult}" />
                 <f:param name="querySorting" value="#{questionarios.order}" />
                 </h:commandLink>
                
                 <h:commandLink value=">>"
                 rendered="#{questionarios.nextExists}">
                 <f:param name="firstResult" value="#{questionarios.lastFirstResult}" />
                 <f:param name="querySorting" value="#{questionarios.order}" />
                 </h:commandLink></div>
                
                
                 <div class="actionButtons">
                 <!-- Delete Button -->
                 <h:commandLink action="#{questionarioHome.removeChecked}" value="Excluir" >
                 <f:param name="firstResult" value="0" />
                 <f:param name="querySorting" value="#{questionarios.order}" />
                 </h:commandLink>
                
                 </div>
                
                 </h:form>
                
                </div>
                
                </body>
                </html>
                
                
                
                





                • 5. Re: EntityHome, ajax4JSF and Pagination
                  Gledson Rabelo Newbie

                  I'm debugging and I confirmed the behavior quoted.

                  I added a debug information in getResultList in the EntityQuery, in the HashMap to discovery when the model is updated.

                  The model is updated after the querying of listing.

                  The console prints the information below:

                  20:43:12,562 INFO [STDOUT] Hibernate: select top ? questionar0_.idQuestionario as idQuesti1_49_, questionar0_.exercicio as exercicio49_, questionar0_.descricao as descricao49_, questionar0_.restritoGestor as restrito4_49_, questionar0_.tipoQuestionario_idTipoQuestionario as tipoQues5_49_ from Questionario questionar0_ order by questionar0_.descricao
                  20:43:12,562 INFO [STDOUT] GETTING RESULT LIST
                  20:43:12,562 INFO [STDOUT] CALL GET SELECTION
                  
                  ...
                  
                  20:43:12,734 INFO [STDOUT] Hibernate: select count(*) as col_0_0_ from Questionario questionar0_
                  
                  ....
                  
                  20:43:12,765 INFO [STDOUT] GETTING RESULT LIST
                  20:43:14,656 INFO [STDOUT] PUT 13 - false
                  20:43:14,671 INFO [STDOUT] PUT 14 - false
                  





                  My JSP
                  <body>
                  
                   <div class="body">
                  
                   <h1>Questionário - Pesquisa</h1>
                  
                   <h:form id="searchform">
                  
                   <h:messages styleClass="message" />
                  
                   <!-- search box -->
                  
                   <div class="dialog">
                  
                   <span class="prop">
                  
                   <span class="name">Descricao:</span>
                   <span class="value"><h:inputText value="#{questionarioSearch.descricao}" /></span>
                   </span> <br/>
                  
                   <span class="prop"> <span class="name">Exercicio :</span>
                  
                   <span class="value"><h:inputText value="#{questionarioSearch.exercicio}" /> </span> </span> <br/>
                  
                   <div class="actionButtons">
                  
                   <s:link view="/searchQuestionario.xhtml" value="Pesquisar" />
                  
                   <s:link view="/editQuestionario.xhtml" value="Incluir" /></div>
                   </div>
                  
                   <!-- search results -->
                  
                   <rich:dataTable value="#{questionarios.resultList}" var="questionario" id="table">
                   <f:facet name="header">
                   <rich:columnGroup>
                   <rich:column>
                   Seleção
                   </rich:column>
                   <rich:column>
                   <h:commandLink value="-" >
                   <f:param name="querySorting" value="descricao" />
                   </h:commandLink>
                   <h:outputText value="Descri&ccedil;&atilde;o" />
                   </rich:column>
                   <rich:column>
                   <h:commandLink value="-" >
                   <f:param name="querySorting" value="exercicio" />
                   </h:commandLink>
                   <h:outputText value="Exerc&iacute;cio" />
                   </rich:column>
                   </rich:columnGroup>
                   </f:facet>
                  
                   <rich:column>
                   <h:selectBooleanCheckbox value="#{questionarioHome.selection[questionario.idQuestionario]}" />
                   </rich:column>
                  
                   <rich:column>
                   <s:link view="/viewQuestionario.xhtml" value="#{questionario.descricao}">
                   <f:param name="questionarioId" value="#{questionario.idQuestionario}" />
                   </s:link>
                   </rich:column>
                  
                   <rich:column>
                   <h:outputText value="#{questionario.exercicio}" />
                   </rich:column>
                  
                   </rich:dataTable>
                  
                   <h:outputText
                   value="Não h&aacute; question&aacute;rios para seram exibidos."
                   rendered="#{empty questionarios.resultList}" class="message" />
                  
                  
                   <div class="tableControl">
                  
                   <h:outputText value="Total de Registros: ${questionarios.resultCount}" />
                  
                   <!-- Pagination Buttons -->
                  
                   <h:commandLink
                   value="&lt;&lt;"
                   rendered="#{questionarios.previousExists}">
                   <f:param name="firstResult" value="0" />
                   <f:param name="querySorting" value="#{questionarios.order}" />
                   </h:commandLink>
                  
                   <h:commandLink value="&lt;"
                   rendered="#{questionarios.previousExists}">
                   <f:param name="firstResult"
                   value="#{questionarios.previousFirstResult}" />
                   <f:param name="querySorting" value="#{questionarios.order}" />
                   </h:commandLink>
                  
                   <h:commandLink value="&gt;"
                   rendered="#{questionarios.nextExists}">
                   <f:param name="firstResult" value="#{questionarios.nextFirstResult}" />
                   <f:param name="querySorting" value="#{questionarios.order}" />
                   </h:commandLink>
                  
                   <h:commandLink value="&gt;&gt;"
                   rendered="#{questionarios.nextExists}">
                   <f:param name="firstResult" value="#{questionarios.lastFirstResult}" />
                   <f:param name="querySorting" value="#{questionarios.order}" />
                   </h:commandLink>
                  
                   </div>
                  
                  
                   <div class="actionButtons">
                   <!-- Delete Button -->
                  
                   <h:commandLink action="#{questionarioHome.removeChecked}" value="Excluir" >
                   <f:param name="firstResult" value="0" />
                   <f:param name="querySorting" value="#{questionarios.order}" />
                   </h:commandLink>
                  
                   </div>
                  
                   </h:form>
                  
                  </div>
                  
                  </body>
                  
                  


                  My EntityQuery
                  
                  
                  public class FramexEntityQuery extends EntityQuery {
                  
                   @RequestParameter
                   private String querySorting;
                  
                   @RequestParameter
                   private Integer firstResult;
                  
                   @Override
                   public String getOrder() {
                   if (querySorting != null) {
                   setOrder(querySorting);
                   }
                   return super.getOrder();
                   }
                  
                   @Override
                   public Integer getFirstResult() {
                   if (firstResult != null) {
                   setFirstResult(firstResult);
                   }
                   return super.getFirstResult();
                   }
                  
                   @Override
                   @Transactional
                   public List getResultList() {
                   List list = super.getResultList();
                   System.out.println("GETTING RESULT LIST");
                   return list;
                   }
                  
                  



                  My EntityHome
                  public class FramexEntityHome<E> extends EntityHome<E> {
                  
                   private static final long serialVersionUID = -1322828158520981636L;
                  
                   @Override
                   public Object getId() {
                   return super.getId();
                   }
                  
                   Map<Object, Boolean> selection = new CustomHashMap<Object, Boolean>();
                  
                   //@Out(scope=ScopeType.EVENT)
                   public Map<Object, Boolean> getSelection() {
                  
                   System.out.println("CALL GET SELECTION");
                   for (Object id : selection.keySet()) {
                   System.out.println("---> " + id + ":" + selection.get(id));
                   }
                  
                  
                   return selection;
                   }
                  
                   public void setSelection(Map<Object, Boolean> selection) {
                   System.out.println("CALL SET SELECTION");
                   for (Object id : selection.keySet()) {
                   System.out.println("---> " + id + ":" + selection.get(id));
                   }
                   this.selection = selection;
                   }
                  
                   public void removeChecked() {
                   System.out.println("CALL REMOVE CHECKED");
                   if (selection != null) {
                   System.out.println("### SIZE ###" + selection.keySet().size());
                   for (Object id : selection.keySet()) {
                   System.out.println("---> " + id + ":" + selection.get(id));
                   }
                   }
                   }
                  
                  



                  My CustomHashMap
                  
                  public class CustomHashMap<K,V> extends HashMap<K,V> {
                  
                   @Override
                   public V put(K key, V value) {
                   System.out.println("PUT " + key + " - " + value);
                   return super.put(key, value);
                   }
                  }