struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Heligon Sandra <>
Subject RE: How define a DynaActionForm to display a collection ?
Date Wed, 19 Mar 2003 09:48:48 GMT
Thanks a lot for your example, it is exactly what I wish to do. 
The JSP code with the tag logic:iterate helped me much.
I still have nevertheless a problem. 

When I run the application I have the error:
[ServletException in: /pages/MyPage.jsp]I do not know how to iterate over
'class java.lang.String'.' 

It is probably the code of the action that populates the form
that is bad.
For your example I will write:

public ActionForward executeAction(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) throws Exception 
    Collection beans = new ArrayList();
    ItemBean bean1 = new ItemBean();

    ItemBean bean2 = new ItemBean();
    // Populate the form from the business data values

The action that populates the form is not the action
The action process the form, isn't it ?

Thanks a lot in advance for your help.


As of February 12th, 2003 Thomson unifies its email addresses on a worldwide
Please note my new email address: 

----Original Message-----
From: harish krishnaswamy []
Sent: 18 March 2003 19:30
To: Struts Users Mailing List
Subject: RE: How define a DynaActionForm to display a collection ?

After spending quite sometime on the collection-backed
form properties solution, I figured its worth
mentioning the solution I dug out. I have to say that
the documentation on this one is pretty sparse. Ok
here we go...

I have a jsp that needs to accept an order for items.
This jsp has single-occurence fields like customer
name and address and multi-occurence fields like item
id, item name and item price. The later is the focus
of this message. I have created a plain java bean for
the multi-occurence fileds called ItemBean.

public class ItemBean {
  public ItemBean() {
  public void setId(int id) { = id;
  public int getId() {
    return this.itemId;
  public void setName(String name) { = name;
  public String getName() {
  public void setPrice(double price) {
    this.price = price;
  public double getPrice() {
    return this.price;

I have created a DynaActionForm bean as follows:

<form-bean name="orderForm" dynamic="true"   
  <form-property name="name" type="java.lang.String"/>
  <form-property name="address" 
  <form-property name="itemBeans" 
  <form-property name="event"

And I have a jsp like shown below:

<html:form action="">

Name: <html:text property="name"/>&nbsp;
Address: <html:text property="address"/>



<logic:iterate id="itemBeans" indexId="idx" 
  name="orderForm" property="itemBeans" 

<td><html:text name="itemBeans" property="id" 
<td><html:text name="itemBeans" property="name" 
  size="50" indexed="true"/></td>
<td><html:text name="itemBeans" property="price" 


<td><html:submit value="Save" 
<td><html:submit value="Add" 

<html:hidden property="event"/>


Notice that the values of "id" and "property"
attributes of the <logic:iterate> tag are the same.
This is what makes the name of the html text fields to
evaluate to the right format, which is:
itemBeans[n].id for the id field. This "itemBeans" is
the name of the indexed-property in the form bean. The
"event" field is used by DispatchAction.

Hope this was helpful to atleast someone.


 Heligon Sandra <> wrote:
I have an other question if I use a sub-class of DynaValidatorForm 
and define the form-bean in the struts-config file with:

dynamic="true" type="">

How do I write my JSP page ?


Is this the good manners to make? 


As of February 12th, 2003 Thomson unifies its email addresses on a worldwide
Please note my new email address: 

----Original Message-----
From: Heligon Sandra 
Sent: 18 March 2003 13:43
To: 'Struts Users Mailing List'
Subject: RE: How define a DynaActionForm to display a collection ?
Importance: High

If I define a sub-class of DynaValidatorForm I just have to add
two methods to access to the list parameter, isn't it ?

public final class MyDynaForm extends DynaValidatorForm {

private ArrayList list;

public MyDynaForm () 
list = new ArrayList();
ConfProp props = new ConfProp();
Vector v = props.getMeterHosts();
for (int i=0; i list.add(v.elementAt(i));

public ArrayList getList() {
return list;

public void setList(ArrayList list) {
this.list = list;

I will wish to be certain that it is the best way to display a
collection in DynaValidatorForm 
because I have a doubt in a message of the archives I read: 
The only reason you would ever need to create a real class that extends
DynaActionForm or DynaValidatorForm would be if you need a custom
or validate() method. 

What do you think about it? 

-----Original Message-----
From: Rick Reumann []
Sent: 11 March 2003 18:18
To: Struts Users Mailing List
Subject: Re: How define a DynaActionForm to display a collection ?

On Tue, 11 Mar 2003 17:36:09 +0100
Heligon Sandra wrote:

> Has someone an example of struts-config.xml file and
> a such SetUpAction with DynaActionForm and Collection ?

In a form-bean declarations, where YourDyanForm is a subclass of a

dynamic="true" type="">

{ snip }

{ snip }

Then in you Action class...

execute(..) {
ArrayList someList = someBusinessClass.getMeListOfObjectsIneed();
formBean.set("myCollection" someList );

//forward to jsp page

The reason you'll want to subclass DynaActionForm is if you do some
validation you probably will have to override the reset method. 

Rick Reumann

To unsubscribe, e-mail:
For additional commands, e-mail:

Do you Yahoo!?
Yahoo! Platinum - Watch CBS' NCAA March Madness, live on your desktop!

  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message