You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Richard Sayre <ri...@gmail.com> on 2008/02/01 13:37:04 UTC

Populate Form from DAO

Struts 2 allows us to automatically populate our forms if we name our
fields correctly, which is wonderful.

My actions usually go something like this

execute () {

    MyObject o = myDAO.getRecord(id);

   member1 = o.getMember1();
   member2 = o.getMember2();

}

MyObject is a JO for hold a row in the database.  I like the fact that
I can name my form field 'member1' and it the interceptor will set and
get from my Action.  I dont like having to set up each member variable
in the action with the members my class.  Is it possible to somehow
have Struts automatically populate an Java Object rather then the
Action?  I thought I remember reading about this before but I'm not
sure.  It's not a big deal, and I know I can use OGNL to access the
value, but I wanted the convience of mapping a fieldName to my custom
object.  Is this possible?

Thank you,

Rich

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


Re: Populate Form from DAO

Posted by Wes Wannemacher <we...@wantii.com>.
If the beans match, you could probably use commons-beanutils, but
IIRC, you'll incur a performance penalty.

http://commons.apache.org/beanutils/apidocs/org/apache/commons/beanutils/BeanUtils.html#copyProperties(java.lang.Object,%20java.lang.Object)

By doing it explicitly though, you allow yourself the room to change
your business/TO/etc. objects without the need to update your UI.

-Wes

On 2/1/08, Richard Sayre <ri...@gmail.com> wrote:
> Yes,
>
> I know I can do it this way.  I'm just being lazy.
>
> I want:
>
> <s:textfield name="member1"/>
>
> To automatically get/set  MyObject.getMeember1() rather then it
> automatically setting it in the Action and then having me create the
> Object and populate it with values.
>
>
>
>
> On Feb 1, 2008 9:10 AM, LEONARD Julien (Consulting for ACCOR Hotels)
> <ju...@consulting-for.accor.com> wrote:
> > Did you try :
> >
> > MyObject theObject;
> > (geter and setter on theObject)
> >
> > execute () {
> >
> >     theObject = myDAO.getRecord(id);
> > }
> >
> > And in the JSP : <s:property value="theObject.member1"/>
> >
> > -----Message d'origine-----
> > De : Richard Sayre [mailto:richardsayre@gmail.com]
> > Envoyé : vendredi 1 février 2008 13:37
> > À : Struts Users Mailing List
> > Objet : Populate Form from DAO
> >
> >
> > Struts 2 allows us to automatically populate our forms if we name our fields correctly, which is wonderful.
> >
> > My actions usually go something like this
> >
> > execute () {
> >
> >     MyObject o = myDAO.getRecord(id);
> >
> >    member1 = o.getMember1();
> >    member2 = o.getMember2();
> >
> > }
> >
> > MyObject is a JO for hold a row in the database.  I like the fact that I can name my form field 'member1' and it the interceptor will set and get from my Action.  I dont like having to set up each member variable in the action with the members my class.  Is it possible to somehow have Struts automatically populate an Java Object rather then the Action?  I thought I remember reading about this before but I'm not sure.  It's not a big deal, and I know I can use OGNL to access the value, but I wanted the convience of mapping a fieldName to my custom object.  Is this possible?
> >
> > Thank you,
> >
> > Rich
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> > For additional commands, e-mail: user-help@struts.apache.org
> >
> >
> >
> > This e-mail, any attachments and the information contained therein ("this message") are confidential and intended solely for the use of the addressee(s). If you have received this message in error please send it back to the sender and delete it. Unauthorized publication, use, dissemination or disclosure of this message, either in whole or in part is strictly prohibited.
> > **********************************************************************
> > Ce message électronique et tous les fichiers joints ainsi que  les informations contenues dans ce message ( ci après "le message" ), sont confidentiels et destinés exclusivement à l'usage de la  personne à laquelle ils sont adressés. Si vous avez reçu ce message par erreur, merci  de le renvoyer à son émetteur et de le détruire. Toutes diffusion, publication, totale ou partielle ou divulgation sous quelque forme que se soit non expressément autorisées de ce message, sont interdites.
> > **********************************************************************
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> > For additional commands, e-mail: user-help@struts.apache.org
> >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>


-- 
Wesley Wannemacher
President, Head Engineer/Consultant
WanTii, Inc.
http://www.wantii.com

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


Re: Populate Form from DAO

Posted by Al Sutton <al...@alsutton.com>.
Any reason you're not using ModelDriven?


----- Original Message ----- 
From: "Richard Sayre" <ri...@gmail.com>
To: "Struts Users Mailing List" <us...@struts.apache.org>
Sent: Friday, February 01, 2008 1:01 PM
Subject: Re: Populate Form from DAO


Yes,

I know I can do it this way.  I'm just being lazy.

I want:

<s:textfield name="member1"/>

To automatically get/set  MyObject.getMeember1() rather then it
automatically setting it in the Action and then having me create the
Object and populate it with values.




On Feb 1, 2008 9:10 AM, LEONARD Julien (Consulting for ACCOR Hotels)
<ju...@consulting-for.accor.com> wrote:
> Did you try :
>
> MyObject theObject;
> (geter and setter on theObject)
>
> execute () {
>
>     theObject = myDAO.getRecord(id);
> }
>
> And in the JSP : <s:property value="theObject.member1"/>
>
> -----Message d'origine-----
> De : Richard Sayre [mailto:richardsayre@gmail.com]
> Envoyé : vendredi 1 février 2008 13:37
> À : Struts Users Mailing List
> Objet : Populate Form from DAO
>
>
> Struts 2 allows us to automatically populate our forms if we name our 
> fields correctly, which is wonderful.
>
> My actions usually go something like this
>
> execute () {
>
>     MyObject o = myDAO.getRecord(id);
>
>    member1 = o.getMember1();
>    member2 = o.getMember2();
>
> }
>
> MyObject is a JO for hold a row in the database.  I like the fact that I 
> can name my form field 'member1' and it the interceptor will set and get 
> from my Action.  I dont like having to set up each member variable in the 
> action with the members my class.  Is it possible to somehow have Struts 
> automatically populate an Java Object rather then the Action?  I thought I 
> remember reading about this before but I'm not sure.  It's not a big deal, 
> and I know I can use OGNL to access the value, but I wanted the convience 
> of mapping a fieldName to my custom object.  Is this possible?
>
> Thank you,
>
> Rich
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
>
> This e-mail, any attachments and the information contained therein ("this 
> message") are confidential and intended solely for the use of the 
> addressee(s). If you have received this message in error please send it 
> back to the sender and delete it. Unauthorized publication, use, 
> dissemination or disclosure of this message, either in whole or in part is 
> strictly prohibited.
> **********************************************************************
> Ce message électronique et tous les fichiers joints ainsi que  les 
> informations contenues dans ce message ( ci après "le message" ), sont 
> confidentiels et destinés exclusivement à l'usage de la  personne à 
> laquelle ils sont adressés. Si vous avez reçu ce message par erreur, merci 
> de le renvoyer à son émetteur et de le détruire. Toutes diffusion, 
> publication, totale ou partielle ou divulgation sous quelque forme que se 
> soit non expressément autorisées de ce message, sont interdites.
> **********************************************************************
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

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


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


Re: Populate Form from DAO

Posted by Richard Sayre <ri...@gmail.com>.
Yes,

I know I can do it this way.  I'm just being lazy.

I want:

<s:textfield name="member1"/>

To automatically get/set  MyObject.getMeember1() rather then it
automatically setting it in the Action and then having me create the
Object and populate it with values.




On Feb 1, 2008 9:10 AM, LEONARD Julien (Consulting for ACCOR Hotels)
<ju...@consulting-for.accor.com> wrote:
> Did you try :
>
> MyObject theObject;
> (geter and setter on theObject)
>
> execute () {
>
>     theObject = myDAO.getRecord(id);
> }
>
> And in the JSP : <s:property value="theObject.member1"/>
>
> -----Message d'origine-----
> De : Richard Sayre [mailto:richardsayre@gmail.com]
> Envoyé : vendredi 1 février 2008 13:37
> À : Struts Users Mailing List
> Objet : Populate Form from DAO
>
>
> Struts 2 allows us to automatically populate our forms if we name our fields correctly, which is wonderful.
>
> My actions usually go something like this
>
> execute () {
>
>     MyObject o = myDAO.getRecord(id);
>
>    member1 = o.getMember1();
>    member2 = o.getMember2();
>
> }
>
> MyObject is a JO for hold a row in the database.  I like the fact that I can name my form field 'member1' and it the interceptor will set and get from my Action.  I dont like having to set up each member variable in the action with the members my class.  Is it possible to somehow have Struts automatically populate an Java Object rather then the Action?  I thought I remember reading about this before but I'm not sure.  It's not a big deal, and I know I can use OGNL to access the value, but I wanted the convience of mapping a fieldName to my custom object.  Is this possible?
>
> Thank you,
>
> Rich
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
>
> This e-mail, any attachments and the information contained therein ("this message") are confidential and intended solely for the use of the addressee(s). If you have received this message in error please send it back to the sender and delete it. Unauthorized publication, use, dissemination or disclosure of this message, either in whole or in part is strictly prohibited.
> **********************************************************************
> Ce message électronique et tous les fichiers joints ainsi que  les informations contenues dans ce message ( ci après "le message" ), sont confidentiels et destinés exclusivement à l'usage de la  personne à laquelle ils sont adressés. Si vous avez reçu ce message par erreur, merci  de le renvoyer à son émetteur et de le détruire. Toutes diffusion, publication, totale ou partielle ou divulgation sous quelque forme que se soit non expressément autorisées de ce message, sont interdites.
> **********************************************************************
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

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


RE: Populate Form from DAO

Posted by "LEONARD Julien (Consulting for ACCOR Hotels)" <ju...@consulting-for.accor.com>.
Did you try :

MyObject theObject;
(geter and setter on theObject)

execute () {

    theObject = myDAO.getRecord(id);
} 

And in the JSP : <s:property value="theObject.member1"/>

-----Message d'origine-----
De : Richard Sayre [mailto:richardsayre@gmail.com] 
Envoyé : vendredi 1 février 2008 13:37
À : Struts Users Mailing List
Objet : Populate Form from DAO

Struts 2 allows us to automatically populate our forms if we name our fields correctly, which is wonderful.

My actions usually go something like this

execute () {

    MyObject o = myDAO.getRecord(id);

   member1 = o.getMember1();
   member2 = o.getMember2();

}

MyObject is a JO for hold a row in the database.  I like the fact that I can name my form field 'member1' and it the interceptor will set and get from my Action.  I dont like having to set up each member variable in the action with the members my class.  Is it possible to somehow have Struts automatically populate an Java Object rather then the Action?  I thought I remember reading about this before but I'm not sure.  It's not a big deal, and I know I can use OGNL to access the value, but I wanted the convience of mapping a fieldName to my custom object.  Is this possible?

Thank you,

Rich

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



This e-mail, any attachments and the information contained therein ("this message") are confidential and intended solely for the use of the addressee(s). If you have received this message in error please send it back to the sender and delete it. Unauthorized publication, use, dissemination or disclosure of this message, either in whole or in part is strictly prohibited.
********************************************************************** 
Ce message électronique et tous les fichiers joints ainsi que  les informations contenues dans ce message ( ci après "le message" ), sont confidentiels et destinés exclusivement à l'usage de la  personne à laquelle ils sont adressés. Si vous avez reçu ce message par erreur, merci  de le renvoyer à son émetteur et de le détruire. Toutes diffusion, publication, totale ou partielle ou divulgation sous quelque forme que se soit non expressément autorisées de ce message, sont interdites.
********************************************************************** 


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