java.util.Map with HtmlDataTable
Posted
by gerry
on Stack Overflow
See other posts from Stack Overflow
or by gerry
Published on 2010-04-27T10:42:05Z
Indexed on
2010/04/27
10:43 UTC
Read the original article
Hit count: 354
Hi,
I'm developing an application on GlassFish v3 which uses Suns-RI of JavaEE6 and JSF2.0, etc. And the bad thing is, that no changes/switches away from Suns RI can be made (to use MyFaces or something like that).
Now, the problem is, that I want to build HtmlDatatable by hand ( in Java code). The datatable should represent a java.util.Map where the first column should display the key and the second the values of the map.
I've build successfully a PanelGrid from a java.util.List and used every time the "setExpressionValue" methods of UIComponent to bind the UI to the underlying List.
But now, this doesn't work with the Map. Here is a snippet of my code:
public HtmlDataTable getEntityDetailsDataTable() {
...
Application app = FacesContext.getCurrentInstance().getApplication();
HtmlDataTable component = (HtmlDataTable)app.createComponent(HtmlDataTable.COMPONENT_TYPE);
component.setValueExpression("value", ExpressionUtil.createValueExpression("#{entityTree.entity."+fieldName+".entrySet()}", Map.class));
component.setVar("param");
UIColumn column = new UIColumn();
UIOutput label1 = DynamicHtmlComponentCreator.createHtmlOutputText("#{param[key]}", String.class);
column.getChildren().add(label1);
UIOutput label2 = DynamicHtmlComponentCreator.createHtmlOutputText("#{param[value]}", String.class);
column.getChildren().add(label2);
component.getChildren().add(column);
...
return component;
}
component.getChildren().add(column);
...
return component;
}
So, further the problem is, that this code only prints out the content of the Map, on another page I need the values displayed in HtmlInputText elements and the whole map updated if the user clicks a i.e. "Save" button.
So, further the problem is, that this code only prints out the content of the Map, on another page I need the values displayed in HtmlInputText elements and the whole map updated if the user clicks a i.e. "Save" button.
If there is a workaround, to represent the Map as to Lists...please help me, because for this (map as 2 lists) I've no idea how the underlying map/database model can be updated again.
Hopefully, someone can help me....
© Stack Overflow or respective owner