Help

Controls

PermLinkWikiLink

Built with Seam

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.

Forum: Seam Users Forum ListTopic List
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:
17. Nov 2008, 21:06 CET | Link

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?

17. Nov 2008, 21:44 CET | Link

Map should be removed from the documentation. The reason is that if we have a map as input to a table, what values should we use? map.values(), map.keySet() or map.entrySet()?

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
}

17. Nov 2008, 22:38 CET | Link

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?

18. Nov 2008, 08:59 CET | Link

Thank you for taking your time on this!

For me, it would be very useful if the worksheet would have the same behavior like a dataTable...
(It's the same useCase, I have a Collection which I'd like to display in rows and columns:

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
Daniel

 
18. Nov 2008, 11:29 CET | Link

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?