You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Joe Zendle <jo...@vericept.com> on 2003/07/18 18:22:34 UTC

order of bean form population

This is probably a JSP question but here goes:

What is the order in which bean properties are populated. Is it from 1st
to last as defined in the class (assuming reflection is used)? Can I
reliably use a property's value defined 1st to make a decision of how to
populate a later attribute? I am trying to make a form that can be used
to hold various business entities that share common attributes. 

Ex:

Assume hidden value is used in jsp to populate dataType below:

class MyForm extends ActionForm {
       private String dataType;
       private Vector holdsBaseClass = new Vector();


       public Set/getDataType(){}

       BaseClass getHoldsBaseClass(int index) {
           // need to know the concrete type to add
           while (holdsBaseClass.size()-1 < index) {
                if ( dataType.equals("derived1")
                     holdsBaseClass.add(new Derived1());
                if ( dataType.equals("derived2")
                     holdsBaseClass.add(new Derived2());
           }
           return holdsBaseClass.elementAt(index);
        }
}

       

---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


Re: order of bean form population

Posted by David Graham <gr...@yahoo.com>.
--- "Craig R. McClanahan" <cr...@apache.org> wrote:
> 
> 
> On Fri, 18 Jul 2003, Joe Zendle wrote:
> 
> > Date: Fri, 18 Jul 2003 10:22:34 -0600
> > From: Joe Zendle <jo...@vericept.com>
> > Reply-To: Struts Users Mailing List <st...@jakarta.apache.org>
> > To: Struts Users Mailing List <st...@jakarta.apache.org>
> > Subject: order of bean form population
> >
> > This is probably a JSP question but here goes:
> >
> > What is the order in which bean properties are populated. Is it from
> 1st
> > to last as defined in the class (assuming reflection is used)? Can I
> > reliably use a property's value defined 1st to make a decision of how
> to
> > populate a later attribute? I am trying to make a form that can be
> used
> > to hold various business entities that share common attributes.
> >
> 
> The only reasonable assumption to make is that it's undefined.  It ends
> up
> being driven by the order the request parameter names are iterated
> through
> from a HashMap, and that's essentially out of your control.  (See the
> method RequestUtils.populate() for the gory details.)

Also, the order the form elements are submitted via HTTP is undefined
although many browsers submit the fields in the order they are declared on
the form.

David

> 
> Craig
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
> 


__________________________________
Do you Yahoo!?
SBC Yahoo! DSL - Now only $29.95 per month!
http://sbc.yahoo.com

---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


Re: order of bean form population

Posted by "Craig R. McClanahan" <cr...@apache.org>.

On Fri, 18 Jul 2003, Joe Zendle wrote:

> Date: Fri, 18 Jul 2003 10:22:34 -0600
> From: Joe Zendle <jo...@vericept.com>
> Reply-To: Struts Users Mailing List <st...@jakarta.apache.org>
> To: Struts Users Mailing List <st...@jakarta.apache.org>
> Subject: order of bean form population
>
> This is probably a JSP question but here goes:
>
> What is the order in which bean properties are populated. Is it from 1st
> to last as defined in the class (assuming reflection is used)? Can I
> reliably use a property's value defined 1st to make a decision of how to
> populate a later attribute? I am trying to make a form that can be used
> to hold various business entities that share common attributes.
>

The only reasonable assumption to make is that it's undefined.  It ends up
being driven by the order the request parameter names are iterated through
from a HashMap, and that's essentially out of your control.  (See the
method RequestUtils.populate() for the gory details.)

Craig


---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org