1 Reply Latest reply on Oct 26, 2010 11:23 AM by Roger Mori

    Handling composite primary keys in pages.xml using EntityHome

    Karsten Wutzke Expert


      wow does Seam Framework handle composite primary keys in pages.xml using EntityHome?

      The usual approach is to assign an ID to entityHome components, like:

      <page view-id="/team-list.xhtml">
        <param name="club" value="#{clubHome.id}" converterId="javax.faces.Integer" validatorId="javax.faces.LongRange" />

      This assigns the (atomic) ID to clubHome from the URL


      but what's the technique to apply for entities using composite primary keys? Here the key is composed of (roundId, ordinalNumber), giving a URL


      <page view-id="/standings.xhtml">
        <param name="group" value="#{groupHome.setId(new GroupId(round???, group???))}" />

      The above is a non-working attempt to assign a new composite ID to groupHome. The problem here is how to reference the URL params. (Is there a way to create temp vars in pages.xml?)

      Other than that, I see no other way but to assign the atomic PK properties to member variables in one or several different EntityHome components, of course requiring EntityHome subclasses with resprective getters and setters:

      public class GroupHome extends EntityHome<Group>
          // temp var
          private Integer ordinalNumber;
          public void setOrdinalNumber(Integer ordinalNumber)
              this.ordinalNumber = ordinalNumber;
          public Integer getOrdinalNumber()
              return ordinalNumber;

      Used as following from pages.xml:

      <page view-id="/standings.xhtml">
        <param name="round" value="#{roundHome.id}" />
        <param name="group" value="#{groupHome.ordinalNumber}" />

      So, what's the best practice here? I can neither find any examples using composite primary keys in Seam in Action nor in/on the net.