Re: newbie with Cayenne Quick Start > Tapestry Tutorial

From: Mike Kienenberger (mkienen..laska.net)
Date: Thu Feb 10 2005 - 21:59:15 EST

  • Next message: Dov Rosenberg: "Re: Cayenne: Is it thread safe as compared to EOF?"

    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 : Thu Feb 10 2005 - 21:58:47 EST