<?xml version="1.0" encoding="Shift_JIS"?>
<document>

  <properties>
    <author email="jon@latchkey.com">Jon S. Stevens</author>
    <title>You make the decision - Sample Application</title>
    <translator>熊坂祐二</translator>
    <translator>高橋達男</translator>
    <translator>羽生田恒永</translator>
    <original>ymtd/ymtd-sampleapp</original>
  </properties>

<body>

<section name="Sample Application" alias="サンプルアプリケーション">

<primary>
<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>
</primary>
<p>
直接 Java に関連する問題に対処するために、
ユーザのアプリケーションで特別なコードを書かないといけない、
などということはあってはならないと、Velocity の開発者は考えています。
</p>

<primary>
<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>
</primary>
<p>
別の言い方をすると、JSP/Struts コミュニティの強い主張として、
「これは JSP の良くない使い方の例です」という意味のことを言うことがあります。
それは正しいかもしれませんが、結局のところ提供される例のほとんどすべてが
JSP の良くない使い方の例なのです。前に説明した通り、ページに埋め込まれた
Java コードは良くないのです。
ここまでの説明でそれを十分に分かっていただけたかと思います。
</p>

<primary>
<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>
</primary>
<p>
<a href="http://www.javaworld.com/">JavaWorld</a>に載っている
JSP に関する記事を読めば、どの記事でもこのツールの良くない使い方を示したものが
いろいろとあります。なぜ（明らかに）優秀な人々の多くが、
このツールの使い方の正しい例を提示できないのでしょうか？
</p>

<primary>
<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>
</primary>
<p>
結局のところ、このツールを正しく使用することは非常に難しいということです。
Struts は、その難しさを単純にし、
正しいやり方を示そうとするという点で素晴らしい実績を残しています。
しかし、それは単に JSP 本来の設計の美しくない部分を隠しているだけです。
</p>

<primary>
<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>
</primary>
<p>
オブジェクト指向では、基本クラスに機能を追加するにはクラスを拡張
するべし、と言います。
基本クラスの public メソッドは、それを拡張したクラスでも使うことができます。
つまり、Struts を JSP にかぶせたからといって、JSP の欠点が治るわけではありません。
それは単に欠点を隠すだけで、開発者がそのことに気づいたらそれまでです。
</p>

<source><![CDATA[
<%-- 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" %>
]]></source>

<primary>
<source><![CDATA[
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'.
]]></source>
</primary>
<source><![CDATA[
JSP の空白保持規則のため、スクリプトレットで if/else 文を書くときは、
慎重に行わなければなりません。
以下のコードは、*動作しません*。

  <% if (tool.isNewWithin(45)) { %>
    <FONT COLOR=#FF0000><B> (New!) </B></FONT>
  <% } %>
  <% else if (tool.isUpdatedWithin(45)) { %>
    <FONT COLOR=#FF0000><B> (Updated!) </B></FONT>
  <% } %>

このコードでは、背後にあるサーブレットが
if 節と else 節の間で改行を出力しようとするので、

「if」なしの「else」

という分かりにくいコンパイルエラーを引き起こします。

]]></source>

<hr noshade="true" size="1"/>

<primary>
<p>
This is the version of the example above translated to Velocity:
</p>
</primary>
<p>
これは、上記の例を Velocity に翻訳したものです
</p>

<source><![CDATA[
## 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")
]]></source>

<primary>
<p>
You make the decision.
</p>
</primary>
<p>
[どちらを選ぶかは] あなたが判断してください。
</p>

<primary>
<p>
<strong>[ <a href="ymtd-javabeans.html">JavaBeans</a> &lt;- Previous |
    Next -&gt; <a href="./ymtd-taglibs.html">Taglibs</a> ]
</strong></p>
</primary>
<p>
<strong>[ <a href="ymtd-javabeans.html">JavaBeans</a> &lt;- 前 | 
    次 -&gt; <a href="./ymtd-taglibs.html">taglib</a> ]
</strong></p>

</section>

</body>
</document>

