[jboss-user] [JBoss Seam] - Best practice for creating reference entity for entity creat

awhitford do-not-reply at jboss.com
Fri Feb 9 23:30:38 EST 2007


I used seam-gen from 1.1.6 GA to create a reverse-engineered project.  I have a table with a self join.  (Note that in order to use generate-entities, I had to drop the foreign key constraint, then I doctored the generated project a bit to restore the object relationship.)  My entity looks something like:
  | @Entity
  | public class Currency implements Serializable
  | {
  |     private static final long serialVersionUID = 1L;
  | 
  |     /** ISO 4217 Currency Code */
  |     @Id
  |     @Column(columnDefinition = "char(3)", length = 3)
  |     @NotNull
  |     @Length(min = 3, max = 3)
  |     private String code;
  | 
  |     /** Currency name (English) */
  |     @Column(length = 40, nullable = false, unique = true)
  |     @NotEmpty
  |     @Length(max = 40)
  |     private String name;
  | 
  |     /** Rank for sorting */
  |     @Column(nullable = false)
  |     @NotNull
  |     private int sortRank;
  | 
  |     /**
  |      * Replacement Currency. For example pre-Euro currencies would have EUR specified.
  |      */
  |     @ManyToOne
  |     private Currency replacementCurrency;
  | 
  |     /**
  |      * Replacement Date is the date that the currency was replaced. For example,
  |      * the date when the currency was converted to EUR.
  |      */
  |     @Temporal(TemporalType.DATE)
  |     private Date replacementDate;
  | ...
  | }
  | 

So on the CurrencyEdit.xhtml page, there is code like:

  |                     <tr class="prop">
  |                         <td class="name">Replacement Currency</td>
  |                         <td class="value">
  |                             <s:decorate>
  |                                <h:inputText id="replacementCurrency" 
  |                                           size="3"
  |                                      maxlength="3"
  |                                          value="#{currencyHome.instance.replacementCurrency}"/>
  |                             </s:decorate>
  |                         </td>
  |                     </tr>
  | 
  | 

Of course, when I try to save, I get an argument type mismatch error:
anonymous wrote : 
  | CurrencyEdit.xhtml @85,96 value="#{currencyHome.instance.replacementCurrency}": Exception setting property replacementCurrency of base with class com.mycompany.reference.iso.Currency, Bean: com.mycompany.reference.iso.Currency, property: replacementCurrency, argument type mismatch 
  | 

The form only is accepting a String, which is the PK of Currency, but not a Currency object.  Clearly, I need to use that String key to find the object instance, and then assign that to the object being edited...  Anybody have an example?

I can imagine the code to do this, but I am really wondering what the best practice is.  Can I use the CurrencyHome or CurrencyList object in some fashion, or do I need to create another bean?

(I am a little surprised that I couldn't find an example in the Seam documentation.)


View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4014018#4014018

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4014018



More information about the jboss-user mailing list