#1272 closed enhancement (fixed)
Add support for using Formatters to SimpleExporter (aka. table exporter)
Reported by: | Nicklas Nordborg | Owned by: | Nicklas Nordborg |
---|---|---|---|
Priority: | critical | Milestone: | BASE 2.12 |
Component: | web | Version: | |
Keywords: | Cc: |
Description
The typical use case for a Formatter is to format a raw value into a nice displayable value. It is currently used on several list pages to format dates and numbers and to add color-coding to some values. A formatter can also be used as a value-converter that convert between units.
Currently, we have a problem with the SimpleExporter in that it is limited to output the raw values only. This is usually not a problem but, for example, in ticket #1266 there is the problem with different internal and external coordinate system for BASE. It would be nice to have the TableExporter to output A1,B2,C3 etc. instead of [0,0],[1,1],[2,2]. This would be possible if we could tell the SimpleExporter to use certain Formatter:s.
I am thinking that this could be done from the index.jsp pages that already passes along the main query for generating the table. Something like this:
ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); final ItemQuery<Sample> query = Sample.getQuery(); cc.configureQuery(query, true); cc.setQuery(query); cc.setObject("formatter.bioWell.row", new WellRowFormatter()); // new code cc.setObject("formatter.bioWell.row", new WellColumnFormatter()); // new code
And then, in the SimpleExporter:
for (String column : columns) { Object possibleFormatter = cc.getObject("formatter." + column); // new code Formatter formatter = possibleFormatter instanceof Formatter ? // new code (Formatter)possibleFormatter : defaultFormatter; // new code ExportedProperty ep = ExportedProperty.parse(dc, column, columnPrefix, annotatable, formatter, sameUnits); exportedProperties.add(ep); properties.add(ep.name); }
The same technique can possible also be used to solve the export of child items discussed in ticket #1128. In that case the formatter of course need to be a lot more complex. Among other things it must contain the query that is needed to load the correct child items.
Change History (6)
comment:1 by , 16 years ago
comment:3 by , 16 years ago
Owner: | changed from | to
---|---|
Priority: | major → critical |
Status: | new → assigned |
comment:4 by , 16 years ago
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
(In [4855]) Fixes #1272: Add support for using Formatters to SimpleExporter (aka. table exporter)
Formatters should be stored in the current ItemContext object as:
ItemContext.setObject("export.formatter.<propertyname>", formatter);
where <propertyname> is the name of the property that are exported. The formatter is cleared after the export and if the same context is used again a new formatter needs to be specified.
Would this also target the issue discussed in ticket:1259?