i have two classes Email and Data. The relationship between them is OneToMany. In the data table of datas i want to display the list of emails it contains. How can i do that? These are parts of my entities:
@Entity
@Table(name = "EMAILS")
public class Email implements Serializable {
@Id
@Column(name = "id")
private String id;
@Column(name = "extraction_Date")
@Temporal(TemporalType.TIMESTAMP)
private Date date;
@Size(max = 255)
@Column(name = "email")
private String email;
@ManyToOne(cascade = CascadeType.PERSIST)
private Data dataBase;
public Email() {
this.date = new Date();
this.id = IdGenerator.IdGenerathorCall();
}
@Entity
@Table(name = "DATAS")
public class Data implements Serializable {
@Id
@Column(name = "id")
private String id;
@Temporal(TemporalType.TIMESTAMP)
@Column(name = "creation")
private Date date;
@Column(name = "timeofextraction")
private float grabduration;
@Column(name = "keyword")
private String keyword;
@Column(name = "number")
private int number;
@OneToMany(cascade = CascadeType.ALL, mappedBy = "dataBase", fetch = FetchType.EAGER)
private List<Email> emails;
public Data() {
super();
this.date = new Date();
this.id = IdGenerator.IdGenerathorCall();
}
My page dataList.xhtml looks like:
<p:dataTable value="#{dataMB.datas}" var="item" id="datas" rowsPerPageTemplate="5,10,15,20,25,30"
paginator="true" rows="10" filteredValue="#{dataMB.filteredDatas}"
selectionMode="single" rowKey="#{item.id}"
selection="#{dataMB.selectedData}">
<p:ajax event="rowSelect" update=":form:dataView , :form:confirmDelete"/>
<p:column sortBy="#{item.date}" filterBy="#{item.date}">
<f:facet name="header">
<p:outputLabel value="Creation"/>
</f:facet>
<p:outputLabel value="#{item.date}">
<f:convertDateTime pattern="MM/dd/yyyy HH:mm:ss" />
</p:outputLabel>
</p:column>
<p:column sortBy="#{item.grabduration}" filterBy="#{item.grabduration}">
<f:facet name="header">
<h:outputText value="Time of execution"/>
</f:facet>
<h:outputText value="#{item.grabduration}"/>
</p:column>
<p:column sortBy="#{item.keyword}" filterBy="#{item.keyword}">
<f:facet name="header">
<h:outputText value="Keyword"/>
</f:facet>
<h:outputText value="#{item.keyword}"/>
</p:column>
<p:column sortBy="#{item.number}" filterBy="#{item.number}">
<f:facet name="header">
<h:outputText value="Number"/>
</f:facet>
<h:outputText value="#{item.number}"/>
</p:column>
<p:column sortBy="#{item.emails}" filterBy="#{item.emails}">
<f:facet name="header">
<h:outputText value="Emails List"/>
</f:facet>
<h:outputText value="#{item.emails}"/>
</p:column>
</p:dataTable>
When i display the dataTable the column containing the emails list is empty nothing is shown.
You are trying to render a list in a single value component.
Change your emails column to this:
<p:column headerText="Emails List">
<p:dataList value="#{item.emails}" var="email" itemType="none">
#{email.email}
</p:dataList>
</p:column>
In addition to this you will need to make an auxiliary method to sort and filter by emails.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With