commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Bruce Alspaugh" <compulink...@gmail.com>
Subject [beanutils] Mixing static and dynamic properties in the same DynaBean
Date Sun, 19 Mar 2006 23:02:02 GMT
Newbie here.  Is it possible to define a DynaBean that has both dynamic
properties that are lazily added at runtime as well as static properties
that are defined at compile time?

For example, I would like to be able to do something like this:

    DynaBean order = new LazyDynaBean()  {
        public double getTotal() {
            double price = ((Double)get("price")).doubleValue();
            double quantity = ((Double)get("quantity")).doubleValue();
            return price * quantity;
        }
    };

And then access the properties this way:

    PropertyUtils.setSimpleProperty(order, "price", Double.valueOf(5.0));
    System.out.println("Price: " +
            PropertyUtils.getSimpleProperty(order, "price"));

    PropertyUtils.setSimpleProperty(order, "quantity", Double.valueOf(10.0
));
    System.out.println("Quantity: " +
            PropertyUtils.getSimpleProperty(order, "quantity"));

    System.out.println("Total: " +
            PropertyUtils.getSimpleProperty(order, "total"));

The output is:

Price:  5.0
Quantity:  10.0
Total: null

How do I get BeanUtils to use my getTotal() method to output the product of
price times quantity?

Ultimately, I would like to get the dynamic properties from a JDBC result
set, and use the statically defined properties to compute totals and the
like for the dynamic properties.

- Bruce

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message