Hi! I'm current using the displaytag together with the springframework in a project. It works great and I'm quite happy with it. :)
Now I'm starting to use the new conversion service introduced in Spring 3. It basically supports annotations on you model properties to define the formatting. This looks like this for example: @NumberFormat(pattern = "#.###,00") private double price; To get this to work you need the model object and the property name. This is only possible in the TableDecorator. Unfortunately Displaytag uses a pattern where it expects the TableDecorator to implement a getter method for every property. This is unnecessary with the conversion service. Fortunately the TabelDecorator defines an evaluate method, which can do the trick. Here is what I've changed in the displaytag source code to make this work: 1. The evaluate method has to be made public (currently protected). 2. The logic in the getValue Method in the Column class has to be extended: // 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) { // keep the same functionality. Check for getter method if (this.row.getParentTable().getTableDecorator(). hasGetterFor(this.header.getBeanPropertyName())) { object = LookupUtil.getBeanProperty( this.row.getParentTable().getTableDecorator(), this.header.getBeanPropertyName()); } else { // NEW: call the evaluate function // it basically does the same in the standard // implementation as the else block below // object = this.row.getParentTable(). getTableDecorator().evaluate( this.header.getBeanPropertyName()); } } else { // else check underlining object object = LookupUtil.getBeanProperty(this.row.getObject(), this.header.getBeanPropertyName()); } } This is it. Now you can write your own Spring-aware TableDecorator which looks like this: @Component("tableDecorator") public class ConversionServiceAwareDecorator extends TableDecorator { @Autowired private ConversionService conversionService; private TypeDescriptor stringTypeDescriptor = TypeDescriptor.valueOf(String.class); @Override public Object evaluate(String propertyName) { try { Object model = getCurrentRowObject(); TypeDescriptor fromTd = new TypeDescriptor( model.getClass().getDeclaredField(propertyName)); Method getter = PropertyUtils.getPropertyDescriptor( model, propertyName).getReadMethod(); return (String) conversionService.convert( getter.invoke(model, (Object[]) null), fromTd, stringTypeDescriptor); } catch (Exception e) { // throw runtimeexception or return null throw new RuntimeException(e); } } } Of course you also need an own DecoratorFactory Implementation with gets the TableDecorator from the Spring ApplicationContext. So my question is: could somebody with commit rights please implement the suggested modification? I'm sending a patch together with this mail. And the other question: when can we expect a new displaytag version? ;) Thanks. Adrian.
displaytag.patch
Description: Binary data
------------------------------------------------------------------------------ Download Intel® Parallel Studio Eval Try the new software tools for yourself. Speed compiling, find bugs proactively, and fine-tune applications for parallel performance. See why Intel Parallel Studio got high marks during beta. http://p.sf.net/sfu/intel-sw-dev
_______________________________________________ displaytag-user mailing list displaytag-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/displaytag-user