Adding the ability of a TableDecorator to decorate all cells in a row using a single method -------------------------------------------------------------------------------------------
Key: DISPL-302 URL: http://jira.codehaus.org/browse/DISPL-302 Project: DisplayTag Type: Improvement Components: Decorators Versions: 1.1 Reporter: Eric Taix Attachments: Column.java, TableDecorator.java I wanted my TableDecorator to be able to decorate all cells in a row in a single method (adding the same link for all cells) - I did'nt want to override all properties of my bean which is a bad idea because you have to change your decorator each time your add (or remove) a property whereas So i added 2 methods in TableDecorator: public Object startCell(String propertyName) public Object endCell(String propertyName) By default these methods return null in abstract TableDecorator class. And I modified Column model like this : public Object getValue(boolean decorated) throws ObjectLookupException, DecoratorException { TableDecorator tableDecorator = this.row.getParentTable().getTableDecorator(); // Patch (Eric Taix): Get the table decorator if exist and get the start of cell object Object start = ""; if (tableDecorator != null) { if (this.header.getBeanPropertyName() != null) { Object objStart = tableDecorator.startCell(this.header.getBeanPropertyName()); start = (objStart != null ? objStart : ""); } } Object object = null; // a static value has been set? if (this.cell.getStaticValue() != null) { object = this.cell.getStaticValue(); } else if (this.header.getBeanPropertyName() != null) { // if a decorator has been set, and if decorator has a getter for the requested property only, check // decorator if (decorated && this.row.getParentTable().getTableDecorator() != null && this.row.getParentTable().getTableDecorator().hasGetterFor(this.header.getBeanPropertyName())) { object = LookupUtil.getBeanProperty(tableDecorator, this.header .getBeanPropertyName()); } else { // else check underlining object object = LookupUtil.getBeanProperty(this.row.getObject(), this.header.getBeanPropertyName()); } } DisplaytagColumnDecorator[] decorators = this.header.getColumnDecorators(); if (decorated) { for (int j = 0; j < decorators.length; j++) { object = decorators[j].decorate(object, row.getParentTable().getPageContext(), row .getParentTable() .getMedia()); } } if (object == null || "null".equals(object)) //$NON-NLS-1$ { if (!this.header.getShowNulls()) { object = TagConstants.EMPTY_STRING; } } // Patch (Eric Taix) : Get the table decorator if exist and get the end of cell object Object end = ""; if (tableDecorator != null) { if (this.header.getBeanPropertyName() != null) { Object objEnd = tableDecorator.endCell(this.header.getBeanPropertyName()); end = (objEnd != null ? objEnd : ""); } } StringBuffer result = new StringBuffer(); result.append(ObjectUtils.toString(start)); result.append(ObjectUtils.toString(object)); result.append(ObjectUtils.toString(end)); return result; } I think it's a good improvement, because it give us the ability to decorate cells without implementing a getter for each properties. In attached files, you'll find TableDecorator and Colum modified classes. Hope it help community -- 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 ------------------------------------------------------- This SF.Net email is sponsored by xPML, a groundbreaking scripting language that extends applications into web and mobile media. Attend the live webcast and join the prime developer group breaking into this new coding territory! http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642 _______________________________________________ displaytag-devel mailing list displaytag-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/displaytag-devel