You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Oliver Thiel <th...@gmx.de> on 2004/01/12 08:31:11 UTC
Real Dynamic Forms - Using DynaBeans & MapBackedForms
Hi @all,
I am relative new to Strut, but I have to | want to do a struts project
for my studies at the university of applied science. I try to build a
'real' dynamic registration form using DynaBeans and Maps (all HashMaps
will be filled by a database call later).
What I have so far is:
CreateFormAction.java:
DynaActionForm mappedForm2 = (DynaActionForm) form;
HashMap mappedForm = new HashMap();
mappedForm.put("username", "test");
mappedForm.put("email", "test@gmx.de");
mappedForm.put("password", "xyz");
mappedForm.put("conf_pwd", "xyz");
mappedForm2.set("mappedForm", mappedForm);
request.setAttribute("mappedForm2", mappedForm2);
struts-config.xml
<form-bean dynamic="true" name="mappedForm2"
type="org.apache.struts.action.DynaActionForm">
<form-property name="mappedForm" type="java.util.HashMap"/>
<form-property name="getEmail" size="20" type="java.lang.String"/>
</form-bean>
mappedForm.jsp
<!-- TYPE:INPUT -->
<bean:define id="values" name="mappedForm2" property="mappedForm"
type="java.util.HashMap"/>
<logic:iterate id="mappedForm" name="mappedForm2" property="mappedForm">
<TR>
<TD width="40%"><bean:write name="mappedForm"
property="key"/>:</TD>
<TD><input type="text" name="<bean:write name="mappedForm"
property="key" />"
value="<bean:write name="mappedForm" property="value" />"
class="Feld"></TD>
</TR>
</logic:iterate>
<!-- TYPE:CHECKBOX -->
<TR>
<TD><html:checkbox styleClass="Check" property="getEmail"
/></TD>
<TD><bean:message key="form.getMail"/></TD>
</TR>
mappedForm.java (extends DynaActionForm)
String getEmail = (String)this.get("getEmail");
In the mappedForm.java I can only access the getMail value!
Questions:
1. How can I access the values from the map in my mappedForm
validate() method? To validate them I want to use another Map, filed
with Regular Expressions?
2. Can I use more than one Map? Cause I also want the (input
type="text") to be dynamic too, so that I can switch between text and
password for example.
3. How can I out print a 'dynamic' bean massage?
Something like that: <bean:message key="<bean:write name="mappedForm"
property="value"/>" /> But this does not work!
4. Is their a better way in Struts to do this?
5. Has any one done something like that before and can provide my
some examples or code snippets?
Thanks in advanced
Oliver
Re: Real Dynamic Forms - Using DynaBeans & MapBackedForms
Posted by hhlow <hh...@yahoo.com.au>.
Hi Oliver,
i am doing a simple login form.
well i am using Struts bean.
anyway i print the bean out by using
<bean:write name="user" property="username"/>
but recently i have this no getter method for the bean i dun understand why.
coz i have initialised the bean.
check out the tut here..it demostrates some simple features
www.reumann.net/do/struts/lesson1
www.reumann.net/do/struts/lesson2
www.reumann.net/do/struts/lesson3
Clement
----- Original Message -----
From: "Oliver Thiel" <th...@gmx.de>
To: <st...@jakarta.apache.org>
Sent: Monday, January 12, 2004 3:31 PM
Subject: Real Dynamic Forms - Using DynaBeans & MapBackedForms
> Hi @all,
>
>
> I am relative new to Strut, but I have to | want to do a struts project
> for my studies at the university of applied science. I try to build a
> 'real' dynamic registration form using DynaBeans and Maps (all HashMaps
> will be filled by a database call later).
>
> What I have so far is:
>
> CreateFormAction.java:
>
> DynaActionForm mappedForm2 = (DynaActionForm) form;
> HashMap mappedForm = new HashMap();
>
> mappedForm.put("username", "test");
> mappedForm.put("email", "test@gmx.de");
> mappedForm.put("password", "xyz");
> mappedForm.put("conf_pwd", "xyz");
>
> mappedForm2.set("mappedForm", mappedForm);
> request.setAttribute("mappedForm2", mappedForm2);
>
>
>
> struts-config.xml
>
> <form-bean dynamic="true" name="mappedForm2"
> type="org.apache.struts.action.DynaActionForm">
> <form-property name="mappedForm" type="java.util.HashMap"/>
> <form-property name="getEmail" size="20" type="java.lang.String"/>
> </form-bean>
>
>
>
> mappedForm.jsp
>
> <!-- TYPE:INPUT -->
> <bean:define id="values" name="mappedForm2" property="mappedForm"
> type="java.util.HashMap"/>
> <logic:iterate id="mappedForm" name="mappedForm2" property="mappedForm">
> <TR>
> <TD width="40%"><bean:write name="mappedForm"
> property="key"/>:</TD>
> <TD><input type="text" name="<bean:write name="mappedForm"
> property="key" />"
> value="<bean:write name="mappedForm" property="value" />"
> class="Feld"></TD>
> </TR>
> </logic:iterate>
> <!-- TYPE:CHECKBOX -->
> <TR>
> <TD><html:checkbox styleClass="Check" property="getEmail"
> /></TD>
> <TD><bean:message key="form.getMail"/></TD>
> </TR>
>
>
> mappedForm.java (extends DynaActionForm)
>
> String getEmail = (String)this.get("getEmail");
> In the mappedForm.java I can only access the getMail value!
>
> Questions:
> 1. How can I access the values from the map in my mappedForm
> validate() method? To validate them I want to use another Map, filed
> with Regular Expressions?
> 2. Can I use more than one Map? Cause I also want the (input
> type="text") to be dynamic too, so that I can switch between text and
> password for example.
> 3. How can I out print a 'dynamic' bean massage?
> Something like that: <bean:message key="<bean:write name="mappedForm"
> property="value"/>" /> But this does not work!
> 4. Is their a better way in Struts to do this?
> 5. Has any one done something like that before and can provide my
> some examples or code snippets?
>
>
> Thanks in advanced
> Oliver
>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org