Return-Path: Delivered-To: apmail-jakarta-struts-user-archive@apache.org Received: (qmail 2862 invoked from network); 2 Sep 2002 10:56:56 -0000 Received: from unknown (HELO nagoya.betaversion.org) (192.18.49.131) by daedalus.apache.org with SMTP; 2 Sep 2002 10:56:56 -0000 Received: (qmail 2378 invoked by uid 97); 2 Sep 2002 10:57:12 -0000 Delivered-To: qmlist-jakarta-archive-struts-user@jakarta.apache.org Received: (qmail 2362 invoked by uid 97); 2 Sep 2002 10:57:11 -0000 Mailing-List: contact struts-user-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Struts Users Mailing List" Reply-To: "Struts Users Mailing List" Delivered-To: mailing list struts-user@jakarta.apache.org Received: (qmail 2350 invoked by uid 98); 2 Sep 2002 10:57:11 -0000 X-Antivirus: nagoya (v4218 created Aug 14 2002) Message-ID: From: Darryl Nortje To: 'Struts Users Mailing List' Subject: RE: Dynamic name to the text fields Date: Mon, 2 Sep 2002 12:48:37 +0200 MIME-Version: 1.0 X-Mailer: Internet Mail Service (5.5.2655.55) Content-Type: text/plain; charset="iso-8859-1" X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N Anoop, I did it by iterating through a collection of beans, each bean in the collection for eg had a getKey() and getValue() method then the jsp looks like this. "/> It's very simple but it works.... cheers Darryl -----Original Message----- From: Donald Ball [mailto:dball@rhoworld.com] Sent: Friday, August 30, 2002 4:44 PM To: struts-user@jakarta.apache.org; anoopra@india.hp.com Subject: Re: Dynamic name to the text fields On 8/30/2002 at 7:28 PM Anoop wrote: >Hi All, > > I am a newbie to struts and taglibs, was trying to display text fields >dynamically using "html:iterator". Below is the scenario I was >trying out. You may be in luck, I've been recently trying to learn how to do something similar myself. >The html snippet for the above is something like: > > > > >But I want it to be something like: > > > > >Where the values("a" & "b") for the name attribute comes from an array >defined in the Form Bean. What are the changes required in my jsp snippet? > >Also, if only it is possible to get an output as desired, does the FormBean >be modified to support this. As there won't be any getter/setter for "a" >and >"b". > >Appreciate any kind of help regarding this. First, google around for "map-backed ActionForms" or similar. There's some stuff over on jguru that might be helpful. Also, I'm trying to write documentation for the struts user's guide for this, so I'd appreciate your comments on how (un)clear the following is (apologies for the formatting, my mail client sucks):

The DynaActionForm classes offer the ability to create ActionForm beans at initialization time, based on a list of properties enumerated in the struts configuration file. However, many HTML forms are generated dynamically at request-time. Their ActionForm beans' properties are not all known ahead of time, so we need a new approach.

Struts allows you to make one (or more) of your ActionForm's properties ' values a Map instead of a traditional atomic object. You can then store your form's dynamic fields' data in that Map. Here is an example of a map-backed ActionForm class:


In its corresponding JSP page, you can access objects stored in the values map using a special notation: mapname(keyname). The parantheses in the bean property name serve to indicate that the bean property named mapname should be a Map, and that struts should look at the value stored with the key keyname in that Map to find the "real" property for mapname(keyname).

Here is a simple example:


]]>

This will call the getValue() method on FooForm with a key value of "foo" to find the property value. To create a form with dynamic field names, you might do something like this:

"/>
%> ]]>
Hope it helps, thanks in advance for any comments. - donald -- To unsubscribe, e-mail: For additional commands, e-mail: -- To unsubscribe, e-mail: For additional commands, e-mail: