RE: newbie with Cayenne Quick Start > Tapestry Tutorial

From: Michael Mangus (mdmangu..mail.com)
Date: Fri Feb 11 2005 - 11:01:34 EST

  • Next message: Koen Segers: "NEWBIE: cayenne.xml"

    Mike,

    Thanks for your responses. I'm glad the example blew up on me, because it
    gave me a chance to walk through Tapestry's stack trace to debug, which in
    turn gave me a little insight of Cayenne.

    Thanks for your input and hopefully after I read the online user guide I
    will understand how to implement your suggestion:

    >You can use a different Configuration subclass if you decide you want your
    >model configuration files found in a different place or using a different
    >loading mechanism.

    Thanks Again!

    Michael

    -----Original Message-----
    From: Mike Kienenberger [mailto:mkienen..laska.net]
    Sent: Thursday, February 10, 2005 8:59 PM
    To: cayenne-use..bjectstyle.org
    Subject: Re: newbie with Cayenne Quick Start > Tapestry Tutorial

    Michael Mangus <mdmangu..mail.com> wrote:
    > Hi,
    >
    > I have another Question about Cayenne Quick Start > Tapestry Tutorial.
    >
    > I got it running and all the pages worked fine except:
    >
    > AddPaintingPage gives this error:
    >
    > org.apache.tapestry.BindingException
    > Parameter value (0) is an instance of java.math.BigDecimal, which does not
    > inherit from java.lang.String.
    > binding: ExpressionBinding[AddPaintingPage painting.estimatedPrice]
    > location: context:/WEB-INF/pages/AddPaintingPage.page, line 21, column
    > 64
    >
    > I believe is because the TextField implements String and can't bind
    directly
    > to the BigDecimal Type of painting.estimatedPrice.
    >
    > I had to change the following:
    > AddPaintingPage.java
    > public void pageBeginRender(PageEvent event) {
    > Painting painting = new Painting();
    > painting.setEstimatedPrice(new BigDecimal(0));
    > setPainting(painting);
    > }
    >
    > TO
    > public void pageBeginRender(PageEvent event) {
    > Painting painting = new Painting();
    > painting.setEstimatedPrice("0");
    > setPainting(painting);
    > }
    >
    > I also had to change the generated class file from Cayenne:
    > public void setEstimatedPrice(java.math.BigDecimal estimatedPrice) {
    > writeProperty("estimatedPrice", estimatedPrice);
    > }
    > public java.math.BigDecimal getEstimatedPrice() {
    > return (java.math.BigDecimal)readProperty("estimatedPrice");
    >
    >
    > TO
    > public void setEstimatedPrice(String estimatedPrice) {
    > writeProperty("estimatedPrice", estimatedPrice);
    > }
    > public String getEstimatedPrice() {
    > return readProperty("estimatedPrice").toString();
    > }
    >
    > After I changed those above I could run the whole example with no
    problems.
    >
    > My question is that the generated class says:
    > /** Class _Painting was generated by Cayenne.
    > * It is probably a good idea to avoid changing this class manually,
    > * since it may be overwritten next time code is regenerated.
    > * If you need to make any customizations, please use subclass.
    > */
    >
    > I thought about overriding the method in the Painting class that extends
    > _Painting, but it doesn't allow that with return types not matching.
    >
    > Where would I make this change without worrying about my changes being
    > overwritten by Cayenne?

    You could do this by adding

         public void setEstimatedPriceString(String estimatedPriceString) {
             setEstimatedPrice(new BigDecimal(estimatedPriceString));
         }
         public String getEstimatedPriceString() {
             return getEstimatedPrice().toString();
         }

    to Painting.

    However, you really should have an intermediate presentation layer method
    that validates that the String coming in can be converted to a valid
    BigDecimal (is numeric, is positive, etc), and then call it with the
    converted String value.

    -Mike



    This archive was generated by hypermail 2.0.0 : Fri Feb 11 2005 - 11:01:54 EST