简体   繁体   English

具有HtmlDataTable的java.util.Map

[英]java.util.Map with HtmlDataTable

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). 我正在GlassFish v3上开发一个应用程序,该应用程序使用JavaEE6的Suns-RI和JSF2.0等。坏的是,无法对Suns RI进行任何更改/切换(使用MyFaces或类似的东西) 。

Now, the problem is, that I want to build HtmlDatatable by hand ( in Java code). 现在的问题是,我想手动构建HtmlDatatable(在Java代码中)。 The datatable should represent a java.util.Map where the first column should display the key and the second the values of the map. 数据表应表示一个java.util.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. 我已经从java.util.List成功构建了PanelGrid,并在每次UIComponent的“ setExpressionValue”方法将UI绑定到基础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 ie "Save" button. 因此,进一步的问题是,此代码仅打印出Map的内容,在另一页上,我需要在HtmlInputText元素中显示的值,并且如果用户单击“保存”按钮即更新了整个地图。
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 ie "Save" button. 因此,进一步的问题是,此代码仅打印出Map的内容,在另一页上,我需要在HtmlInputText元素中显示的值,并且如果用户单击“保存”按钮即更新了整个地图。

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. 如果有解决方法,以列表的形式表示地图...请帮助我,因为对于此(地图为2个列表),我不知道如何再次更新基础地图/数据库模型。

Hopefully, someone can help me.... 希望有人可以帮助我...

The UIData components can't iterate over a Set since it doesn't provide ways to get/set elements by index. UIData组件无法迭代Set因为它不提供按索引获取/设置元素的方法。 It would also not work when you coded it straight in the JSF page. 当您直接在JSF页面中进行编码时,它也不起作用。 Replace it by a List or DataModel . 将其替换为ListDataModel

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM