I have a database table that contains data for several groups (It is football fixtures) and I want to display this in a JSF application.
I have JPA setup with a POJO for the database table and with a simple backing bean I can show everything in a single datatable. This looks like
@Entity
@Getter @Setter @NoArgsConstructor
@Table(name="FIXTURES")
public class Fixture {
@Id
@Column(name="FIXTURE_ID")
private int fixtureId;
@Column(name="FIXTURE_DATE")
private Date fixtureDate
// more fields
}
Then
@Stateless
public class FixtureService {
@PersistenceContext(unitName="fixtureUnit")
private EntityManager em;
public void addFixture(Fixture fixture) {
em.persist(fixture);
}
public List<Fixture> getFixtures() {
return em.createQuery("From Fixture").getResultList();
}
// more stuff
}
and finally in the backing bean I have
@Inject
private FixtureService fixService;
public List<Fixture> getFixtures() {
return fixService.getFixtures();
}
What I would like however is split this up so I have separate tables for each group.
Using PrimeFaces I would like to do something like
<p:tabView>
<p:tab title="Group A">
<h1>Group A</h1>
<h:dataTable value="#{bean.fixtures}" var="f">
<h:column>
<f:facet name="header">Date</f:facet>
<h:outputText value="f.date" />
</h:column>
<h:column>
<f:facet name="header">Home Team</f:facet>
<h:outputText value="f.homeTeam" />
</h:column>
<!-- more columns -->
</p:tab>
</p:tabView>
and repeat with more columns and more groups.
I presume there is a way of dynamically creating the tabs based on which groups appear in the data but the main issue I am having is how (and where) I get the data for each group.
Currently I have it working so I return a list of fixtures but I am struggling to work out how I can just show group A's fixtures on that tab. Looking to understand how best I turn one big table into several smaller tables
I am using Weblogic 12.2.1.4 which is JSF 2.2