1 Reply Latest reply on Oct 26, 2010 11:23 AM by rogermorituesta.rogermori.yahoo.com

    Handling composite primary keys in pages.xml using EntityHome

    kwutzke

      Hello,


      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" />
      </page>



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


      http://...?club=12345...


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


      http://...?round=143&group=1...


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



      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:


      @Name("groupHome")
      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}" />
      </page>



      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.


      Karsten