You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by "Boyalla, Raveendra" <Ra...@dfa.state.ny.us> on 2002/07/05 17:59:54 UTC

DynaActionForm and Nested property -- (to Craig)

Hi Craig,

this is my form bean.


<form-bean      name="addPCCompanyForm"
                    type="org.apache.struts.action.DynaActionForm">
		
		<form-property name="pcCompany"
type="rb.pc.vo.pcCompanies.PCCompanyVO"/>
		
    </form-bean>



and in form 

<html:text property="pcCompany.companyName" size="30" maxlength="30"/> 


java.lang.IllegalArgumentException: Null property value for 'pcCompany'
	at
org.apache.commons.beanutils.PropertyUtils.getNestedProperty(PropertyUtils.j
ava:693)
	at
org.apache.commons.beanutils.PropertyUtils.getProperty(PropertyUtils.java:74
1)
	at org.apache.struts.util.RequestUtils.lookup(RequestUtils.java:723)


It seems I need to initialize form-bean   property pcCompany to new
rb.pc.vo.pcCompanies.PCCompanyVO().


Please help me out so that I can change all my form beans to DynaActionForm
having nested properties.

Thanks to Struts Authors for making life easier.

Raveendra Boyalla




-----Original Message-----
From: Craig R. McClanahan [mailto:craigmcc@apache.org]
Sent: Thursday, July 04, 2002 1:30 PM
To: Struts Users Mailing List
Subject: Re: should I use form bean and javabean for the same data?




On Thu, 4 Jul 2002, Jim Clayson wrote:

> Date: Thu, 4 Jul 2002 17:58:03 +0100
> From: Jim Clayson <ji...@Infogain.co.uk>
> Reply-To: Struts Users Mailing List <st...@jakarta.apache.org>
> To: "'struts-user@jakarta.apache.org'" <st...@jakarta.apache.org>
> Subject: should I use form bean and javabean for the same data?
>
> Hi,
>
> I read somewhere on this list sometime ago that one should bear in mind
that
> struts form beans should be considered to be part of the view in your
> run-of-the-mill MVC struts app and that they should only be used for
> prepopulating a form and/or reporting surface level validation errors.
>
> Does this mean that I shouldn't ever be setting the values on the form
bean
> inside my action class or wherever I perform my business logic? If this is
> true (and please could someone confirm this), should I be using a vanilla
> javabean to model the data for use outside of the view?
>

It's hard to be very descriptive without a particular example, but in
general I would say that model-tier data is generally exposed to the view
tier as JavaBeans.  If you are using some of the popular design patterns
for multi-tier applications (such as those in "Core J2EE Patterns" by
Alur/Crupi/Malks), this object will typically be a Data Access Object, or
a Value Object, or (a more current term) Data Transfer Object.

It's ok to expose model data directly to the view tier for display-only
use, by saving it in a request or session attribute where the view page
can get to it.  For the incoming data that modifies things, I generally
set up my applications like this:

* "Setup" action creates and prepopulates the form bean, as well
  as setting up any other beans that are needed for the display.
  It then forwards to the "input form" page.

* The "input form" page as an <html:form> tag pointing at the
  "Process" action, with input fields that match the properties
  of the corresponding form bean.  In most cases, the properties
  of the form bean will be strings.

* The form bean has a validate() method to check for things like
  required fields and conversion errors (such as entering "1a3"
  into a field destined to be an integer).  If any errors are found,
  Struts redisplays the "input form" page for you, with the exact
  values that the user entered (even if they were wrong).  Note that
  we have *not* corrupted any model tier objects with invalid data.

* The "Process" action is called only after validation is successful.
  It can perform any additional checks it needs, and then interacts
  with the business objects to perform whatever updates are needed.
  (In trivially simple Struts apps, the business logic is sometimes
  embedded in the Action -- it's better to segregate this logic into
  separate business objects, though).

* At this point, the form bean gets thrown away, because it has
  completed its purpose.  For request-scope form beans, this happens
  automatically when the request completes.  For session-scope form
  beans, you have to deliberately remove the coresponding session
  attribute.

> Maybe I'm missing something here.
>
> Any assistance will be much appreciated.
>
> Jim
>

Craig


> __________________________________________________________
>
> <?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office"
/>
>
> Jim Clayson
>
>
> Infogain Limited
>
>
> tel: 01628 580600
> fax: 01628 580610
> email: jimc@infogain.co.uk <ma...@infogain.co.uk>
> web: www.infogain.com <http://www.infogain.com/>
>
>
>
> Disclaimer:  Neither this e-mail nor any attachment places any legal or
> contractual obligations on Infogain Limited. Any reproduction, disclosure
or
> dissemination beyond the intended addressees is strictly prohibited save
for
> the legitimate business purposes of Infogain Limited and its clients or
> partners.
>
> __________________________________________________________
>
>
>
>


--
To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
For additional commands, e-mail:
<ma...@jakarta.apache.org>

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: DynaActionForm and Nested property -- (to Craig)

Posted by Chuck Cavaness <ch...@attbi.com>.
Thanks for catching me on that. I looked at the form-bean element twice and 
still thought there was a custom impl there, but that was actually the type 
attribute.

Sorry for the confusion.
chuck

At 12:42 PM 7/5/2002 -0700, you wrote:


>On Fri, 5 Jul 2002, Chuck Cavaness wrote:
>
> > Date: Fri, 05 Jul 2002 15:32:13 -0400
> > From: Chuck Cavaness <ch...@attbi.com>
> > Reply-To: Struts Users Mailing List <st...@jakarta.apache.org>
> > To: Struts Users Mailing List <st...@jakarta.apache.org>
> > Subject: Re: DynaActionForm and Nested property -- (to Craig)
> >
> > Raveendra,
> >
> >    I was reading your email and just thought I would mention something that
> > I saw that may be a hard bug to find later. When using dynamic forms, you
> > have to set the "dynamic" attribute to true, like this:
> >
> > ><form-bean name="addPCCompanyForm"  dynamic="true"
> > >type="org.apache.struts.action.DynaActionForm">>
> > >   <form-property name="pcCompany" 
> type="rb.pc.vo.pcCompanies.PCCompanyVO"/>>
> > ></form-bean>
> >
> >
> > Just wanted to point that out in case you didn't see it.
> >
>
>Actually, you don't need to do this if you use the standard implementation
>class (org.apache.struts.action.DynaActionForm).  It is only required on
>your own custom subclasses of DynaActionForm.
>
> > Chuck
>
>Craig
>
>
>--
>To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
>For additional commands, e-mail: <ma...@jakarta.apache.org>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: DynaActionForm and Nested property -- (to Craig)

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

On Fri, 5 Jul 2002, Chuck Cavaness wrote:

> Date: Fri, 05 Jul 2002 15:32:13 -0400
> From: Chuck Cavaness <ch...@attbi.com>
> Reply-To: Struts Users Mailing List <st...@jakarta.apache.org>
> To: Struts Users Mailing List <st...@jakarta.apache.org>
> Subject: Re: DynaActionForm and Nested property -- (to Craig)
>
> Raveendra,
>
>    I was reading your email and just thought I would mention something that
> I saw that may be a hard bug to find later. When using dynamic forms, you
> have to set the "dynamic" attribute to true, like this:
>
> ><form-bean name="addPCCompanyForm"  dynamic="true"
> >type="org.apache.struts.action.DynaActionForm">>
> >   <form-property name="pcCompany" type="rb.pc.vo.pcCompanies.PCCompanyVO"/>>
> ></form-bean>
>
>
> Just wanted to point that out in case you didn't see it.
>

Actually, you don't need to do this if you use the standard implementation
class (org.apache.struts.action.DynaActionForm).  It is only required on
your own custom subclasses of DynaActionForm.

> Chuck

Craig


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: DynaActionForm and Nested property -- (to Craig)

Posted by Chuck Cavaness <ch...@attbi.com>.
Raveendra,

   I was reading your email and just thought I would mention something that 
I saw that may be a hard bug to find later. When using dynamic forms, you 
have to set the "dynamic" attribute to true, like this:

><form-bean name="addPCCompanyForm"  dynamic="true" 
>type="org.apache.struts.action.DynaActionForm">>
>   <form-property name="pcCompany" type="rb.pc.vo.pcCompanies.PCCompanyVO"/>>
></form-bean>


Just wanted to point that out in case you didn't see it.

Chuck



At 11:09 AM 7/5/2002 -0700, you wrote:


>On Fri, 5 Jul 2002, Boyalla, Raveendra wrote:
>
> > Date: Fri, 5 Jul 2002 11:59:54 -0400
> > From: "Boyalla, Raveendra" <Ra...@dfa.state.ny.us>
> > Reply-To: Struts Users Mailing List <st...@jakarta.apache.org>
> > To: 'Struts Users Mailing List' <st...@jakarta.apache.org>
> > Subject: DynaActionForm and Nested property -- (to Craig)
> >
> > Hi Craig,
> >
> > this is my form bean.
> >
> >
> > <form-bean      name="addPCCompanyForm"
> >                     type="org.apache.struts.action.DynaActionForm">
> >
> >               <form-property name="pcCompany"
> > type="rb.pc.vo.pcCompanies.PCCompanyVO"/>
> >
> >     </form-bean>
> >
> >
> >
> > and in form
> >
> > <html:text property="pcCompany.companyName" size="30" maxlength="30"/>
> >
> >
> > java.lang.IllegalArgumentException: Null property value for 'pcCompany'
> >       at
> > 
> org.apache.commons.beanutils.PropertyUtils.getNestedProperty(PropertyUtils.j
> > ava:693)
> >       at
> > 
> org.apache.commons.beanutils.PropertyUtils.getProperty(PropertyUtils.java:74
> > 1)
> >       at org.apache.struts.util.RequestUtils.lookup(RequestUtils.java:723)
> >
> >
> > It seems I need to initialize form-bean   property pcCompany to new
> > rb.pc.vo.pcCompanies.PCCompanyVO().
> >
>
>Yep ... you sure do.
>
> >
> > Please help me out so that I can change all my form beans to DynaActionForm
> > having nested properties.
> >
>
>The approach I generally take is to do this sort of thing is to subclass
>DynaActionForm with a class that only has a reset() method (and optionally
>a validate() method if you need one), and do the setup in reset().  This
>works because reset() is always called when Struts creates an instance of
>this form bean for you (in 1.1 -- it wasn't always true in 1.0), so it
>makes a good spot to do initialization like this.
>
> > Thanks to Struts Authors for making life easier.
> >
>
>You're welcome :-).
>
> > Raveendra Boyalla
> >
>
>Craig
>
>
>--
>To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
>For additional commands, e-mail: <ma...@jakarta.apache.org>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: DynaActionForm and Nested property -- (to Craig)

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

On Fri, 5 Jul 2002, Boyalla, Raveendra wrote:

> Date: Fri, 5 Jul 2002 11:59:54 -0400
> From: "Boyalla, Raveendra" <Ra...@dfa.state.ny.us>
> Reply-To: Struts Users Mailing List <st...@jakarta.apache.org>
> To: 'Struts Users Mailing List' <st...@jakarta.apache.org>
> Subject: DynaActionForm and Nested property -- (to Craig)
>
> Hi Craig,
>
> this is my form bean.
>
>
> <form-bean      name="addPCCompanyForm"
>                     type="org.apache.struts.action.DynaActionForm">
>
> 		<form-property name="pcCompany"
> type="rb.pc.vo.pcCompanies.PCCompanyVO"/>
>
>     </form-bean>
>
>
>
> and in form
>
> <html:text property="pcCompany.companyName" size="30" maxlength="30"/>
>
>
> java.lang.IllegalArgumentException: Null property value for 'pcCompany'
> 	at
> org.apache.commons.beanutils.PropertyUtils.getNestedProperty(PropertyUtils.j
> ava:693)
> 	at
> org.apache.commons.beanutils.PropertyUtils.getProperty(PropertyUtils.java:74
> 1)
> 	at org.apache.struts.util.RequestUtils.lookup(RequestUtils.java:723)
>
>
> It seems I need to initialize form-bean   property pcCompany to new
> rb.pc.vo.pcCompanies.PCCompanyVO().
>

Yep ... you sure do.

>
> Please help me out so that I can change all my form beans to DynaActionForm
> having nested properties.
>

The approach I generally take is to do this sort of thing is to subclass
DynaActionForm with a class that only has a reset() method (and optionally
a validate() method if you need one), and do the setup in reset().  This
works because reset() is always called when Struts creates an instance of
this form bean for you (in 1.1 -- it wasn't always true in 1.0), so it
makes a good spot to do initialization like this.

> Thanks to Struts Authors for making life easier.
>

You're welcome :-).

> Raveendra Boyalla
>

Craig


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>