Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

p:dataList cannot iterate java.util.Set

I have a primefaces dataList within a primefaces dataGrid but I'm having issue mapping to a property of the nested dataList collection (java.util.Set). When I reference any attribute on the nested Set (dream.tag), I get exception:

javax.servlet.ServletException: /registered/modify.xhtml @42,48 value="#{tag.id}": Property 'id' not found on type org.hibernate.collection.PersistentSet.

That attribute is there, but the dream.tag attribute is mapped to a private Set tag. Is it possible to use the dataList component with a Set. I've copied an outline of my data model below. Thanks for the help!

<p:dataGrid var="dream" value="#{dreamModifyBean.dreams}" columns="5"  rows="10" paginator="true" effect="true"  paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}" rowsPerPageTemplate="10,15,20" paginatorPosition="bottom"> 
    <p:column>  
        <h:panelGrid columns="1" style="width:100%"> 
            <h:outputText value="#{dream.order}. #{dream.title}"/><br/>
            <p:graphicImage value="#{dream.imageThumb}" width="125" height="100"/><br/>
            <h:outputText value="#{dream.notes}"/><br/>
            <p:dataList value="#{dream.tag}" var="tag">  
                <h:outputText value="#{tag.id}"/>
            </p:dataList> 
            <h:outputText value="#{bundle['dreamModify.cost.TEXT']} #{dream.cost}"/><br/>
        </h:panelGrid>  
    </p:column>  
</p:dataGrid>

Dream (dreamModifyBean.dreams) - Parent:

public class Dream implements Serializable{
 @OneToMany(fetch=FetchType.EAGER,cascade={CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REFRESH})
 @JoinColumn(name="DREAM_ID")
 private Set<Tag> tag;

public Set<Tag> getTag() {
    return tag;
}
public void setTag(Set<Tag> tag) {
    this.tag = tag;
}
}

Tag (dream.tag) - Child

public class Tag {
 @Id
 @GeneratedValue(strategy=GenerationType.IDENTITY)
 @Basic(optional=false)
 @Column(name="ID")
 private Long id;
 @Basic(optional=false)
 @Column(name="DESCRIPTION")
 private String description;
 @ManyToOne(fetch=FetchType.EAGER)
 @JoinColumn(name="DREAM_ID")
 private Dream dream;

 public Long getId() {
    return id;
 }
 public void setId(Long id) {
    this.id = id;
 }
 public String getDescription() {
    return description;
 }
 public void setDescription(String description) {
    this.description = description;
 }
public Dream getDream() {
    return dream;
}
public void setDream(Dream dream) {
    this.dream = dream;
}
}
like image 630
c12 Avatar asked Dec 16 '22 16:12

c12


2 Answers

Try to use a List. The value attribute must be one of the following as described here:

  • a list of beans
  • an array of beans
  • a single bean
  • a javax.faces.model.DataModel object
  • a java.sql.ResultSet object
  • a javax.servlet.jsp.jstl.sql.Result object
  • a javax.sql.RowSet object
like image 168
Matt Handy Avatar answered Dec 29 '22 05:12

Matt Handy


You can use toArray() method of the Set:

<p:dataList value="#{dream.tag.toArray}" var="tag">  
    <h:outputText value="#{tag.id}" />
</p:dataList>
like image 45
Ahmet Avatar answered Dec 29 '22 03:12

Ahmet