users@javaserverfaces.java.net

Re: dataTable of map

From: Thufir <hawat.thufir_at_gmail.com>
Date: Tue, 13 Apr 2010 00:23:17 +0000 (UTC)

On Mon, 12 Apr 2010 17:16:38 -0400, Raymond DeCampo wrote:

> You need to provide an implementation of javax.faces.model.DataModel
> that understands how to interpret your Map as the value to the
> dataTable. Alternatively, coerce the Map into an array, List or
> ResultSet to use one of the built-in DataModels.
> You need to provide an implementation of javax.faces.model.DataModel
> that understands how to interpret your Map as the value to the
> dataTable.  Alternatively, coerce the Map into an array, List or
> ResultSet to use one of the built-in DataModels.<br>

I can get output from a List fine, however, not a List of List, if you
will.

so, if you array:
int[][] array = new int[3][2];

how would you get that into a DataTable?

I think, but could be wrong, that this approach may work:



   1. <h:dataTable var="item" value="#{MyBean.items}"
   2. binding="#{MyBean.dataTable}" >
   3. <h:column>
   4. <h:outputText styleClass="output" value="#{item.productName}"/>
   5. </h:column>
   6.
   7. <h:column>
   8. <h:commandButton value="remove" action="#{MyBean.remove}" />
   9. </h:column>
  10. </h:dataTable>


   1. public class MyBean {
   2. private ArrayList items = new ArrayList();
   3. private HtmlDataTable dataTable;
   4.
   5. public ArrayList getItems() {
   6. return items;
   7. }
   8.
   9. public void setItems(List items) {
  10. this.items = new ArrayList(items);
  11. }
  12.
  13. public void remove(){
  14. ItemBean item = (ItemBean) getDataTable().getRowData();
  15. items.remove(item);
  16. }
  17.
  18. public HtmlDataTable getDataTable() {
  19. return dataTable;
  20. }
  21.
  22. public void setDataTable(HtmlDataTable dataTable){
  23. this.dataTable = dataTable;
  24. }
  25.
  26. }

http://kalanir.blogspot.com/2007/02/jsf-binding-datatable-from-managed-
bean.html


I like that, because the DataTable is loaded/populated from the bean
rather than the view. However, I would expect that you could do
something like:


JTable table = new JTable(data, columnNames); //swing

but that just doesn't work?




thanks,

Thufir