2 Replies Latest reply on Feb 10, 2007 1:25 PM by Anthony Whitford

    Foreign Keys and changing Seam Gen templates

    Damian Harvey Master

      Hi,

      I'm using Seam Gen to generate the CRUD pages for my application using Seam 1.1.5, however one thing that I find odd with the generated pages is that if you have a foreign key, the generated pages do not allow you to enter it in a normal fashion.

      For example: If you have one table COUNTRY with a primary key of COUNTRYCODE and another table PERSON with a foreign key of COUNTRYCODE, the generated pages make you enter in a COUNTRY and then the PERSONs associated with that country. When entering in PERSON you cannot select a country.

      In reality you would enter in a COUNTRY and then be able to select a country when entering the PERSON.

      I've tried to modify the Seam Template edit.xhtml.ftl and change the line:

      <#if !c2h.isCollection(property) && !c2h.isManyToOne(property) && property.columnSpan==1>

      to remove the restriction on "isManytoOne", however this results in an error:
      property.value.typeName is undefined. It cannot be assigned to propertyType


      I don't know the Seam gen package and Freemarker well enough to jump into it.

      Can anybody suggest how to modify the template so that all fields in the table are displayed? Even better would be having some means of automating the lookup? eg using ice:selectInputText or similar?

      Thanks,

      Damian.

        • 1. Re: Foreign Keys and changing Seam Gen templates
          Damian Harvey Master

          I totally misunderstood what Hibernate was trying to do there. I get it now.

          What I was really after was the <si:selectItems> and for those looking it's all detailed here: http://wiki.jboss.org/wiki/Wiki.jsp?page=SeamSelectItemsNewDesign

          The only problem I'm now facing is that the si:selectItems doesn't seem to want to play nice with the EntityHome that Seam Gen uses on all Create/Edit pages. This is covered in this thread: http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4008752#4008752

          Also for anyone interested I made a change to the edit.xhtml.ftl template to include si:selectItems for ManyToOne fields:

          <#elseif c2h.isManyToOne(property)>
          <#assign parentPojo = c2j.getPOJOClass(cfg.getClassMapping(property.value.referencedEntityName))>
          <#assign parentPageName = parentPojo.shortName>
          <#assign parentName = util.lower(parentPojo.shortName)>
          
           <tr class="prop">
           <td class="name">${property.name}</td>
           <td class="value">
           <s:decorate>
           <h:selectOneMenu value="${'#'}{${homeName}.instance.${property.name}}">
           <si:selectItems value="${'#'}{${parentName}SelectList.resultList}" var="${parentName}" label="${'#'}{${parentName}.${parentPojo.identifierProperty.name}}"/>
           </h:selectOneMenu>
           </s:decorate>
           </td>
           </tr>
          

          This goes between the last 2 </#if> which are before the first </#foreach>. I also deleted the association stuff after the actionButtons.

          You still have to configure the project to handle si:selectItems and configure the components.xml to have the relevant queries; eg:
          <framework:entity-query name="countryCodeSelectList" ejbql="select c from CountryCode c" />
          


          Hope this helps someone.

          Cheers,

          Damian.

          • 2. Re: Foreign Keys and changing Seam Gen templates
            Anthony Whitford Newbie

            I think I have the same problem as you, and Gavin suggested getting the latest seam-gen from CVS... See my post:
            http://www.jboss.com/index.html?module=bb&op=viewtopic&t=101221