|
Joe,
I made the argument for Custom tags over scriptlets at
our shop and lost. Soon pages became more and more
complex and things started to break down. Debugging
scriptlets is difficult, tools are behind Java tools used
to develop tags, and for the most part you have all of
the tag functionality you need with JSTL.
Your Struts example would be improved through the use of
JSTL and the JSTL expression language. Here is something
similar with struts:
<table>
<thead>
<tr>
<th align="left"><bean-el:message key="text.delete" /></th>
<th align="left"><bean-el:message key="text.customer.name"
/></th>
<th align="left"><bean-el:message key="text.customer.address"
/></th>
<th align="left"><bean-el:message key="text.customer.city"
/></th>
<th align="left"><bean-el:message key="text.customer.state"
/></th>
<th align="left"><bean-el:message key="text.customer.email"
/></th>
</tr>
</thead>
<tbody>
<c:forEach var="customer" items="${customerListForm.customers}">
<tr>
<td><html-el:checkbox styleClass="checkbox"
name="customerListForm" property="deletes" value="${customer.id}"
/></td>
<td><c:url value="/customerListAction.do" var="editlink">
<c:param name="action" value="update" />
<c:param name="alpha" value="${customerListForm.alpha}" />
<c:param name="updateId" value="${customer.id}" />
</c:url> <a href='<c:out value="${editlink}" />'><c:out
value="${customer.name}" /></a>
</td>
<td><c:out value="${customer.address1}" /></td>
<td><c:out value="${customer.city}" /></td>
<td><c:out value="${customer.state}" /></td>
<td><c:out value="${customer.email}" /></td>
</tr>
</c:forEach>
</tbody>
</table>
There are several advantages here provided by Struts. One
is that the screen descriptions are softcoded (similar to using MSGID
in
DDS). Also, this is easy to debug as all logic is in real Java code.
I don't see it as a problem to say that something you will
treat as a list has to be either a Collection, Map, Object[],
String, Array, Iterator or Enumeration. In my example, the
form supporting the page has a List of Customer objects
it. The Customer class was generated via Hibernate right
off the iSeries (or MySql, Oracle, Postgres, etc).
David Morris
>>> joepluta@xxxxxxxxxxxxxxxxx 10/9/2003 2:02:00 PM >>>
Here's my two cents:
This is an example without Struts:
<%
List list = dvds.getDVDList();
for (Iterator i = list.iterator(); i.hasNext();) {
DVD dvd = (DVD)i.next();
%>
<tr>
<td><%=dvd.getTitle()%></td>
<td><%=dvd.getLength()%></td>
<td><%=dvd.getActors()%></td>
</tr>
<%
}
%>
This is the same example with Struts:
<logic:iterate id="dvd" name="dvds" property="DVDList">
<tr>
<td><bean:write name="dvd" property="title" /></td>
<td><bean:write name="dvd" property="length" /></td>
<td><bean:write name="dvd" property="actors" /></td>
</tr>
</logic:iterate>
The argument for struts is that this is "cleaner". I guess that's
because it all has nice <tag> and </tag> symmetry.
Personally, I don't much see it being cleaner. I understand the upper
code better than the lower. And the lower syntax is very confining,
especially if my classes don't exactly conform to the JavaBean
specification - let's say one of my methods was "calculateTax".
Unless
I change that method name to "getTax", I will not be able to create a
<bean:write> tag for it. Also, my object of type "dvds" has to be of
a
specific interface - one that supports the "iterator" method.
I suggest taking a LOT of time to read the Struts tag library to make
sure you realize what you're getting yourself into. Struts is fine if
you like having your language dictate how you write your application.
Me, I'll stick with my own code.
Joe
As an Amazon Associate we earn from qualifying purchases.
This mailing list archive is Copyright 1997-2025 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].
Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.