[ http://jira.codehaus.org/browse/DISPL-110?page=comments#action_42122 ]
Steve McLeod commented on DISPL-110: ------------------------------------ I have written a patch to solve this issue. My changes are solid and well-tested in a demanding environment (major European bank). However I have neither the time nor inclination to work out how to add my solution to the build. Contact me directly if you want a patched jar to drop into your code at steve (dot) mcleod (at) gmail (dot) com. Ahead are my changes. Please add to the official build if you can - the glory can be all yours. To patch display tag manually, instructions follow. In org.displaytag.model.Row replace the getOpenTag() method with this: /** * Writes the open <tr> tag. * @return String <tr> tag with the appropriate css class attribute */ public String getOpenTag() { // try to get a CSS style from the current tableDecorator. If none exists // then use the default odd/even style system. String css = null; if (this.tableModel.getTableDecorator() != null) { css = this.tableModel.getTableDecorator().getCssClass(this.rowNumber); } if (css == null) { css = this.tableModel.getProperties().getCssRow(this.rowNumber); } if (StringUtils.isNotBlank(css)) { return TagConstants.TAG_OPEN + TagConstants.TAGNAME_ROW + " " //$NON-NLS-1$ + TagConstants.ATTRIBUTE_CLASS + "=\"" //$NON-NLS-1$ + css + "\"" //$NON-NLS-1$ + TagConstants.TAG_CLOSE; } return TagConstants.TAG_OPEN + TagConstants.TAGNAME_ROW + TagConstants.TAG_CLOSE; } In org.displaytag.decorator.TableDecorator add the following new method called getCssClass /** * Called to obtain the name of * the CSS class that should be used in rendering the current table row, for * situations when the default odd/even row system is not * suitable. * * @return the name of the CSS class to use, or null if the * default DisplayTag odd/even row CSS classes should be used on * this row. */ public String getCssClass(int rowNumber) { return null; } Once you have successfully recompiled, you can set classes on an individual row basis using the table decorator feature: eg. <display:table ...lots of attributes here... decorator="MyTableDecorator"/> In a class called MyTableDecorator, which extends TableDecorator, override the new getCssClass method. For example, the following code sets a particular style depending on whether the row has a non-zero value for problem_id. public String getCssClass(int rowNumber) { Row row = (Row) this.getCurrentRowObject(); BigDecimal problemCode = (BigDecimal) row.get("problem_id"); String cssClass = null; if ((problemCode != null) && (problemCode.intValue() != 0)) { cssClass = "problematic_"; cssClass += (rowNumber % 2 == 0) ? "odd" : "even"; } return cssClass; } It would be good to follow the approach I have used to add a getCssId(...) method as well. The approach would be identical. > Ability to highlight selected table row > --------------------------------------- > > Key: DISPL-110 > URL: http://jira.codehaus.org/browse/DISPL-110 > Project: DisplayTag > Type: Wish > Components: Decorators, HTML Generation > Versions: 1.0 RC1 > Reporter: fabrizio giustina > Priority: Minor > Attachments: selected-row-2.jpg, selected-row-2_NEW.jpg > > > ==== > imported from sf tracker > id 810796 > submitted by Bernard Farrell - bernfarr > http://sourceforge.net/support/tracker.php?aid=810796 > ==== > It would be good to provide a means to highlight (via > CSS tags, ideally) the row on the table that has been > selected. > Ideally it would be good if the row selection (by clicking > on a given row) would automatically do this highlighting, > though I think that might be more interaction than would > be needed by most table users. > Also, I could see where developers would like facilities to > select an entire row, entire column, or a specific cell. > === > Date: 2004-03-26 10:52 > Sender: knuterikb > Logged In: YES > user_id=364080 > I suppose this could be implemented in a table decorator by > comparing the request parameters with the > paramId/paramProperty pair, and if they match, you could > change the style for the row in question. > - Maybe this functionality is also so generic that it should be > included in the default tag implementation, e.g. with a > styleClassSelectedRow="myStyleClass" parameter for the tag. > I would also like access to this kind of functionality, and will > look into it if I can spare the time... > === > Date: 2004-04-05 21:11 > Sender: knuterikb > Logged In: YES > user_id=364080 > I have just finished making this functionality as a patch that > we use in a project I am working on. > Ideally this functionality should maybe have a parameter by > it's own, but because I had little time available I had to > integrate it in the decorator parameter. > example: > <display:table .... decorator="highlightSelectedRow,param" > > The patch then matched the request parameters (already > clicked link) with the links that are produced by the cells in > the table. At the first match, the row in question is > highlighted. This means that if multiple rows link to the same > location, and not the first row containing this link is clicked, > the wrong row is selected. This is not a problem in my > application, but could be an issue for others... > ...any way, I could send the patch to anyone interested. -- This message is automatically generated by JIRA. - If you think it was sent incorrectly contact one of the administrators: http://jira.codehaus.org/secure/Administrators.jspa - For more information on JIRA, see: http://www.atlassian.com/software/jira ------------------------------------------------------- SF.Net email is sponsored by: Discover Easy Linux Migration Strategies from IBM. Find simple to follow Roadmaps, straightforward articles, informative Webcasts and more! Get everything you need to get up to speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click _______________________________________________ displaytag-devel mailing list displaytag-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/displaytag-devel