Johan

I take that as definite No! with no room for negotiation - oh shit, better
tell my boss I did it all wrong ;)

As I said to William...

The problem of implementing this using the Struts BeanUtils is that it has
been deprecated because its been donated to the Jakarta Commons project -
will we be able to persuade Jakarta Commons to include this when it doesn't
have anything to do with JavaBeans?

My interface is more minimalistic than yours because its tightly focused on
all Struts needs to do i.e. get and set values. How people implement it is
up to them - how properties a stored (doesn't have to be a HashMap), getting
a list of properties (i.e your getBeanProperties() method) and type
conversion can all be implemented in your own flavour of ActionForm (which
is what we did).

Thanks for your offer of code - these aspects of our system are done and
working and I really want to see what Struts does because if it suits us,
better to use the vanilla Struts solution.

Niall


> -----Original Message-----
> From: Johan Compagner [mailto:[EMAIL PROTECTED]]
> Sent: 30 May 2001 10:07
> To: [EMAIL PROTECTED]
> Subject: RE: PropertyUtils Enhancement Source Code
>
>
> > 1) Created a "DynamicProperties" interface which has the
> > following methods:
> >
> >      public String getValue(String property);
> >      public String getValue(int index, String property);
> >      public void   setValue(String property, String value);
> >      public void   setValue(int index, String property, String value);
>
> Almost the samething i have now.  I only have some more (and i
> don't have at
> this time the index because
> i don't believe that is nessesary, because BeanUtils / PropertyUtils are
> taking care of that!
>
> This is My interface that i use for quite sometime know.
>
> public interface Property
> {
> public java.util.Map getBeanProperties();             // Is
> needed for the new describe
> method in PropertyUtils!!
> public Object getBeanProperty(String sPropertyName);
> public Class[] getParameterTypes(String sName); // You should be
> able to get
> the types of the property.
> public void setBeanProperty(String sPropertyName, Object oPropertyValue);
> }
>
>
> > 2) Sub-classed "ActionServlet" and changed the
> "processPopulate" method to
> > populate the ActionForm using the above setters if its an instance of
> > "DynamicProperties" or using its normal reflection if not.
>
> No!
> ActionServlet doesn't have to change at all!!
> Everychange must only be done in the PropertyUtils and BeanUtils.
> What does ActionServlet to do with beans? Nothing. Struts only
> uses the Bean
> And property utils
> for filling the beans. At this time only with reflection but i
> changed Bean
> And PropertyUtils
> so that it looks for the above Interface Property and then calls
> the get or
> set of that Property Interface.
>
> Here some code i changed in the PropertyUtils class:
>
> public static void setSimpleProperty(Object bean, String name,
> Object value)
> {
>       // If it is of Property
>       if (bean instanceof Property)
>       {
>               // Use that one instead of Reflection (you create
> youre own reflection
> interface)
>               ((Property) bean).setBeanProperty(name, value);
>       }
>       else
>       {
>               // Retrieve the property setter method for the
> specified property
>               PropertyDescriptor descriptor =
> getPropertyDescriptor(bean, name);
>               if (descriptor == null)
>                       throw new NoSuchMethodException("Unknown
> property '" + name + "'");
>               Method writeMethod = getWriteMethod(descriptor);
>               if (writeMethod == null)
>                       throw new NoSuchMethodException("Property
> '" + name + "' has no setter
> method");
>
>               // Call the property setter method
>               Object values[] = new Object[1];
>               values[0] = value;
>               writeMethod.invoke(bean, values);
>       }
> }
>
>
> > 3) Modified Struts tags to retrieve bean values using the above
> getters if
> > its an instance of "DynamicProperties" or using its normal reflection if
> > not.
>
> No tag doesn't have to be changed in my way. Because all is done throught
> the Property and BeanUtils classes!!!
>
>
> > 4) Created a sub-class of ActionForm (DynamicActionForm) which
> implements
> > our "DynamicProperties" interface.
>
> No this can be done by the programmers themself just do this:
>
> public class DynamicForm extends ActionForm implements
> org.apache.struts.util.Property
>
> And then they must implement the four methods.
> Ofcourse Struts could create a default DynamicForm that uses a Hashmap for
> storing its properties
> only the getParameterTypes would be a bit difficut then! (i will
> think this
> over)
>
>
> > Now we only have one DynamicActionForm and don't have to go round
> > setting up
> > loads of different "ActionForm" classes. The DynamicActionForm is a bit
> > simplistic and wouldn't suit everyones needs, but the advantage
> of this is
> > people could create their own concrete implementations.
>
> If they just uses my interface then it is very easy to do this.
>
>
> > It would be interesting to hear others opinions on how dynamic
> properties
> > should be implemented.
>
> given :-)
>
> > Niall
>
> Johan Compagner
>
> P.S.  I am willing to give my implementation of the Property interface and
> the changes to
>       BeanUtils/PropertyUtils email me if you want.
>
>
>

Reply via email to