20021122 Friday November 22, 2002

JSP's Evolution There's another interesting discussion taking place over on the struts-dev list again. Man, I'm glad I subscribed (again) to this list last week! It started out as a discussion of JSP vs. Velocity and Craig (McClanahan) provided an interesting evolution of JSP (and comparison to Velocity).

Velocity:
========

(Note -- it's assumed that the Customer collection has been stored in the
VelocityContext by some preceding business logic.)

  \#foreach $result in $results {
    <tr>
      <td>$result.ID</td>
      <td>$result.Name</td>
    </tr>
  }

JSP 1.1 (with Scriptlets):
=========================

  <%
    Customer custs = ...;
    for (int i=0; i < custs.length; i++) {
  %>
    <tr>
      <td><%= custs[i].getId() %></td>
      <td><%= custs[i].getName() %></td>
    </tr>
  <%
    }
  %>

JSP 1.1 (with custom tags):
==========================
(Note -- it is assumed here and in the following examples that the Customer collection has been stored by some preceding business logic.)

  <logic:iterate id="cust" name="custs">
    <tr>
      <td><jsp:getProperty name="cust" property="id"/></td>
      <td><jsp:getProperty name="cust" property="name"/></td>
    </tr>
  </logic:iterate>

JSP 1.2 + JSTL 1.0:
==================

  <c:forEach var="cust" items="${custs}">
    <tr>
      <td><c:out value="${cust.id}"/></td>
      <td><c:out value="${cust.name}"/></td>
    </tr>
  </c:forEach>

JSP 2.0 + JSTL 1.0:
==================

  <c:forEach var="cust" items="${custs}">
    <tr>
      <td>${cust.id}</td>
      <td>${cust.name}</td>
    </tr>
  </c:forEach>
</pre>

I can't wait for JSP 2.0 - it's going to make everything so much easier. Once again, we have exciting times for the Java world. With the power of JSP 2.0 and XDoclet, deadlines should be a non-issue. Now we just have to figure out the best way to use them, and the fastest way to pump out a Struts project. Wouldn't it be awesome if you you could add a new column to a table, build your project using Ant and XDoclet and whalla, all your classes are updated! That would be cool - and I think it's possible. Now I just have to figure out how - and fast! Posted in Java at Nov 22 2002, 06:05:23 PM MST 6 Comments

Comments:

Just strolling by, thought I would mention that your site does not validate. The character that messes up the XTML validator is the "&" character. Instead of referring to it as such, use "&amp;" and it should solve your problem. (Without the quotes, of course.) Sorry to be a first time visitor handing out advice.... I hate those types. :) Interesting reading. Cheers.

Posted by Bradley on November 22, 2002 at 09:05 PM MST #

Sorry, that should be "& a m p ;". I had to add a space in between each character because it rendered it as an actual &!

Posted by Bradley on November 22, 2002 at 09:07 PM MST #

Yep, this happens a lot - as anyone that maintains an XHTML Strict site will tell you. This morning issue was caused by a Velocity error rather than something I typed in though. Fixed now.

Posted by Matt Raible on November 23, 2002 at 04:53 AM MST #

Matt, you can escape the \$ and the \# by placing a slash in front of them.

Posted by Lance on November 23, 2002 at 08:51 AM MST #

Thanks Lance - this worked for the #, but apparently I didn't need to escape the $'s.

Posted by Matt Raible on November 23, 2002 at 11:05 AM MST #

Why not try eXist XML database and use XQuery to generate XHTML ?!

for $cust in $custs
return
  <tr>
    <td>{data($cust/id)}</td>
    <td>{data($cust/name)}</td>
  </tr>

This way you just stay within the XML domain. We build our entire web application using XForms, Orbeon, XQuery (eXis) this way. No XML databinding needed here !

Posted by Roger van de Kimmenade on March 17, 2008 at 01:07 PM MDT #

Post a Comment:
  • HTML Syntax: Allowed
Click me to subscribe
Matt Raible is the Lead UI Architect at LinkedIn. The opinions on this site are mine, not my employers.
« September 2008
SunMonTueWedThuFriSat
 
1
2
4
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
    
       
Today

Recent Entries

Tag Cloud