0

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

Jameson_uk
  • 432
  • 2
  • 12
  • I would use a HashMap, to group data, in your bean and I would display them with a ui:repeat looping by a key. Something like [this](https://stackoverflow.com/questions/8552804/uirepeat-doesnt-work-with-map) – WoAiNii Jun 09 '21 at 20:53
  • The issue I was having here was persisting input back to the database. I have kind of got it working by having a `@PostConstruct` method that pulls the entire list as above and stores it in the bean and then changed my method to populate the datatable to take a group as a parameter (which I am then using `stream` to pull out the relevant items from the list. This seems to work OK but I am not sure this is the ideal way of doing it. – Jameson_uk Jun 10 '21 at 07:53

0 Answers0