1

I get call in a flow a method which returns a HashSet of Person back. Then i call the Set in my xhtml file with the Primeface-dataTable. Now i want to display the prename of the person, but a error appear and say, he doesn't found "prename"...

Then i put the HashSet in a ArrayList and do the same. And... it works fine! But why?
Set and List use as Superinterfaces Collection & Iterable. So why this don't work with Set?

Here are the parts of the files:

flow.xml

<view-state id="rcpm" view="rc/rcmembers.xhtml">
    <on-entry>
        <evaluate expression="RCHtmlCache.getCommunityList('rcpm')"
            result="flowScope.members" />
    </on-entry>
</view-state>

rcmembers.xhtml

<p:dataTable id="table1" var="member" value="#{members}"
                                sortMode="multiple" rowIndexVar="status"
                                emptyMessage="The Community is empty.">
<p:column>
    <f:facet name="header">
         <h:outputText value="Vorname" />
   </f:facet>

   <h:outputText value="#{member.vorname}" />

</p:column>

RCHtmlCache.java Set Version

public Set<Person> getCommunity(String key) {
        return htmlCache.get(key);
    }

RCHtmlCache.java List Version

public List<Person> getCommunityList(String key) {
    Set<Person> comList = htmlCache.get(key);
    ArrayList<Person> result = new ArrayList<Person>();
    for (Person person : comList) {
        result.add(person);
    }
    return result;
}

Hope you can explain me this weird incident...

4

2 回答 2

3

It is just a hint, but I think PrimeFaces only accept the List interface, hence you can't use Set interface, they are not the same.

You may create your own List + Set Adapter class by using the Adapter Pattern. It may suit very well to your problem, since you want to adapt the Set interface to a List interface. If you do so, then you won't need to convert your Set to a List every time.

Take a look at this: http://en.wikipedia.org/wiki/Adapter_pattern

Hope I could help.

于 2013-03-04T15:18:27.783 回答
2

DataTable works with DataModels...and DataModels only supports:
* java.util.List
* Array of java.util.Object
* java.sql.ResultSet (which therefore also supports javax.sql.RowSet)
* javax.servlet.jsp.jstl.sql.Result
* Any other Java object is wrapped by a DataModel instance with a single row.
(The above objects are implicitly used to build a DataModel)
See JSF Specification.

于 2013-03-04T15:36:19.903 回答