You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Thomas Thomas <de...@gmail.com> on 2006/12/03 15:35:55 UTC

getting formbean properties in Action class

Hi,

To get the properties these two ways work :

1) System.out.println("lastName   = " + custForm.get("login"));

2) System.out.println("lastName   = " + request.getParameter("login"));

Why should I use 1) rather than 2) ?

Thank u.

Re: getting formbean properties in Action class

Posted by Chris Pratt <th...@gmail.com>.
At that level there really isn't an advantage.  The advantage comes in when
you use Struts' abiltity to traverse nested beans.  In other words if you
create an ActionForm that has some bean attributes you Struts will manage
all that complexity for you.  Maybe an example:

public class DateBean {
  private int day;
  private int month;
  private int year

    // assume there are accessors and mutators for each of the attributes
  }

--=< From Struts Config >=--
<form-bean name="MyForm" type="com.vsp.canada.controller.DynaForm">
  <form-property name="date" type="DateBean" initial="0"/>
</form-bean>

--=< From the JSP >=--

<html:text property="date.day" size="2" maxlength="2"/>
<html:text property="date.month" size="2" maxlength="2"/>
<html:text property="date.year" size="4" maxlength="4"/>

--=< From your Action >=--
DynaActionForm data = (DynaActionForm)form;
DateBean = ((DateBean)data.get("date"))

Using this you can have the three form fields in the JSP handled as a single
object in Java.
  (*Chris*)



On 12/3/06, Nuwan Chandrasoma <my...@gmail.com> wrote:
>
> Hi,
>
> I use the property utils,
>
> PropertyUtils.getSimpleProperty(aForm, "exchange");
>
> PropertyUtils.seetSimpleProperty(aForm, "exchange","NASDAQ");
>
> Thanks,
>
> Nuwan.
>
>
> ----- Original Message -----
> From: "Thomas Thomas" <de...@gmail.com>
> To: "Struts Users Mailing List" <us...@struts.apache.org>
> Sent: Sunday, December 03, 2006 2:35 PM
> Subject: getting formbean properties in Action class
>
>
> > Hi,
> >
> > To get the properties these two ways work :
> >
> > 1) System.out.println("lastName   = " + custForm.get("login"));
> >
> > 2) System.out.println("lastName   = " + request.getParameter("login"));
> >
> > Why should I use 1) rather than 2) ?
> >
> > Thank u.
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

Re: getting formbean properties in Action class

Posted by Nuwan Chandrasoma <my...@gmail.com>.
Hi,

I use the property utils,

PropertyUtils.getSimpleProperty(aForm, "exchange");

PropertyUtils.seetSimpleProperty(aForm, "exchange","NASDAQ");

Thanks,

Nuwan.


----- Original Message ----- 
From: "Thomas Thomas" <de...@gmail.com>
To: "Struts Users Mailing List" <us...@struts.apache.org>
Sent: Sunday, December 03, 2006 2:35 PM
Subject: getting formbean properties in Action class


> Hi,
> 
> To get the properties these two ways work :
> 
> 1) System.out.println("lastName   = " + custForm.get("login"));
> 
> 2) System.out.println("lastName   = " + request.getParameter("login"));
> 
> Why should I use 1) rather than 2) ?
> 
> Thank u.
>

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