DynaForms aren't as dynamic as there name suggest, at least not until you start using indexed properties.If the case of forms you'll still be wanting to use struts html tags, as jstl doesn't cover this yet until java servers faces is released.

For most cases nesting beans works

//in struts config
<form-bean name="myForm">
<form-property name="user" type="java.util.ArrayList" />

I'm using arraylist rather than User[] .. I still need to find out whether there's an advantage.


.. //in the bean public class User { String name;

        getName() {
                return name;
        }

        setName(String str) {
                this.name = str;
        }
}
..
//in the action
User user = new User();
user.setName("Brian Blessed");

User anotherUser = new User();
anotherUser.setName("Brian Clough");

ArrayList list = new ArrayList();
list.add(user);
list.add(anotherUser);

theForm.set("user",list);
..

<html:form action="/foo.do">
<logic:iterate id="u" name="myForm" property="user"> <html:text name="u" property="name" indexed="true" /><br>
</logic:iterate>
<br>
<html:submit />
</html: form >


...

ArrayList userList = (ArrayList) theForm.get("user");

for(int i = 0;i < userList.size();i++) {
        User user = (User) userList.get(i);
        System.out.println(user.getName());
}

..

Cheers Mark


On Friday, September 12, 2003, at 02:54 PM, [EMAIL PROTECTED] wrote:


Ok.

So to use variable names they reccomend using

<%
        for (int i = 0; i < 10; i++) {
                String name = "value(foo-" + i + ")";
%>
                <html:text property="<%= name %>"/>
                <br/>
<%
        }
%>


I would like to use JSTL, but you can't put jstl tags inside struts tags and
someone mentioned at one point that I should use EL... soo, any links as to
where I can read about this?


Thanks,

Denis
----- Original Message -----
From: <[EMAIL PROTECTED]>
To: "Struts Users Mailing List" <[EMAIL PROTECTED]>
Sent: Friday, September 12, 2003 9:43 AM
Subject: Re: Really Dynamic Forms


Well. So after I write, I found

http://jakarta.apache.org/struts/userGuide/ building_controller.html#map_action_form_classes
Thanks anyway.

Regards,

Denis
----- Original Message -----
From: <[EMAIL PROTECTED]>
To: "Struts Users Mailing List" <[EMAIL PROTECTED]>
Sent: Friday, September 12, 2003 9:40 AM
Subject: Really Dynamic Forms


Hello,


So I have a problem, and I just can't get out of the box to look at it
anymore so I am writing you all:

I have a user registration page and action i am writing. User can have a
variable number of properties with different names that need to be filled
in. User also has some properties that always need to be filled in.


I am not sure how to do this using struts forms of any kind. It seems to
me
that I need to define at least the names of the properties in advance,
when
that will be changing (I know the client will be adding and removing
properties in the future so I can't hardcode them).

Right now I am using a regular form, I have my fixed properties hardcoded,
and variable ones are preloaded in a map in the setup action and I iterate
over them to display them. Then in the action I retrieve them.


This is fine until I want to validate something, and I really like struts
forms validation, so i'd like to use them if possible.


To summarize:
I have  a map of properties, as well as some regular properties.
I want to use a struts form to retrieve the data.
I don't know how to do it so the names are dynamic.


Regards,


Denis


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