Re: Dynamic number of form fields

2002-09-11 Thread John Averty

Yep, I think you're right. That was worth a try though ;-)

Thanks,

John.

- Original Message -
From: "Donald Ball" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]>;
<[EMAIL PROTECTED]>
Sent: Wednesday, September 11, 2002 3:24 PM
Subject: Re: Dynamic number of form fields


> On 9/11/2002 at 3:20 PM John Averty wrote:
>
> >Duuh! Sorry about that.
> >
> >
> >I'd like to bring it one step further: I'd like to be able to set the
> >corresponding field type.
> >
> >Would the following work?
> >
> >
> ><% for (int i=0; i<10; i++) {
> >
> >  String name = "value(foo-" + i + ")";
> >  String type = "type(foo-" + i + ")";
> >   property="<%=name%>"/>
> >%>
>
> Almost certainly not. If you want to dynamically choose a different type
of
> element, I think you basically need to fake a switch statement with a
bunch
> of logic:equals elements.
>
> - donald
>
>

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




Re: Dynamic number of form fields

2002-09-11 Thread Donald Ball

On 9/11/2002 at 3:20 PM John Averty wrote:

>Duuh! Sorry about that.
>
>
>I'd like to bring it one step further: I'd like to be able to set the
>corresponding field type.
>
>Would the following work?
>
>
><% for (int i=0; i<10; i++) {
>
>  String name = "value(foo-" + i + ")";
>  String type = "type(foo-" + i + ")";
>   property="<%=name%>"/>
>%>

Almost certainly not. If you want to dynamically choose a different type of
element, I think you basically need to fake a switch statement with a bunch
of logic:equals elements.

- donald


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




Re: Dynamic number of form fields

2002-09-11 Thread John Averty

Duuh! Sorry about that.


I'd like to bring it one step further: I'd like to be able to set the
corresponding field type.

Would the following work?


<% for (int i=0; i<10; i++) {

  String name = "value(foo-" + i + ")";
  String type = "type(foo-" + i + ")";
   property="<%=name%>"/>
%>
Thank you again.

John


- Original Message -
From: "David Graham" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]>
Sent: Wednesday, September 11, 2002 2:56 PM
Subject: Re: Dynamic number of form fields


> Donald put this attachment on one of his posts.  It's quite helpful and
I've
> attached it again to this message.
>
> Dave
>

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




Re: Dynamic number of form fields

2002-09-11 Thread Donald Ball

On 9/11/2002 at 3:59 PM David Graham wrote:

>Javascript doesn't like it when you use things like [ or ( in the name of
>a 
>form field.  There are several ways of coding the js and one of them
>accepts 
>those characters (I think).  So, you can still use javascript to validate
>it 
>but you might have to change the method by which you do it.  Of course,
>when 
>I get around to learning the struts validator stuff I won't need to do the

>js portion (hopefully :-).

Oh, that's easy. instead of:

form.foo.value

use

form.elements['foo'].value

Regarding the validator... I don't know how easy it will be to make the
struts validator stuff play with dynamic form inputs. I fear it will be
tricky to impossible, since the validator assumes you can enumerate all of
the properties that it will be validating in its configuration file.
Perhaps a struts validator guru may have a better answer.

- donald


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




Re: Dynamic number of form fields

2002-09-11 Thread David Graham

Javascript doesn't like it when you use things like [ or ( in the name of a 
form field.  There are several ways of coding the js and one of them accepts 
those characters (I think).  So, you can still use javascript to validate it 
but you might have to change the method by which you do it.  Of course, when 
I get around to learning the struts validator stuff I won't need to do the 
js portion (hopefully :-).

Thanks again,
Dave


>From: "Donald Ball" <[EMAIL PROTECTED]>
>Reply-To: [EMAIL PROTECTED]
>To: [EMAIL PROTECTED], [EMAIL PROTECTED]
>Subject: Re: Dynamic number of form fields
>Date: Wed, 11 Sep 2002 17:36:57 -0400
>
>On 9/11/2002 at 1:02 PM David Graham wrote:
>
> >Brilliant!  Thanks so much for your help!  That's a lot more elegant than
> >what I had been doing, although it does create interesting dilemmas with
> >javascript.  Hopefully that patch will make it into the docs soon.
>
>Glad you found the docs useful. Out of curiousity, what javascript dilemma
>do you see using map-backed ActionForms creating?
>
>- donald




_
Join the world’s largest e-mail service with MSN Hotmail. 
http://www.hotmail.com


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




Re: Dynamic number of form fields

2002-09-11 Thread David Graham

Donald put this attachment on one of his posts.  It's quite helpful and I've 
attached it again to this message.

Dave


>From: "John Averty" <[EMAIL PROTECTED]>
>Reply-To: "John Averty" <[EMAIL PROTECTED]>
>To: "Struts Users Mailing List" 
><[EMAIL PROTECTED]>,<[EMAIL PROTECTED]>
>Subject: Re: Dynamic number of form fields
>Date: Wed, 11 Sep 2002 14:47:18 -0700
>
>I'm na new struts user, and I'm trying to get a true dynamic form to work.
>Could you give me more pointers on how to access this doc?
>
>Thanx,
>
>John
>
>- Original Message -
>From: "Donald Ball" <[EMAIL PROTECTED]>
>To: <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]>
>Sent: Wednesday, September 11, 2002 10:34 AM
>Subject: Re: Dynamic number of form fields
>
>
>
> > The Dyna beans don't exactly give you what you're looking for. The
> > properties of a Dyna bean must be known at deployment time, do they're 
>not
> > directly suited for dynamic forms (the Dyna prefix is a bit misleading).
> > What you probably want are map-backed ActionForm beans (which can be
> > vanilla or Dyna, actually, with some caveats). There is no documentation
>in
> > the user guide for them, but I've written a patch that adds some. 
>Comments
> > on it are greatly welcomed.
> >
> > - donald
> >
>
>
>
>
>
>
> > --
> > To unsubscribe, e-mail:
><mailto:[EMAIL PROTECTED]>
> > For additional commands, e-mail:
><mailto:[EMAIL PROTECTED]>
>
>--
>To unsubscribe, e-mail:   
><mailto:[EMAIL PROTECTED]>
>For additional commands, e-mail: 
><mailto:[EMAIL PROTECTED]>




_
Join the world’s largest e-mail service with MSN Hotmail. 
http://www.hotmail.com


? patch
Index: doc/userGuide/building_controller.xml
===
RCS file: 
/home/cvspublic/jakarta-struts/doc/userGuide/building_controller.xml,v
retrieving revision 1.23
diff -u -r1.23 building_controller.xml
--- doc/userGuide/building_controller.xml   27 Jul 2002 21:53:13 -  1.23
+++ doc/userGuide/building_controller.xml   4 Sep 2002 15:36:28 -
@@ -7,6 +7,7 @@
 Ted Husted
 Martin Cooper
 Ed Burns
+Donald Ball
 The Struts User's Guide - Building Controller Components
   

@@ -90,11 +91,92 @@
 

 
-[:TODO:]
+  Maintaining a separate concrete ActionForm class for each form in 
your struts application is time-consuming. This can be alleviated through 
the use of DynaActionForm classes. Instead of creating a new ActionForm 
subclass and new get/set methods for each of your bean's properties, you can 
list its properties, type, and defaults in the struts configuration 
file.
+  For example, add the following to struts-config.xml for a UserForm 
bean that stores a user's given and family names:
+
+
+
+  The list of types supported by DynaActionForm beans includes:
+  
+java.lang.BigDecimal
+java.lang.BigInteger
+boolean and java.lang.Boolean
+byte and java.lang.Byte
+char and java.lang.Character
+java.lang.Class
+double and java.lang.Double
+float and java.lang.Float
+int and java.lang.Integer
+long and java.lang.Long
+short and java.lang.Short
+java.lang.String
+java.sql.Date
+java.sql.Time
+java.sql.Timestamp
+  
+  If you do not supply an initial attribute, numbers will be 
initialized to 0 and objects to null.
 

-
-[:TODO:]
+
+  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. Since the properties of these forms' ActionForm 
beans are not all known ahead of time, 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 the data from your form's dynamic fields 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 
parentheses in the bean property name indicate that the bean property named 
mapname is indexed using Strings (probably backed by a Map) and that 
struts should look for get/set methods that take a String key parameter to 
find the correct sub-property value. Struts will, of course, 

RE: Dynamic number of form fields

2002-09-11 Thread Donald Ball

On 9/11/2002 at 3:56 PM Hemanth Setty wrote:

>Correct me if I wrong, I think in the bean it should be:
>void setCategoryName(Map categoryName) and
>Map getCategoryName()
>-hemanth

I'm reasonably certain that you're wrong. The map-backed ActionForm parsing
code doesn't actually presume that there's a Map backing the property, just
something which acts like a map in that there exist these methods:

void setCategory(String key, Object value);
Object getCategory(String key);

on the bean. The underlying data storage object could be essentially
anything.

Of course, I didn't write this code, just tried to document it, so I may be
wrong.

- donald


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




Re: Dynamic number of form fields

2002-09-11 Thread John Averty

I'm na new struts user, and I'm trying to get a true dynamic form to work.
Could you give me more pointers on how to access this doc?

Thanx,

John

- Original Message -
From: "Donald Ball" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]>
Sent: Wednesday, September 11, 2002 10:34 AM
Subject: Re: Dynamic number of form fields



> The Dyna beans don't exactly give you what you're looking for. The
> properties of a Dyna bean must be known at deployment time, do they're not
> directly suited for dynamic forms (the Dyna prefix is a bit misleading).
> What you probably want are map-backed ActionForm beans (which can be
> vanilla or Dyna, actually, with some caveats). There is no documentation
in
> the user guide for them, but I've written a patch that adds some. Comments
> on it are greatly welcomed.
>
> - donald
>






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

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




Re: Dynamic number of form fields

2002-09-11 Thread Donald Ball

On 9/11/2002 at 2:53 PM David Graham wrote:

>I'm having some trouble getting this to work.  I get the error message 
>"javax.servlet.jsp.JspException: No getter method for property 
>categoryName(2) of bean org.apache.struts.taglib.html.BEAN"
>
>I have a HashMap in my form called categoryNames and a getter/setter like 
>this:
>public void setCategoryName(String key, Object name) {
> this.categoryNames.put(key, name);
>}
>
>public Object getCategoryName(String key) {
> return this.categoryNames.get(key);
>}

Looks correct to me.

>I put a bunch of AccountCategory objects in the session and then the jsp 
>loops through to display the input boxes like this:
>
>
>  property="categoryCode(<%= 
>((AccountCategory)pageContext.getAttribute("category")).getAccountCategoryI
D() 
>%>)"/>
>
>
>
>Any ideas?  Do I need struts 1.1 for this (I'm using 1.0.2)?

You do need struts 1.1 for this, sorry, I should have made that explicit.
Also, fwiw, I've had trouble with this usage:

>  property="categoryCode(<%= 
>((AccountCategory)pageContext.getAttribute("category")).getAccountCategoryI
D() 
>%>)"/>

jasper doesn't seem to evaluate the <%= %> expression inside the prompt
attribute value. Danged if I know why, but obviously my understanding of
the jsp processing model isn't the best. I use a scriptlet instead:

<% String property = "categoryCode(" + foo + ")"; %>


I would hope someone has a better solution to suggest. :)

- donald


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




Re: Dynamic number of form fields

2002-09-11 Thread Donald Ball

On 9/11/2002 at 1:02 PM David Graham wrote:

>Brilliant!  Thanks so much for your help!  That's a lot more elegant than 
>what I had been doing, although it does create interesting dilemmas with 
>javascript.  Hopefully that patch will make it into the docs soon.

Glad you found the docs useful. Out of curiousity, what javascript dilemma
do you see using map-backed ActionForms creating?

- donald


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




RE: Dynamic number of form fields

2002-09-11 Thread Hemanth Setty

Correct me if I wrong, I think in the bean it should be:
void setCategoryName(Map categoryName) and
Map getCategoryName()
-hemanth



-Original Message-
From: David Graham [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, September 11, 2002 3:54 PM
To: [EMAIL PROTECTED]; [EMAIL PROTECTED]
Subject: Re: Dynamic number of form fields


I'm having some trouble getting this to work.  I get the error message
"javax.servlet.jsp.JspException: No getter method for property
categoryName(2) of bean org.apache.struts.taglib.html.BEAN"

I have a HashMap in my form called categoryNames and a getter/setter like
this:
public void setCategoryName(String key, Object name) {
 this.categoryNames.put(key, name);
}

public Object getCategoryName(String key) {
 return this.categoryNames.get(key);
}

I put a bunch of AccountCategory objects in the session and then the jsp
loops through to display the input boxes like this:


)"/>



Any ideas?  Do I need struts 1.1 for this (I'm using 1.0.2)?

Thanks,
Dave

>From: "Donald Ball" <[EMAIL PROTECTED]>
>Reply-To: [EMAIL PROTECTED]
>To: [EMAIL PROTECTED], [EMAIL PROTECTED]
>Subject: Re: Dynamic number of form fields
>Date: Wed, 11 Sep 2002 13:34:18 -0400
>
>On 9/11/2002 at 11:00 AM David Graham wrote:
>
> >I want to have a form with a variable number of input boxes.  For
> >example, a
> >simple edit person form that has a first name and last name input box for
> >each person in your db.  So the first set would be named firstName_12
> >lastName_12, the second set might be firstName_45623 and lastName_45623.
> >The number after the underscore is the personID from the db table.  When
> >the
> >form is submitted you loop over these fields and update the appropriate
> >row
> >in the database from the _ID info.
> >
> >I've read through the docs on DynaBeans and that seems like the way to go
> >but I'm still not sure how to go about this. When populating the
> >DynaFormBean, does struts just go through the request params and assign
> >them
> >to new form properties?  How would you validate this type of form?
>
>The Dyna beans don't exactly give you what you're looking for. The
>properties of a Dyna bean must be known at deployment time, do they're not
>directly suited for dynamic forms (the Dyna prefix is a bit misleading).
>What you probably want are map-backed ActionForm beans (which can be
>vanilla or Dyna, actually, with some caveats). There is no documentation in
>the user guide for them, but I've written a patch that adds some. Comments
>on it are greatly welcomed.
>
>- donald
><< patch >>
>--
>To unsubscribe, e-mail:
><mailto:[EMAIL PROTECTED]>
>For additional commands, e-mail:
><mailto:[EMAIL PROTECTED]>




_
MSN Photos is the easiest way to share and print your photos:
http://photos.msn.com/support/worldwide.aspx


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


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




Re: Dynamic number of form fields

2002-09-11 Thread David Graham

I'm having some trouble getting this to work.  I get the error message 
"javax.servlet.jsp.JspException: No getter method for property 
categoryName(2) of bean org.apache.struts.taglib.html.BEAN"

I have a HashMap in my form called categoryNames and a getter/setter like 
this:
public void setCategoryName(String key, Object name) {
 this.categoryNames.put(key, name);
}

public Object getCategoryName(String key) {
 return this.categoryNames.get(key);
}

I put a bunch of AccountCategory objects in the session and then the jsp 
loops through to display the input boxes like this:


)"/>



Any ideas?  Do I need struts 1.1 for this (I'm using 1.0.2)?

Thanks,
Dave

>From: "Donald Ball" <[EMAIL PROTECTED]>
>Reply-To: [EMAIL PROTECTED]
>To: [EMAIL PROTECTED], [EMAIL PROTECTED]
>Subject: Re: Dynamic number of form fields
>Date: Wed, 11 Sep 2002 13:34:18 -0400
>
>On 9/11/2002 at 11:00 AM David Graham wrote:
>
> >I want to have a form with a variable number of input boxes.  For
> >example, a
> >simple edit person form that has a first name and last name input box for
> >each person in your db.  So the first set would be named firstName_12
> >lastName_12, the second set might be firstName_45623 and lastName_45623.
> >The number after the underscore is the personID from the db table.  When
> >the
> >form is submitted you loop over these fields and update the appropriate
> >row
> >in the database from the _ID info.
> >
> >I've read through the docs on DynaBeans and that seems like the way to go
> >but I'm still not sure how to go about this. When populating the
> >DynaFormBean, does struts just go through the request params and assign
> >them
> >to new form properties?  How would you validate this type of form?
>
>The Dyna beans don't exactly give you what you're looking for. The
>properties of a Dyna bean must be known at deployment time, do they're not
>directly suited for dynamic forms (the Dyna prefix is a bit misleading).
>What you probably want are map-backed ActionForm beans (which can be
>vanilla or Dyna, actually, with some caveats). There is no documentation in
>the user guide for them, but I've written a patch that adds some. Comments
>on it are greatly welcomed.
>
>- donald
><< patch >>
>--
>To unsubscribe, e-mail:   
><mailto:[EMAIL PROTECTED]>
>For additional commands, e-mail: 
><mailto:[EMAIL PROTECTED]>




_
MSN Photos is the easiest way to share and print your photos: 
http://photos.msn.com/support/worldwide.aspx


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




Re: Dynamic number of form fields

2002-09-11 Thread David Graham

Brilliant!  Thanks so much for your help!  That's a lot more elegant than 
what I had been doing, although it does create interesting dilemmas with 
javascript.  Hopefully that patch will make it into the docs soon.

Thanks,
Dave


>From: "Donald Ball" <[EMAIL PROTECTED]>
>Reply-To: [EMAIL PROTECTED]
>To: [EMAIL PROTECTED], [EMAIL PROTECTED]
>Subject: Re: Dynamic number of form fields
>Date: Wed, 11 Sep 2002 13:34:18 -0400
>
>On 9/11/2002 at 11:00 AM David Graham wrote:
>
> >I want to have a form with a variable number of input boxes.  For
> >example, a
> >simple edit person form that has a first name and last name input box for
> >each person in your db.  So the first set would be named firstName_12
> >lastName_12, the second set might be firstName_45623 and lastName_45623.
> >The number after the underscore is the personID from the db table.  When
> >the
> >form is submitted you loop over these fields and update the appropriate
> >row
> >in the database from the _ID info.
> >
> >I've read through the docs on DynaBeans and that seems like the way to go
> >but I'm still not sure how to go about this. When populating the
> >DynaFormBean, does struts just go through the request params and assign
> >them
> >to new form properties?  How would you validate this type of form?
>
>The Dyna beans don't exactly give you what you're looking for. The
>properties of a Dyna bean must be known at deployment time, do they're not
>directly suited for dynamic forms (the Dyna prefix is a bit misleading).
>What you probably want are map-backed ActionForm beans (which can be
>vanilla or Dyna, actually, with some caveats). There is no documentation in
>the user guide for them, but I've written a patch that adds some. Comments
>on it are greatly welcomed.
>
>- donald
><< patch >>
>--
>To unsubscribe, e-mail:   
><mailto:[EMAIL PROTECTED]>
>For additional commands, e-mail: 
><mailto:[EMAIL PROTECTED]>




_
MSN Photos is the easiest way to share and print your photos: 
http://photos.msn.com/support/worldwide.aspx


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




Re: Dynamic number of form fields

2002-09-11 Thread Donald Ball

On 9/11/2002 at 11:00 AM David Graham wrote:

>I want to have a form with a variable number of input boxes.  For
>example, a 
>simple edit person form that has a first name and last name input box for 
>each person in your db.  So the first set would be named firstName_12 
>lastName_12, the second set might be firstName_45623 and lastName_45623.  
>The number after the underscore is the personID from the db table.  When
>the 
>form is submitted you loop over these fields and update the appropriate
>row 
>in the database from the _ID info.
>
>I've read through the docs on DynaBeans and that seems like the way to go 
>but I'm still not sure how to go about this. When populating the 
>DynaFormBean, does struts just go through the request params and assign
>them 
>to new form properties?  How would you validate this type of form?

The Dyna beans don't exactly give you what you're looking for. The
properties of a Dyna bean must be known at deployment time, do they're not
directly suited for dynamic forms (the Dyna prefix is a bit misleading).
What you probably want are map-backed ActionForm beans (which can be
vanilla or Dyna, actually, with some caveats). There is no documentation in
the user guide for them, but I've written a patch that adds some. Comments
on it are greatly welcomed.

- donald



patch
Description: Binary data

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


Re: Dynamic number of form fields

2002-09-11 Thread rob

There was a good tutorial on this possibly linked from the struts page
titled "Monkey Struts".  I found it to be quite good, very easy to
follow.

David Graham wrote:
> I want to have a form with a variable number of input boxes.  For 
> example, a simple edit person form that has a first name and last name 
> input box for each person in your db.  So the first set would be named 
> firstName_12 lastName_12, the second set might be firstName_45623 and 
> lastName_45623.  The number after the underscore is the personID from 
> the db table.  When the form is submitted you loop over these fields and 
> update the appropriate row in the database from the _ID info.
> 
> I've read through the docs on DynaBeans and that seems like the way to 
> go but I'm still not sure how to go about this. When populating the 
> DynaFormBean, does struts just go through the request params and assign 
> them to new form properties?  How would you validate this type of form?
> 
> Advice and links to info are appreciated.
> 
> Thanks,
> Dave
> 
> 
> 
> _
> Join the world's largest e-mail service with MSN Hotmail. 
> http://www.hotmail.com
> 
> 
> -- 
> To unsubscribe, e-mail:   
> 
> For additional commands, e-mail: 
> 
> 
> 



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