The "regular" set() method (i.e. not the indexed/mapped setters) doesn't
call the get(name) method - so you could override the other getters/setters
implementing your own behaviour as you suggest. Alternatively you could
"wrap" the LazyDynaBean and implement your own "getter" behaviour. If you're
wanting this as an ActionForm flavour (rather than just DynaBean) then you
could easily extend BeanValidatorForm to do this. Something like...

public class CustomLazyForm extends BeanValidatorForm {

    public LazyValidatorForm() {
        super(new LazyDynaBean());
    }

    public Object getMap() {
        return ((LazyDynaBean)dynaBean).getMap();
    }
    public Object get(String name) {
        if (name == null) {
            throw new IllegalArgumentException("No property name
specified");
        }
        if (getMap().contains(name) {
            return getMap().get(name);
        } else {
            throw new IllegalArgumentException(("Property '" + name +
                            "' does not exist in bean.");
        }
    }
    public Object get(String name, int index) {
        Object value = get(name);
        if (value != null) {
            return dynaBean.get(name, index)
        } else {
            throw new IllegalArgumentException(("Indexed Property '"
                    + name + "' is not initialized.");
        }
    }

    public Object get(String name, String key) {
        Object value = get(name);
        if (value != null) {
            return dynaBean.get(name, key)
        } else {
            throw new IllegalArgumentException(("Mapped Property '"
                    + name + "' is not initialized.");
        }

    }
}

You need to be careful about overriding the "indexed" getter - BeanUtils
uses that when populating indexed values and thats where indexed properties
need to "automatically grow"  for the ActionForm population to work properly
in Struts.

Niall

----- Original Message ----- 
From: "Joe Hertz" <[EMAIL PROTECTED]>
To: "'Struts Users Mailing List'" <user@struts.apache.org>
Sent: Monday, February 07, 2005 6:06 PM
Subject: RE: LazyDynaBean question


> Yep. I was afraid you'd say something like that. I'll see what I can do
> about moving to 1.2.6.
>
> On the subject:
>
> Is there a LazyDynaBean implementation that keeps the standard dynabean
> behavior on the get() methods? I don't want to touch any of the
> createProperty() methods because I want that behavior on the setters.
>
> I'm doing it now, but I'd just assume stay in the "path most traveled". It
> looks to be just a matter of any place that forces a return of null to
> return an InvalidArgumentException:
>
> Ex:
>
>         // Property doesn't exist
>         if (!isDynaProperty(name)) {
> //            return null;
>   throw new IllegalArgumentException("Property '" + name +
> "' does not exist in bean.");
>
> Bout right?
>
> Tx again
>
> -Joe



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to