OK, then I repeat my earlier answer - use (or at least look at) the "Lazy"
versions I wrote.

http://www.niallp.pwp.blueyonder.co.uk/

<form-bean name="SampleMain" dynamic="true"
     type="lib.framework.util.LazyValidatorForm"/>

is all it needs.


If you look at the get(String name, int index) method in LazyValidatorForm,
then it generates an ArrayList of LazyDynaBeans.


Niall



----- Original Message ----- 
From: "Nathan Ewing" <[EMAIL PROTECTED]>
To: "Struts Users Mailing List" <[EMAIL PROTECTED]>
Sent: Wednesday, April 21, 2004 10:51 PM
Subject: RE: Creating an indexed property of DynaActionForms


Let me rephrase :)

"its MUCH easier to save these records to the database if everything is
represented as DynaBeans"

That would be what I meant to say :)

I'm writing the Actions separately, they are not Dyna-anything.  I
defined all my beans as DynaBeans in the struts-config.xml file, and I
wrote some code that allows me to make one call to save a dynabean
straight to my database, which I call in my Action.

Where I'm running into trouble is when I want to embed one dynabean
inside another (like my example below, where I want to write to multiple
database records off the same form).

How could I make this work?  Writing regular non-dynbeans would multiply
maintenance incredibly.

Nathan

-----Original Message-----
From: Niall Pemberton [mailto:[EMAIL PROTECTED]
Sent: Wednesday, April 21, 2004 5:08 PM
To: Struts Users Mailing List
Subject: Re: Creating an indexed property of DynaActionForms

DynaActionForm is an ActionForm that implements the DynaBean interface.
I
would understand if you said its " MUCH easier to save these records to
the
database if everything is
represented as DynaBeans", but not DynaForms - why would you need it to
be
an ActioForm as well as a DynaBean and not just a DynaBean.

Its the implementation of the DynaBean interface in DynaActioForm that
makes
it "Dyna", the ActionForm bit is just for struts.

The "lazy" stuff I wrote caters for exactly the scenario you talk about,
but
with DynaBeans.

Niall


----- Original Message ----- 
From: "Nathan Ewing" <[EMAIL PROTECTED]>
To: "Struts Users Mailing List" <[EMAIL PROTECTED]>
Sent: Wednesday, April 21, 2004 9:44 PM
Subject: RE: Creating an indexed property of DynaActionForms


Lemme give an example, Lets say I have a form for Cars.  The main form
allows them to put in the details of the Car (make, model, year, etc).
Then there is a subform to put in car parts.  When you fill out the car
part form, it automatically adds that car part to the list of car parts
on the main form.  You can then go back to the main form later, and
check off the parts of the car you have, and when you hit save on the
main form, it automatically saves the obtained status for each car part.

Basically a Main form with a dynamically generated list of items as part
of the form.

It is MUCH easier to save these records to the database if everything is
represented as DynaForms.


-----Original Message-----
From: Niall Pemberton [mailto:[EMAIL PROTECTED]
Sent: Wednesday, April 21, 2004 4:27 PM
To: Struts Users Mailing List
Subject: Re: Creating an indexed property of DynaActionForms

I don't understand why you need ActionForms embedded in your main
ActionForm - don't these "sub forms" just need to be some sort of
DynaBeans
rather than ActionForm?

If you want to use the "Lazy" versions, then just make it your main
ActionForm:

<form-bean name="SampleMain" dynamic="true"
     type="lib.framework.util.LazyValidatorForm"/>

Then in your jsp

   <html:text property="subForm1[${status.index}].property1" size="5" />
   <html:text property="subForm1[${status.index}].property2" size="5" />

Should populate an ArrayList of LazyDynaBeans containing property1 and
property2


Niall

----- Original Message ----- 
From: "Nathan Ewing" <[EMAIL PROTECTED]>
To: "Struts Users Mailing List" <[EMAIL PROTECTED]>
Sent: Wednesday, April 21, 2004 8:53 PM
Subject: RE: Creating an indexed property of DynaActionForms


I tried replacing the <form-property name="subForm1" type="SubForm[]"/>
with:

<form-property name="subForm1" type="com.mysite.LazyValidatorForm[]"/>

And I get the following when I hit the submit button on my form:

Root Cause

java.lang.ArrayIndexOutOfBoundsException
at java.lang.reflect.Array.get(Native Method)
at
org.apache.struts.action.DynaActionForm.get(DynaActionForm.java:296)
at
org.apache.commons.beanutils.PropertyUtils.getIndexedProperty(PropertyUt
ils.java:474)
at
org.apache.commons.beanutils.PropertyUtils.getIndexedProperty(PropertyUt
ils.java:428)
at
org.apache.commons.beanutils.PropertyUtils.getNestedProperty(PropertyUti
ls.java:770)
at
org.apache.commons.beanutils.PropertyUtils.getProperty(PropertyUtils.jav
a:801)
at
org.apache.commons.beanutils.BeanUtils.setProperty(BeanUtils.java:881)
at
org.apache.commons.beanutils.BeanUtils.populate(BeanUtils.java:808)
at
org.apache.struts.util.RequestUtils.populate(RequestUtils.java:1252)
at
org.apache.struts.action.RequestProcessor.processPopulate(RequestProcess
or.java:821)
at
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:
254)
at
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
at
org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:525)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)

-----Original Message-----
From: Takhar, Sandeep [mailto:[EMAIL PROTECTED]
Sent: Wednesday, April 21, 2004 7:44 AM
To: Struts Users Mailing List
Subject: RE: Creating an indexed property of DynaActionForms

Use the lazyValidatorActionForm, which allows you to keep things request
scope when using arrays.

http://www.niallp.pwp.blueyonder.co.uk/

<form-bean name="SampleMain"
type="org.apache.struts.validator.DynaValidatorForm">
    <form-property name="subForm1" type="java.util.ArrayList"/>
    <form-property name="subForm2" type="java.util.ArrayList"/>
</form-bean>

Unfortunately I haven't tried this, but am pretty sure it works.


sandeep
-----Original Message-----
From: Nathan Ewing [mailto:[EMAIL PROTECTED]
Sent: Tuesday, April 20, 2004 5:49 PM
To: [EMAIL PROTECTED]
Subject: Creating an indexed property of DynaActionForms


I'm trying to figure out how to define and use a DynaActionForm which
has an indexed property that is another DynaActionForm.  I'm using
struts 1.1.  Here is something like what I mean:

First my sample struts-config.xml
----------------------------------
<form-bean name="SubForm"
type="org.apache.struts.validator.DynaValidatorForm">
<form-property name="property1"
type="java.lang.String"/>
<form-property name="property2"
type="java.lang.String"/>
</form-bean>

<form-bean name="SampleMain"
type="org.apache.struts.validator.DynaValidatorForm">
    <form-property name="subForm1" type="SubForm[]"/>
    <form-property name="subForm2" type="SubForm[]"/>
</form-bean>

And the JSP:
------------------

<table>
<c:forEach var="subForm1" items="${SampleMain.map.subForm1}"
varStatus="status">
<tr>
    <td><html:text
property="subForm1[${status.index}].property1" size="5" />

    <td><html:text
property="subForm1[${status.index}].property2" size="5" />
</tr>
</c:forEach>
</table>

Unfortunately this doesn't work.  If I try making the subtypes SubForm[]
like above, I get a NullPointer exception when I try to start the
server, when struts tries to create the DynaForm classes.

If I make the property type Object[], I can successfully populate the
form, but when I try to save it, I get an ArrayOutOfBounds error when
struts tries to create the initial DynaForms (Obviously because it has
no idea what type of form to create, I think).

How do I make this work?

Also, once I start implementing validation on this form, is it going to
be possible to use struts validation to validate the subitems?

Thanks,
Nathan


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]





---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]





---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]





---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to