Thanks for all the help John.
I could work it out tweaking on your solution.

Regards,
Nitesh

----- Original Message ----- From: "John Fitzpatrick" <[EMAIL PROTECTED]>
To: "Struts Users Mailing List" <user@struts.apache.org>
Sent: Friday, June 03, 2005 6:06 PM
Subject: Re: Problem using indexed properties and validator framework


In the struts-config.xml:

   <form-bean name="ManageAccountsForm" type="application.EditUsersForm">
       <form-property name="users" type="application.UserBean[]">
   </form-bean>


   <action-mappings>
   <action
     path="/application/EditUsers"
     type="application.EditUsersAction"
     name="EditUsersForm"
     scope="session"
   >
     <forward
       name="success"
       path="editUsers.jsp"
       redirect="false"
     />
   <action-mappings>


In EditUsersAction.java execute method

   // get collection of users from the database
   Collection users = getUserBeans ();

   // put collection into form as an array for editing
   form.set ( "users", users.toArray ( new UserBean[0] ) );

In editUsers.jsp

   <logic:iterate id="users" name="EditUsersForm" property="users">
       <html:text name="users" property="name" indexed="true">
   </logic:iterate>

In the produced HTML:

   <input type="text" name="users[0].name" />

If you need to client side validation, you'll probably need to write your
own JSP to deal with the element above.

As for using validate.xml to validate on the server side. I've never tried
it with arrays, I just iterate over them in the validate (...) method of the
form, like so:

   UserBean users[] = (UserBean[]) form.get ( "users" );
   for ( int i = 0; i < users.length; i++ ) {
       // check on the attributes of UserBean users[i]
   }

Hope that example clears it up for you.

John



On 20050603 5:05 AM, "Nitesh" <[EMAIL PROTECTED]> wrote:

Thanks for the answer John...

Could you give me an example as to how we pre populate the array?

Regards,
Nitesh
----- Original Message -----
From: "John Fitzpatrick" <[EMAIL PROTECTED]>
To: "Struts Users Mailing List" <user@struts.apache.org>
Sent: Thursday, June 02, 2005 6:00 PM
Subject: Re: Problem using indexed properties and validator framework



For an Array in a DynaForm property, you can either set the size in the
form-property descriptor or, in the case of a session form, pre-populate
the
Array in your action with the number of elements you desire.




---------------------------------------------------------------------
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