| <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> |
| |
| <!-- |
| Copyright 1999-2004 The Apache Software Foundation |
| Licensed under the Apache License, Version 2.0 (the "License"); |
| you may not use this file except in compliance with the License. |
| You may obtain a copy of the License at |
| |
| http://www.apache.org/licenses/LICENSE-2.0 |
| |
| Unless required by applicable law or agreed to in writing, software |
| distributed under the License is distributed on an "AS IS" BASIS, |
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| See the License for the specific language governing permissions and |
| limitations under the License. |
| --> |
| |
| |
| <!-- Content Stylesheet for Site --> |
| |
| |
| <!-- start the processing --> |
| <!-- ====================================================================== --> |
| <!-- GENERATED FILE, DO NOT EDIT, EDIT THE XML FILE IN xdocs INSTEAD! --> |
| <!-- Main Page Section --> |
| <!-- ====================================================================== --> |
| <html> |
| <head> |
| <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/> |
| |
| <meta name="author" value="Jon S. Stevens"> |
| <meta name="email" value="jon@latchkey.com"> |
| |
| |
| |
| |
| <title>Velocity - You make the decision - Sample Application</title> |
| </head> |
| |
| <body bgcolor="#ffffff" text="#000000" link="#525D76"> |
| <table border="0" width="100%" cellspacing="0"> |
| <!-- TOP IMAGE --> |
| <tr> |
| <td align="left"> |
| <a href="http://jakarta.apache.org"><img src="http://jakarta.apache.org/images/jakarta-logo.gif" border="0"/></a> |
| </td> |
| <td align="right"> |
| <a href="http://jakarta.apache.org/velocity/"><img src="../images/logo.gif" alt="Velocity" border="0"/></a> |
| </td> |
| </tr> |
| </table> |
| <table border="0" width="100%" cellspacing="4"> |
| <tr><td colspan="2"> |
| <hr noshade="" size="1"/> |
| </td></tr> |
| |
| <tr> |
| <!-- LEFT SIDE NAVIGATION --> |
| <td width="20%" valign="top" nowrap="true"> |
| |
| <!-- ============================================================ --> |
| |
| <p><strong>About</strong></p> |
| <ul> |
| <li> <a href="../index.html">Overview</a> |
| </li> |
| <li> <a href="../getting-started.html">Getting Started</a> |
| </li> |
| <li> <a href="http://jakarta.apache.org/builds/jakarta-velocity/">Download</a> |
| </li> |
| <li> <a href="../install.html">Install</a> |
| </li> |
| <li> <a href="../design.html">Design</a> |
| </li> |
| <li> <a href="../contributors.html">Contributors</a> |
| </li> |
| <li> <a href="../changes.html">ChangeLog</a> |
| </li> |
| <li> <a href="../code-standards.html">Coding Standards</a> |
| </li> |
| <li> <a href="../license.html">License</a> |
| </li> |
| <li> <a href="../todo.html">TODO</a> |
| </li> |
| <li> <a href="http://issues.apache.org/bugzilla/enter_bug.cgi?product=Velocity">Report Issues</a> |
| </li> |
| </ul> |
| <p><strong>Community</strong></p> |
| <ul> |
| <li> <a href="../powered.html">Powered By Velocity</a> |
| </li> |
| <li> <a href="http://jakarta.apache.org/site/getinvolved.html">Get Involved</a> |
| </li> |
| <li> <a href="http://jakarta.apache.org/site/mail.html">Mailing Lists</a> |
| </li> |
| <li> <a href="http://jakarta.apache.org/site/cvsindex.html">CVS Repositories</a> |
| </li> |
| </ul> |
| <p><strong>Docs</strong></p> |
| <ul> |
| <li> <a href="../user-guide.html">User's Guide (English)</a> |
| </li> |
| <li> <a href="../user-guide_fi.html">User's Guide (Finnish)</a> |
| </li> |
| <li> <a href="../user-guide_fr.html">User's Guide (French)</a> |
| </li> |
| <li> <a href="../user-guide_es.html">User's Guide (Spanish)</a> |
| </li> |
| <li> <a href="../developer-guide.html">Developer's Guide</a> |
| </li> |
| <li> <a href="../vtl-reference-guide.html">VTL Reference Guide</a> |
| </li> |
| <li> <a href="../specification.html">Specification</a> |
| </li> |
| <li> <a href="../api/index.html">Javadoc</a> |
| </li> |
| </ul> |
| <p><strong>Tools</strong></p> |
| <ul> |
| <li> <a href="../tools/index.html">Velocity Tools</a> |
| </li> |
| <li> <a href="../anakia.html">Anakia : XML->doc tool</a> |
| </li> |
| <li> <a href="../texen.html">Texen : text generation</a> |
| </li> |
| <li> <a href="../dvsl/index.html">DVSL : XML xformation</a> |
| </li> |
| <li> <a href="../veltag.html">Veltag : JSP taglib</a> |
| </li> |
| <li> <a href="../migration.html">Migration to Velocity</a> |
| </li> |
| <li> <a href="../devtools.html">Editors and IDEs</a> |
| </li> |
| </ul> |
| <p><strong>Comparisons</strong></p> |
| <ul> |
| <li> <a href="../ymtd/ymtd.html">YMTD</a> |
| </li> |
| <li> <a href="../differences.html">VM/WM Differences</a> |
| </li> |
| <li> <a href="../casestudy1.html">JSP vs. Velocity</a> |
| </li> |
| <li> <a href="../casestudy2.html">XMLC vs. Velocity</a> |
| </li> |
| </ul> |
| <p><strong>Site Translations</strong></p> |
| <ul> |
| <li> <a href="http://jakarta.apache.org/velocity/">English</a> |
| </li> |
| <li> <a href="http://www.ingrid.org/jajakarta/velocity/velocity-1.2-rc2/docs-ja/index.html">Japanese</a> |
| </li> |
| </ul> |
| </td> |
| <td width="80%" align="left" valign="top"> |
| <table border="0" cellspacing="0" cellpadding="2" width="100%"> |
| <tr><td bgcolor="#525D76"> |
| <font color="#ffffff" face="arial,helvetica,sanserif"> |
| <a name="Sample Application"><strong>Sample Application</strong></a> |
| </font> |
| </td></tr> |
| <tr><td> |
| <blockquote> |
| <p> |
| It is the belief of the Velocity developers that you should not have to |
| specially code your applications to work around issues that are related |
| directly to Java. |
| </p> |
| <p> |
| In other words, one of the strong arguments of the JSP/Struts community |
| is to say something to the effect of: "this is a poor example of using |
| JSP." While this may be true, the fact of the matter is that nearly |
| every example available really is a poor example of using JSP. This goes |
| back to the statement that says that embedding Java code in your page is |
| a bad thing. Yes, we all know that now. |
| </p> |
| <p> |
| If one reads the articles available on <a href="http://www.javaworld.com/">JavaWorld</a> that are about JSP, |
| nearly every single article has one thing or another in it that |
| demonstrates poor usage of the tool. Why is it that so many (obviously) |
| talented people cannot come up with correct examples of using the tool? |
| </p> |
| <p> |
| The truth is that it is very hard to use the tool correctly. Struts is |
| doing an excellent job of making it easier and attempting to show the |
| right way, however it is simply hiding the uglyness of the original |
| design of JSP. |
| </p> |
| <p> |
| Object Oriented design dictates that you extend a class to add |
| functionality to the base class. The publicly available methods in the |
| base class are still available to the classes that extend it. Putting |
| Struts on top of JSP doesn't fix the warts in JSP. It simply hides them |
| until your developers find them. |
| </p> |
| <div align="left"> |
| <table cellspacing="4" cellpadding="0" border="0"> |
| <tr> |
| <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td> |
| <td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td> |
| <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td> |
| </tr> |
| <tr> |
| <td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td> |
| <td bgcolor="#ffffff"><pre> |
| <%-- toolview.jsp --%> |
| |
| <% |
| String title = "Tool Listing"; |
| String deck = "A list of content creation tools"; |
| String desc = "Without tools, people are nothing more than animals."; |
| %> |
| |
| <%@ include file="/header.jsp" %> |
| |
| <%@ page session="false" %> |
| <%@ page errorPage="/errorTaker.jsp" %> |
| |
| <jsp:useBean id="toolbean" class="ToolBean" scope="application"> |
| <jsp:setProperty name="toolbean" property="toolsFile" |
| value='<%= application.getInitParameter("toolsFile") %>' /> |
| </jsp:useBean> |
| |
| <% |
| Tool[] tools = toolbean.getTools(request.getParameter("state")); |
| |
| for (int i = 0; i < tools.length; i++) { |
| Tool tool = tools[i]; |
| %> |
| <HR SIZE=2 ALIGN=LEFT> |
| |
| <H3> |
| <%= tool.name %> |
| |
| <% if (tool.isNewWithin(45)) { %> |
| <FONT COLOR="#FF0000"><B> (New!) </B></FONT> |
| <% } else if (tool.isUpdatedWithin(45)) { %> |
| <FONT COLOR="#FF0000"><B> (Updated!) </B></FONT> |
| <% } %> |
| |
| </H3> |
| <A HREF="<%= tool.homeURL %>"><%= tool.homeURL %></A><BR> |
| |
| <%= tool.comments %> |
| |
| <% } %> |
| |
| <%@ include file="/footer.jsp" %> |
| </pre></td> |
| <td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td> |
| </tr> |
| <tr> |
| <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td> |
| <td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td> |
| <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td> |
| </tr> |
| </table> |
| </div> |
| <div align="left"> |
| <table cellspacing="4" cellpadding="0" border="0"> |
| <tr> |
| <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td> |
| <td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td> |
| <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td> |
| </tr> |
| <tr> |
| <td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td> |
| <td bgcolor="#ffffff"><pre> |
| Because of JSP whitespace preservation rules you must be careful when |
| writing if/else statements with scriptlets. The following code would |
| *not* work: |
| |
| <% if (tool.isNewWithin(45)) { %> |
| <FONT COLOR=#FF0000><B> (New!) </B></FONT> |
| <% } %> |
| <% else if (tool.isUpdatedWithin(45)) { %> |
| <FONT COLOR=#FF0000><B> (Updated!) </B></FONT> |
| <% } %> |
| |
| With this code the background servlet would attempt to print a new line |
| between the if and else clauses, causing the obscure compile error: |
| 'else' without 'if'. |
| </pre></td> |
| <td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td> |
| </tr> |
| <tr> |
| <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td> |
| <td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td> |
| <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td> |
| </tr> |
| </table> |
| </div> |
| <hr noshade="true" size="1" /> |
| <p> |
| This is the version of the example above translated to Velocity: |
| </p> |
| <div align="left"> |
| <table cellspacing="4" cellpadding="0" border="0"> |
| <tr> |
| <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td> |
| <td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td> |
| <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td> |
| </tr> |
| <tr> |
| <td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td> |
| <td bgcolor="#ffffff"><pre> |
| ## toolview.vm |
| |
| #set ($title = "Tool Listing") |
| #set ($deck = "A list of content creation tools") |
| #set ($desc = "Without tools, people are nothing more than animals." ) |
| |
| #parse ("header.vm") |
| |
| $toolbean.setToolsFile($application.getInitParameter("toolsFile")) |
| |
| #set ($tools = $toolbean.getTools($request.getParameter("state"))) |
| |
| #foreach ($tool in $tools) |
| <HR SIZE=2 ALIGN=LEFT> |
| |
| <H3> |
| $tool.Name |
| |
| #if ($tool.isNewWithin(45)) |
| <FONT COLOR="#FF0000"><B> (New!) </B></FONT> |
| #elseif (tool.isUpdatedWithin(45)) |
| <FONT COLOR="#FF0000"><B> (Updated!) </B></FONT> |
| #end |
| </H3> |
| <A HREF="$tool.homeURL">$tool.homeURL</A><BR> |
| |
| $tool.comments |
| #end |
| |
| #parse ("footer.vm") |
| </pre></td> |
| <td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td> |
| </tr> |
| <tr> |
| <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td> |
| <td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td> |
| <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td> |
| </tr> |
| </table> |
| </div> |
| <p> |
| You make the decision. |
| </p> |
| <p> |
| <strong>[ <a href="ymtd-javabeans.html">JavaBeans</a> <- Previous | |
| Next -> <a href="./ymtd-taglibs.html">Taglibs</a> ] |
| </strong></p> |
| </blockquote> |
| </p> |
| </td></tr> |
| <tr><td><br/></td></tr> |
| </table> |
| </td> |
| </tr> |
| |
| <!-- FOOTER --> |
| <tr><td colspan="2"> |
| <hr noshade="" size="1"/> |
| </td></tr> |
| <tr><td colspan="2"> |
| <div align="center"><font color="#525D76" size="-1"><em> |
| Copyright © 1999-2004, The Apache Software Foundation |
| </em></font></div> |
| </td></tr> |
| </table> |
| </body> |
| </html> |
| <!-- end the processing --> |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |