Will Spies/Towers Perrin wrote:
>
> I mean your example *displays* an array. Let's say I change your example
> and instead of displaying an array I want to *edit* all elements in the
> array and post the results up to struts. Here is a JSP struts example of
> what we do:
Velocity is a view technology like JSP, so you would use it in the
exact same way you currently use your JSP templates. With Velocity your
example would like this:
<form name="form1" action="/app/saveEmployment.act">
<table align=center border=3 borderColor=#ffffff borderColorDark=#000000
borderColorLight=#ffffff frame=void height=390 rules=rows style="HEIGHT:
190px; LEFT: 0px; TOP: 10px; WIDTH: 700px" width=700>
<tr>
<th align="left"> Employee Id </td>
<td align="left"> Client Id </td>
<td align="left"> Work Zip Code </td>
<td align="left"> Mail code </td>
<td align="left"> Delete </td>
</tr>
#set ($empForm = $employmentForm) <!-- Velocity finds the variable automatically
in the requests attributes --!>
#foreach ($row in $empForm.data.rows)
#set ($i = 0)
<tr>
<td align="left">
<input type="text" name="data.rows$i.empEmployeeId"
maxlength=10 size=10/ value="$row.empEmployeeId">
</td>
<td align="left">
<input type="text" name="data.rows$i.cltClientId" maxlength=10
size=10/ value="$row.cltClientId">
</td>
<td align="left">
<input type="text" name="data.rows$i.workZipcode" maxlength=10
size=10/ value="$row.workZipcode">
</td>
<td align="left">
<input type="text" name="data.rows$i.mailcode" maxlength=10
size=25/ value="$row.mailcode">
</td>
<td align="left">
<input type="checkbox" name="markedForDelete$i">
</td>
</tr>
#set ($i = $i + 1)
#end
<tr>
<td align="left"> </td>
<td align="left"> </td>
<td align="left"> </td>
<td align="left"> </td>
<td align="left"> </td>
</tr>
</table>
<table align="center">
<td align="right"> <input type="submit" value="$html.message("button.save")"/>
</td>
<td align="left"> <input type="reset" value="$html.message("button.reset")"/>
input type="submit" value="$html.message("button.cancel")"/>
</td>
</table>
</form>
On the Struts side nothing changes. When the form is submitted, it is
processed the same way as today.
The advantages are:
- simpler syntax, easier to learn than JSP
- stricter separation of the designer's and the developer's work.
Gabe
>
> <html:form action="/app/saveEmployment.act">
> <table align=center border=3 borderColor=#ffffff borderColorDark=#000000
> borderColorLight=#ffffff frame=void height=390 rules=rows style="HEIGHT:
> 190px; LEFT: 0px; TOP: 10px; WIDTH: 700px" width=700>
> <tr>
> <th align="left"> Employee Id </td>
> <td align="left"> Client Id </td>
> <td align="left"> Work Zip Code </td>
> <td align="left"> Mail code </td>
> <td align="left"> Delete </td>
> </tr>
> <%EmploymentForm empForm=(EmploymentForm)request.getAttribute
> ("employmentForm");%>
> <%for (int i=0; i < empForm.getData().getRows().length;i++) {%>
> <tr>
> <td align="left">
> <input type="text" name="data.rows[<%=i%>].empEmployeeId"
> maxlength=10 size=10/ value="<%=empForm.getData().getRows
> ()[i].getEmpEmployeeId()%>">
> </td>
> <td align="left">
> <input type="text" name="data.rows[<%=i%>].cltClientId" maxlength=10
> size=10/ value="<%=empForm.getData().getRows()[i].getCltClientId()%>">
> </td>
> <td align="left">
> <input type="text" name="data.rows[<%=i%>].workZipcode" maxlength=10
> size=10/ value="<%=empForm.getData().getRows()[i].getWorkZipcode()%>">
> </td>
> <td align="left">
> <input type="text" name="data.rows[<%=i%>].mailcode" maxlength=10
> size=25/ value="<%=empForm.getData().getRows()[i].getMailcode()%>">
> </td>
> <td align="left">
> <input type="checkbox" name="markedForDelete[<%=i%>]">
> </td>
> </tr>
> <%}%>
> <tr>
> <td align="left"> </td>
> <td align="left"> </td>
> <td align="left"> </td>
> <td align="left"> </td>
> <td align="left"> </td>
> </tr>
> </table>
> <table align="center">
> <td align="right"> <html:submit> <bean:message key="button.save"/>
> </html:submit>
> </td>
> <td align="left"> <html:reset> <bean:message key="button.reset"/>
> </html:reset>
> <html:cancel> <bean:message key="button.cancel"/> </html:cancel>
> </td>
> </table>
> </html:form>
>
> We go outside the struts tags here because in the 1.0 version the iterate
> tag does not do this properly ( but the struts engine does ). Note in the
> above how elements are generated as index ( [n] ) elements. The
> ActionForm's would contain indexed properties in order for this to work.
>
> What would the velocity equivalent of the above look like?
>
> _______________________
> Will Spies
> Towers Perrin
> Phone: (215)246-7145
> e-mail: [EMAIL PROTECTED]
>
> --
> To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>
--
Gabriel Sidler
Software Engineer, Eivycom GmbH, Zurich, Switzerland
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>