Title: Melding
Seems like my patch files disappeared, so I'll include them as text in this mail instead:
 
Index: src/java/org/displaytag/model/Row.java
===================================================================
RCS file: /cvsroot/displaytag/displaytag2/src/java/org/displaytag/model/Row.java,v
retrieving revision 1.8
diff -u -r1.8 Row.java
--- src/java/org/displaytag/model/Row.java 29 Feb 2004 09:59:57 -0000 1.8
+++ src/java/org/displaytag/model/Row.java 5 Apr 2004 13:14:41 -0000
@@ -15,7 +15,8 @@
  */
 public class Row
 {
-
+ private boolean decoratSelectedRow = false;
+ public void setDecoratSelectedRow(boolean decoratSelectedRow) {this.decoratSelectedRow = decoratSelectedRow;}
     /**
      * Object holding values for the current row.
      */
@@ -144,7 +145,7 @@
                 + " "
                 + TagConstants.ATTRIBUTE_CLASS
                 + "=\""
-                + css
+                + (decoratSelectedRow ? "selectedRow" : css)
                 + "\""
                 + TagConstants.TAG_CLOSE;
         }
 
 
 
Index: src/java/org/displaytag/model/Column.java
===================================================================
RCS file: /cvsroot/displaytag/displaytag2/src/java/org/displaytag/model/Column.java,v
retrieving revision 1.8
diff -u -r1.8 Column.java
--- src/java/org/displaytag/model/Column.java 29 Feb 2004 09:59:57 -0000 1.8
+++ src/java/org/displaytag/model/Column.java 5 Apr 2004 12:49:57 -0000
@@ -24,6 +24,11 @@
 public class Column
 {
 
+ /*
+  * Stylesheet style to use for this row.
+  */
+ private String style;

     /**
      * Row this column belongs to.
      */
@@ -120,7 +125,9 @@
     public String getOpenTag() throws ObjectLookupException, DecoratorException
     {
         this.stringValue = createChoppedAndLinkedValue();
-
+        if (style!=null) {
+         return "<TD class='" + style + "'>";
+        }
         return HtmlTagUtil.createOpenTagString(TagConstants.TAGNAME_COLUMN, this.htmlAttributes);
     }
 
@@ -272,4 +279,11 @@
             .append("stringValue", this.stringValue)
             .toString();
     }
+   
+ /**
+  * @param pStyle The style to use for this td.
+  */
+ public void setStyle(String pStyle) {
+  this.style = pStyle;
+ }
 }
 
 
 
Index: src/java/org/displaytag/tags/TableTag.java
===================================================================
RCS file: /cvsroot/displaytag/displaytag2/src/java/org/displaytag/tags/TableTag.java,v
retrieving revision 1.52
diff -u -r1.52 TableTag.java
--- src/java/org/displaytag/tags/TableTag.java 11 Mar 2004 22:18:57 -0000 1.52
+++ src/java/org/displaytag/tags/TableTag.java 5 Apr 2004 13:13:13 -0000
@@ -153,6 +153,7 @@
      * table decorator class name - cleaned in doEndTag().
      */
     private String decoratorName;
+    private String decoratorDdName;
 
     /**
      * page size - reset in doEndTag().
@@ -418,7 +419,18 @@
      */
     public void setDecorator(String decorator)
     {
-        this.decoratorName = decorator;
+     String[] d = decorator.split(",");
+     if (d.length == 1) {
+      this.decoratorName = d[0];
+     }
+     if (d.length == 2) {
+      if (!"highlightSelectedRow".equalsIgnoreCase(d[0])) {
+       // This allows us to use a decorator in combination with highlighting of selected row.
+       this.decoratorName = d[0];
+      }
+      this.decoratorDdName = d[1];
+     }
+     else this.decoratorName = decorator;
     }
 
     /**
@@ -1434,11 +1446,15 @@
      */
     private String getTableBody() throws ObjectLookupException, DecoratorException
     {
+        boolean hasDecoratedSelectedRow = false;
+     
         StringBuffer buffer = new StringBuffer();
 
         // Ok, start bouncing through our list...
         RowIterator rowIterator = this.tableModel.getRowIterator();
 
+        String drillDownParam = decoratorDdName + "=" + getPageContext().getRequest().getParameter(decoratorDdName);
+       
         // iterator on rows
         while (rowIterator.hasNext())
         {
@@ -1447,15 +1463,18 @@
             {
                 log.debug("[" + getId() + "] rowIterator.next()=" + row);
             }
-            if (this.tableModel.getTableDecorator() != null)
-            {
-                String stringStartRow = this.tableModel.getTableDecorator().startRow();
-                if (stringStartRow != null)
-                {
-                    buffer.append(stringStartRow);
-                }
-            }
+           
+            ColumnIterator columnIterator = row.getColumnIterator(this.tableModel.getHeaderCellList());
 
+      // Loop through column data to find out if a row should be decorated with 'selectedRow' styleclass
+            boolean currentRowIsSelectedRow = false;
+            if (!hasDecoratedSelectedRow) {
+             currentRowIsSelectedRow = decorateRow(drillDownParam, row, columnIterator);
+             if (currentRowIsSelectedRow) {
+              hasDecoratedSelectedRow = true;
+             }
+            }
+           
             // open tr
             buffer.append(row.getOpenTag());
 
@@ -1464,11 +1483,17 @@
             {
                 log.debug("[" + getId() + "] creating ColumnIterator on " + this.tableModel.getHeaderCellList());
             }
-            ColumnIterator columnIterator = row.getColumnIterator(this.tableModel.getHeaderCellList());
+            columnIterator = row.getColumnIterator(this.tableModel.getHeaderCellList());
 
             while (columnIterator.hasNext())
             {
                 Column column = columnIterator.nextColumn();
+                // Set styleclass for <td> tag.
+                if (currentRowIsSelectedRow) {
+                 column.setStyle("selectedRow");
+                } else {
+                 column.setStyle(this.tableModel.getProperties().getCssRow(this.rowNumber));
+                }
 
                 // Get the value to be displayed for the column
                 buffer.append(column.getOpenTag());
@@ -1511,14 +1536,40 @@
 
         if (this.tableModel.getRowListPage().size() == 0)
         {
-            buffer.append("<tr class=\"empty\"><td colspan=\"" + (this.tableModel.getNumberOfColumns()) + "\">"
+         //String clazz = decoratorDdName!=null ? decoratorDdName : "empty";
+         String clazz = "empty";
+            buffer.append("<tr class=\"" + clazz + "\"><td colspan=\"" + (this.tableModel.getNumberOfColumns()) + "\">"
                 + this.properties.getEmptyListMessage() + "</td></tr>");
         }
 
         return buffer.toString();
     }
 
-    /**
+ /*
+  * Loop through column data to find out if row should be decorated with 'selectedRow' styleclass
+  */
+    private boolean decorateRow(String drillDownParam, Row row, ColumnIterator columnIterator) throws ObjectLookupException, DecoratorException {
+  if (drillDownParam!=null) {
+      while (columnIterator.hasNext()) {
+          Column column = columnIterator.nextColumn();
+          column.getOpenTag();// Must be called
+          String value = column.getChoppedAndLinkedValue();
+          if (value.indexOf(drillDownParam)!=-1) {
+           /*int lastPos = value.indexOf(drillDownParam)+drillDownParam.length();
+           System.out.println("###:" + value.charAt(lastPos) + value.charAt(lastPos+1));*/
+        row.setDecoratSelectedRow(true);
+        return true;
+           /*if (lastPos < value.length()) {
+            if (value.charAt(lastPos)=='"') {
+            }
+           }*/
+          }
+      }
+  }
+  return false;
+ }
+
+ /**
      * Generates table footer with links for export commands.
      * @return String
      */
 
 
 
 
...thats about it.
 
 
Knut Erik Ballestad

 
Hi all,
 
I just finished a patch to displaytag that had two objectives:
 - Include functionality that lets me highlight a row where the user has clicked on a link in a row.
 - Add displaytag code regarding to usage of stylesheet, so that the <TR> and <TD> tags output by displaytag includes the styleclass.
   This makes it possible to change cell attributes like font,text color etc of the text displayed in each cell according to the styleheet of 'odd', 'even' and 'selectedRow'.
   Previously you could not set the style of the text in a cell, which quite heavily limited the color difference you could use in the 'even' and 'odd' style classes,
   and even more importantly in the new 'selectedRow' styleclass which is supposed to stand out from the 'odd' and 'even' styles.
 
Because of me having limited time available to complete this, I added the new functionality as a patch to the 'decorator' tag parameter.
The change is backwards compatible, so that it doesn't break existing code - and you can still use this parameter to specify a decorator.
But the tag parameter now accepts a comma-separated input that lets you specify either one of these combinations:
 - decorator="org.yourorg.decorator.YourDecorator" if you want to use the param as before.....
 - decorator="highlightSelectedRow,drilldownByAccountId" if you want to higlight a row that contains a link that the user clicks
   (that contains the request parameter 'drilldownByAccountId') without using a decorator.
 - decorator="org.yourorg.decorator.YourDecorator,requestParameterToUseForHighlighting if you want to use BOTH a decorator and row highlighting.
 
My implementation matches the request parameter value, e.g 'drilldownByAccountId=10023' with the request parameter values found in each column of the table.
If a match is found, the CSS style class of <TR> and <TD> tags of this row is set to 'selectedRow'
 
Current implementation limitations and wanted future functionality/implementation:
 - If more than one row has a link with the same request paramater + value, only the first occurence is marked as a 'selectedRow'
 - The current implementation can only handle request parameter matching for one column at the time,
    but it should be fairly easy to expand this - now it meets MY, needs so I stopped there....
 - This functionality should probably rather have it's own parameter, instead of patching the decorator="xx" parameter.
 
Apart from that: have fun playing with row highlighting ;-)
(patches included: Row.java, Column.java, TableTag.java)
 
 
Knut Erik Ballestad

Reply via email to