hi

i have been looking at velocity periodically for a few months now, and
although i understand what it is trying to do (define a clearer separation
between controller and view) i felt that its big disadvantage was that it
introduced another language/syntax for a developer/designer to learn. In
view of this i decided to stay with struts, and occasionally resort to using
java scriptlets in my applications !-)

i would be interested in hearing other peoples opinions on this issue,
especially since struts can now integrate with velocity. i may be persuaded
to use velocity in my applications

thanks 

Martin




-----Original Message-----
From: Gabriel Sidler [mailto:[EMAIL PROTECTED]]
Sent: 22 January 2002 17:05
To: Struts Users Mailing List
Subject: Re: Velocity-Tools / Struts


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")"/>
  &nbsp; 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>
>     &nbsp; <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]>


** For great Emap magazine subscription & gift offers visit 
http://www.emapmagazines.co.uk **

--------------------------------------------------------------------------------
The information in this email is intended only for the addressee(s) named above.
Access to this email by anyone else is unauthorised.
If you are not the intended recipient of this message any disclosure, copying, 
distribution or any action taken in reliance on it is prohibited and may be unlawful. 

Emap plc and or its subsidiaries do not warrant that any attachments are free from 
viruses or other defects and accept no liability for any losses resulting from 
infected email transmissions.

Please note that any views expressed in this email may be those of the originator 
and do not necessarily reflect those of this organisation.
--------------------------------------------------------------------------------


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

Reply via email to