Menu

External Sorting

Help
2007-03-27
2012-10-09
  • Kristian Magnani

    Hi, all!

    I"m trying to use displaytag with external paging and sorting. I've implemented the PaginatedList interface and trying to display an instance of that implemented class through the following code:

    <display:table requestURI="autoridades.do?sender=btPaginar" name="sessionScope.autoridades" class="padrao" sort="external" pagesize="10" id="a" cellpadding="0" cellspacing="0" >

    &lt;display:column title=&quot;Autoridade&quot; sortable=&quot;true&quot; sortName=&quot;Autoridade&quot; headerClass=&quot;sortable&quot;&gt;
      ${a.nome}
    &lt;/display:column&gt;
    
    &lt;display:column title=&quot;Cargo&quot; sortable=&quot;true&quot; sortName=&quot;Cargo&quot; headerClass=&quot;sortable&quot;&gt;
      ${a.cargo}
    &lt;/display:column&gt;
    
    &lt;display:column title=&quot;Aniversário&quot; sortable=&quot;true&quot; headerClass=&quot;sortable&quot;&gt;
      &lt;c:if test=&quot;${a.diaAniversario &gt; 0 &amp;&amp; a.mesAniversario &gt; 0}&quot;&gt;
        ${a.diaAniversario}/${a.mesAniversario} 
      &lt;/c:if&gt;
    &lt;/display:column&gt;
    
    &lt;display:column class=&quot;largura70&quot; media=&quot;html&quot; title=&quot;&amp;nbsp&quot; headerClass=&quot;sortable&quot;&gt;
    
      &lt;a href=&quot;javascript: go(document.AutoridadesForm,'btVisualizar${a.codigo}')&quot;&gt;&lt;img src=&quot;./images/5a.gif&quot; border=&quot;0&quot; alt=&quot;Visualizar&quot; /&gt;&lt;/a&gt;
    
      &lt;a href=&quot;javascript: go(document.AutoridadesForm,'btEditar${a.codigo}')&quot;&gt;&lt;img src=&quot;./images/editar.gif&quot; border=&quot;0&quot; alt=&quot;Editar&quot; /&gt;&lt;/a&gt;
    
      &lt;a href=&quot;javascript: go(document.AutoridadesForm,'btExcluir${a.codigo}')&quot;&gt;&lt;img src=&quot;./images/cancelar.gif&quot; border=&quot;0&quot; alt=&quot;Excluir&quot; /&gt;&lt;/a&gt;
    
    &lt;/display:column&gt;
    

    The table is displayed and paginations works fine, but sorting does not, as the link when a column head is clicked does not contain "sort=name", rather it shows a "sort=", an empty sort parameter, and without it it's not possible to the application to figure out what criterion should be used to sort the list.

    Does anyone has a sugestion about what is going on?

     
    • Akram BEN AISSI

      Akram BEN AISSI - 2007-04-17

      You shoud add a "sortname" property to your column:
      <display:column headerClass="align-left" titleKey="label.upload.list.file" sortable="true" sortname="ORDER_BY_FILE_NAME">

      Then in you Controller or StrutsAction, do this:

      ParamEncoder paramEncoder = new ParamEncoder("row");
      String sortParameter = paramEncoder.encodeParameterName(TableTagParameters.PARAMETER_SORT);
      String sort = request.getParameter(sortParameter);
      if ("ORDER_BY_FILE_NAME".equals(sort)) {
      ......
      }

       
      • Kristian Magnani

        First of all, thanks for answering. For a while, I thought no one would answer. :-)

        I tried the code you post, and "sort" is still evaluating to null when the column title is clicked. As it can be noted in the code I post, the "sortName" property is already set. The thing, I believe, is that when the mouse cursor is over the column name, the hyperlink shown at the bottom of the browser (i.e., the hyperlink that wil be called itself), the "sort" parameter is empty. It is empty although the "sortName" property is well-defined. In the example I post at the beginning of the thread, the hyperlink of the title of the column "Autoridade" is:

        http://localhost:8080/MyApp/autoridades.do?sort=&sender=btPaginar&content=autoridades.jsp&searchid=&dir=asc

        As it can be saw, "sort" is empty!

        After many tries, I believe it is a bug! But I got no answer from the developers, as well.

        Thanks!

         
        • Akram BEN AISSI

          Akram BEN AISSI - 2007-04-17

          Are you using the latest version of displaytag ?
          try sortname instead of sortName ( who knows :D ).

           
    • Akram BEN AISSI

      Akram BEN AISSI - 2007-04-17

      I your case, replace, ParamEncoder paramEncoder = new ParamEncoder("row"); with
      ParamEncoder paramEncoder = new ParamEncoder("a");

       
    • Kristian Magnani

      Yes, I'm using the last version (although I got some problems with caches when upgrading from 1.0 to 1.1).

      I've also tried "sortname" instead of "sortName", but the tomcat complains about invalid syntax.

       

Log in to post a comment.

MongoDB Logo MongoDB