Menu

Question on finishRow() method

savoym
2007-12-13
2012-10-09
  • savoym

    savoym - 2007-12-13

    As instructed I did a finishRow() method to add an extra line to my row.

    That worked famously, thanks Ed, but in using the alternative.css file that comes with displaytag I am alternating colors on each row and consequently I do not know how I can configure this new row in my finishRow() method to utilize the same tr.odd or tr.even from the alternative.css file in order to maintain that same row feature.

    Any direction or insight would be greatly appreciated.

    Regards.

     
    • savoym

      savoym - 2007-12-14

      I finally found my problem. The issue is two-fold. I was using the listIndex instead of the viewIndex and then in my code I subtracted 1 from the viewIndex and that got my colors alternating properly.

      Thanks

       
    • savoym

      savoym - 2007-12-14

      I forgot to mention that my lead gave me an example that might work however when I tried the following code I encountered some problems.

      The problem I encountered was that the first 3 rows alternate correctly but when I come to the adding the additional row in my finishRow method the 4th row has the first <tr> with the correct color but then the added <tr> from my finishRow() changes color when it should be the same as the 4th row.

      What am I doing wrong? ANY HELP would be greatly appreciated. Regards.

      Here is my code to try and alternate colors within the finishRow() but it is not working:

      /**

       * Called at the end of a row to provide specific data at the end of a row.
       * 
       * @return null is the default implementation
       */
      @Override
      public String finishRow() {
          RequisitionSearchResults reqSearch = (RequisitionSearchResults)getCurrentRowObject();
          if (reqSearch.getItemDescr() == null) {
              return null;
          }else {
              String addClass = null;
              if (this.getListIndex() % 2 == 0) addClass = &quot;even&quot;; else addClass = &quot;odd&quot;;
              return &quot;&lt;tr class=&quot; + addClass + &quot;&gt;&lt;td&gt;&lt;/td&gt;&lt;td colspan='11'&gt;&lt;font size='2'&gt;&quot; + reqSearch.getItemDescr().trim() + &quot;&lt;/font&gt;&lt;/td&gt;&lt;/tr&gt;&quot;;
          }
      }
      
       
      • Ed Webb

        Ed Webb - 2007-12-14

        if (this.getListIndex() % 2 == 0) addClass = "even"; else addClass = "odd";

        If the list is zero based then the fourth row's index will be 3 and displaytag will mark its row even but your extra row will be marked odd.

        Ed!

         
        • savoym

          savoym - 2007-12-14

          Ed, thanks so much for your time in responding. Yes. That is understood.

          My question is: is there anyway to get my colors displayed whereby if I need to add an extra row that it takes on the color that was assigned to the previous row? That is ultimately what I'm needing to have displayed as the added row is additional info for the previous record. You can tell that by the code I originally posted.

          I was just hoping that if displaytag gives us a method to add an additional row on a table that alternates colors then I thought displaytag would provide a method for what I'm trying to do.

          Hope that makes sense.

          Thanks for any additional help on this issue.

          Regards.

           

Log in to post a comment.

MongoDB Logo MongoDB