You can find the full source code for this website in the Seam package in the directory /examples/wiki. It is licensed under the LGPL.
| Online: | 26 Members of 4511 |
| Forum: Seam Users |
17. Nov 2008, 17:03 CET | Link |
Hello Seam fans!
I tested the new seam excel module. Now I have the problem, that I'm not able to export any Map to an excel spreadsheet...
In the manual according the manual it must be possible:
Basic usage of the worksheet support is simple; it is used like a familiar h:dataTable and you can bind to a List, Set, Map, Array or DataModel.
I tried to get the map via @DataModel, function call and getter/setter, nothing worked for me!
I always get the message: A worksheet's value must be an Iterable, DataModel or Query...
Same problem if I try to export a dataTable (which is builded of a map) directly. Any List work like a charm!
Any hints for me?
Thanks Daniel
My workbook:
------------------------
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:e="http://jboss.com/products/seam/excel"
xmlns:f="http://java.sun.com/jsf/core">
<e:workbook type="jxl">
<e:worksheet name="Devices" value="#{deviceOverviewAction.mkExcelExport()}" var="map">
<e:column>
<f:facet name="header">
<e:cell value="Device" />
</f:facet>
<e:cell value="#{map.key.description}" />
</e:column>
<e:column>
<f:facet name="header">
<e:cell value="Downtime" />
</f:facet>
<e:cell value="#{map.value} h" />
</e:column>
</e:worksheet>
</e:workbook>
</html>
My bean
------------------------
public Map<Device, Integer> mkExcelExport() {
Map<Device, Integer> map = new HashMap<Device, Integer>();
calcAvailabilityMonth();
map.putAll(c_DevicesAvavailabilityMonth);
return map;
}
5 Replies: | |||
|---|---|---|---|
Hmm, looks like the documentation is ahead of the code. Not sure which one should be edited ;-) Daniel (Roth), any comments? Could UIWorksheet.unwrapIterator use a Map.entrySet or something like that? If a man speaks in the forest and there is no woman around to hear him, is he still wrong? |
|||
Map should be removed from the documentation. The reason is that if we have a map as The correct way would be to do something like:
public List<DeviceInteger> mkExcelExport() {
List<DeviceInteger> ret = new LinkedList<DeviceInteger>();
calcAvailabilityMonth();
ret.addAll(c_DevicesAvavailabilityMonth);
return ret;
}
public class DeviceInteger {
private Device device;
private integer integer;
// getter, setters, constructor
}
|
|||
Actually, I think it's sort of doable, I tried adding to UIWorksheet.unwrapIterator a
else if (value instanceof Map) {
return ((Map) value).entrySet().iterator();
}
and added a test method that returned
public Map<String, String> getFoo() {
Map foo = new HashMap<String, String>();
foo.put("a", "1");
foo.put("b", "2");
foo.put("c", "3");
return foo;
}
and xhtml
<e:workbook
xmlns:e="http://jboss.com/products/seam/excel"
xmlns:f="http://java.sun.com/jsf/core">
<e:worksheet value="#{excelTest.foo}" var="data">
<e:column>
<e:cell value="#{data.value}"/>
</e:column>
</e:worksheet>
</e:workbook>
and I actually got an excel but it looked like 2 3 1 which is quite natural, since Maps don't guarantee iteration order. Which renders the Map usecase, well, useless in most cases. Or? If a man speaks in the forest and there is no woman around to hear him, is he still wrong? |
|||
Thank you for taking your time on this! For example to iterate a map:
<h:dataTable id="test" var="map" value="#{myHashMap}">
<h:column>
<f:facet name="header">
<h:outputText value="My Header 1" />
</f:facet>
#{map.key.name}
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="My Header 2" />
</f:facet>
#{map.value.serialNumber}
</h:column>
</h:dataTable>
In case of the iteration order of a map, I always use the LinkedHashmap or Treemap to have a ordered Map, so this should be possible?!
Greetings |
|||
I committed the Map-fix. If a man speaks in the forest and there is no woman around to hear him, is he still wrong? |