struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Boyalla, Raveendra" <Raveendra.Boya...@dfa.state.ny.us>
Subject DynaActionForm and Nested property -- (to Craig)
Date Fri, 05 Jul 2002 15:59:54 GMT
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 <jimc@Infogain.co.uk>
> Reply-To: Struts Users Mailing List <struts-user@jakarta.apache.org>
> To: "'struts-user@jakarta.apache.org'" <struts-user@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 <mailto:jimc@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:
<mailto:struts-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail:
<mailto:struts-user-help@jakarta.apache.org>

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


Mime
View raw message