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", "[EMAIL PROTECTED]");
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