You can find the full source code for this website in the Seam package in the directory /examples/wiki. It is licensed under the LGPL.
| Online: | 28 Members of 4510 |
| Forum: Seam Users |
19. Sep 2008, 11:03 CET | Link |
Hi All
I'm sorry for resurrecting this old bug-bear but I am trying to build a CRUD front-end application for my existing EJB3-based system. (over 200 entities)
Many of my entities contain multiple references to the same entity type - for example, a flight has a departure airport and a destination airport so we have two distinct references to the airports entity / table.
I have been researching this problem and found JIRA JBSEAM-994 which attempts but apparently fails to resolve the problem by means of code generation.
I am perfectly happy to put in the work to manually 'massage' the 'seam-gen'ed code, but I don't know where to start, and what to change.
Gavin King suggests back on May 07 that it is possible, just difficult to do automatically:
No, this patch is not a correct solution, in fact I don't see any easy way to arrive at a correct solution - this is a super-difficult one to solve by code generation, it needs human-written code.
My question however, is 'How?'
A single example would be sufficient to get me going :)
Any guidance would be gratefully appreciated
Thanks
Adrian
public class ${entityName}Home extends ${pojo.importType("org.jboss.seam.framework.EntityHome")}<${entityName}>
{
<#assign prevEntry = " ">
<#foreach property in pojo.allPropertiesIterator>
<#if c2h.isManyToOne(property)>
<#assign parentPojo = c2j.getPOJOClass(cfg.getClassMapping(property.value.referencedEntityName))>
<#assign parentHomeName = util.lower(parentPojo.shortName) + "Home">
<#if parentHomeName !=prevEntry>
@${pojo.importType("org.jboss.seam.annotations.In")}(create=true)
${parentPojo.shortName}Home ${parentHomeName};
<#assign prevEntry = parentHomeName>
</#if>
</#if>
</#foreach>
A quick & dirty solution but got tired of fixing manually
Thank you for the suggestion, Jayanta, and your code does indeed prevent the compilation errors in the FlightHome class, however the resulting application permits CRUD operations to be performed on the departureAirport field of a Flight, but there is no means to access the destinationAirport.
I believe that the original structure showing both fields in the Home class annoted with @In, but with different names is a more correct starting point:
The wire() method also needs manual modification to make this work.
However, I am lost as to what changes are required in the .pages.xml and .xhtml files.
I suspect that Flight.page.xml will need the following two lines duplicated and renamed:
<param name="airportFrom"/> <param name="airportId" value="#{airportHome.airportId}"/>The Flight.xhtml page seems ok but I can't see any way to avoid duplicating all eight Airport files in my source tree:
... with the only difference being the @Name Annotations in the java files, and renaming the links in the destinationAirport tab of the Flight.xhtml to use the new component name eg Airport2
While class re-use is common in 'ordinary' Java, I cannot find any examples of it being used in Seam.
Can anyone advise me please?
Thanks
Adrian
Adrian,
The patch proposed (doublon.zip and doublon2.patch) for JBSEAM-994 works. And it does the job automatically.
If you want to do it manually, you can still check how the patch does the job. Yes, there are quite a lot of code to add. Mainly to deal with one seam component per attribute of same type.