<?xml version="1.0" encoding="Shift_JIS"?>
<!--
  Copyright 2003 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.

  $Id: FormTool.xml,v 1.6 2005/03/20 14:29:53 tatakaha Exp $
-->
<document>

    <properties>
        <title>FormTool</title>
        <author email="sidler@apache.org">Gabriel Sidler</author>
        <translator email="nekop@programmers.jp">木村 貴由</translator>
        <translator email="tatakaha@jajakarta.org">高橋 達男</translator>
        <projectfile>xdocs-ja/struts/menu.xml</projectfile>
        <original>FormTool</original>

    </properties>

    <body>

    <section name="FormTool Reference Documentation" alias="FormTool リファレンスドキュメント">

        <primary>
        <p>Struts has support to parse incoming HTTP requests and populate a Java bean
        with the submitted request parameters. The same Java bean is used to populate
        forms with initial values. Additionally, a hook allows the application developer 
        to include automatic form validation code.</p> 
        </primary>
        <p>Struts は HTTP リクエストの解析と、
        サブミットされたリクエストパラメータのJava ビーンへの設定を行います。
        このJava ビーンは、初期値を含むフォームの値の設定にも利用されます。
        また、自動的なフォームの検証コードをフックさせることもできます。</p> 

        <primary>
        <p>FormTool provides miscellaneous methods to work with forms and form bean in
        the context of Struts applications.</p>
        </primary>
        <p>FormTool はフォームや、 Struts アプリケーションのコンテキスト内のフォームビーンを扱うさまざまなメソッドを提供します。</p>
        
        <toolinfo>
            <version>@@@version@@@, @@@date@@@</version>
            <clazz>org.apache.velocity.tools.struts.FormTool</clazz>
            <name>$form</name>
            <author email="sidler@teamup.com">Gabriel Sidler</author>
            <config-example>&lt;tool&gt;
  &lt;key&gt;form&lt;/key&gt;
  &lt;scope&gt;request&lt;/scope&gt;
  &lt;class&gt;org.apache.velocity.tools.struts.FormTool&lt;/class&gt;
&lt;/tool&gt;</config-example>
        </toolinfo>

        <methods/>

    </section>

    <section name="getBean()">
        <primary>
        <method name="getBean()">
    
            <abstract>
                Retrieve and return the form bean associated with this request.
            </abstract>
    
            <signature>
                ActionForm getBean()
            </signature>
                
            <returns>
                The <code>ActionForm</code> associated with this request/session or 
                <code>null</code> if there is no form bean associated with this mapping.
            </returns>
                
            <description>
                <p>This is a convenience method. The form bean is automatically 
                available in the Velocity context under the name defined in the 
                Struts configuration.</p> 
     
                <p>If the form bean is used repeatedly, it is recommended to create a 
                local variable referencing the bean rather than calling getBean()
                multiple times.</p>
                                
<sourcecode>## Populating an input field with a default value
&lt;input type="text" name="username" value="$form.getBean().username"&gt;

## The same can be written as
&lt;input type="text" name="username" value="$form.bean.username"&gt;

## For repeated use create a local reference
#set ($defaults = $form.bean) 
&lt;input type="text" name="username" value="$defaults.username"&gt;

## Accessing the form using the form name defined in struts-config.xml
## Velocity searches the request and session attributes for loginForm
&lt;input type="text" name="username" value="$loginForm.username"&gt;</sourcecode>
            </description>
    
        </method>
        </primary>
        <method name="getBean()">
    
            <abstract>
                リクエストに関連するフォームビーンを取得し、返却します。
            </abstract>
    
            <signature>
                ActionForm getBean()
            </signature>
                
            <returns>
                request/sessionに関連する <code>ActionForm</code> 、
                関連するフォームビーンがマッピングに無い場合は <code>null</code> 。
            </returns>
                
            <description>
                <p>これは簡易メソッドです。
                フォームビーンは、Velocity コンテキストから Struts 
                の設定で定義した名称で自動的に利用できます。</p> 
     
                <p>フォームビーンを繰り返し使用する場合、
                毎回 getBean() を呼び出すより、ローカル変数を作成して参照すると良いでしょう。</p>
                                
<sourcecode>## インプットフィールドにデフォルト値を設定し、値を取得します
&lt;input type="text" name="username" value="$form.getBean().username"&gt;

## こう書いても上と同じです
&lt;input type="text" name="username" value="$form.bean.username"&gt;

## 繰り返し参照する場合はローカル変数として定義します
#set ($defaults = $form.bean) 
&lt;input type="text" name="username" value="$defaults.username"&gt;

## struts-config.xml で定義されたフォームの名前を使用してフォームへアクセスします
## Velocity は loginForm を request や session の属性(attribute)から検索します
&lt;input type="text" name="username" value="$loginForm.username"&gt;</sourcecode>
            </description>
    
        </method>
    </section>

    <section name="getCancelName()">
        <primary>
        <method name="getCancelName()">
    
            <abstract>
                Returns the query parameter name under which a cancel button press 
                must be reported if form validation is to be skipped.
            </abstract>
    
            <signature>
                int getCancelName()
            </signature>
                
            <returns>
                The value of <code>org.apache.struts.taglib.html.Constants.CANCEL_PROPERTY</code>
            </returns>
       
            <description>
                <p>If a request contains a request parameter with key equal to the return value
                of this method, then automatic form validation is skipped. A typical application
                case is to use this magic string for the name attribute of a cancel button in a form.
                If this button is pressed, automatic form validation is skipped. If automatic form 
                validation is not used, this magic string is irrelevant.</p>

<sourcecode>## A cancel button
&lt;input type="submit" name="$form.getCancelName()" value="Cancel"&gt;

## Can also be written as
&lt;input type="submit" name="$form.cancelName" value="Cancel"&gt;</sourcecode>

<p>This produces the following output:</p>

<sourcecode>&lt;input type="submit" name="org.apache.struts.taglib.html.CANCEL"
value="Cancel"&gt;</sourcecode>

            </description>

        </method>
        </primary>
        <method name="getCancelName()">
    
            <abstract>
                キャンセルボタンが押下された場合の、
                フォームの自動バリデーションのスキップを通知するクエリパラメータの名称を返却します。
            </abstract>
    
            <signature>
                int getCancelName()
            </signature>
                
            <returns>
                <code>org.apache.struts.taglib.html.Constants.CANCEL_PROPERTY</code> の値。
            </returns>
       
            <description>
                <p>リクエストパラメータのキーにこのメソッドの返却値と同じ値が含まれていた場合、フォームの自動バリデーションがスキップされます。
                一般的なアプリケーションでは、フォームのキャンセルボタンの name 属性でこの「おまじない」を使います。
                このボタンが押下された場合、フォームの自動バリデーションがスキップされます。
                もしフォームの自動バリデーションを行っていない場合、この「おまじない」は何の意味もありません。</p>

<sourcecode>## キャンセルボタン
&lt;input type="submit" name="$form.getCancelName()" value="Cancel"&gt;

## これはこのようにも書けます
&lt;input type="submit" name="$form.cancelName" value="Cancel"&gt;</sourcecode>

<p>これは以下の出力を生成します:</p>

<sourcecode>&lt;input type="submit" name="org.apache.struts.taglib.html.CANCEL"
value="Cancel"&gt;</sourcecode>

            </description>

        </method>
    </section>

    <section name="getToken()">
        <primary>
        <method name="getToken()">
    
            <abstract>
                Retrieves and returns the transaction control token for this session.
            </abstract>
    
            <signature>
                String getToken()
            </signature>
                
            <returns>
                The token <code>String</code> or <code>null</code> if no token exists.
            </returns>

            <see>
                Method <a href="#getTokenName()"><code>getTokenName()</code></a> for examples. 
            </see>

        </method>
        </primary>
        <method name="getToken()">
    
            <abstract>
                現在のセッションのトランザクション制御トークンを取得し、返却します。
            </abstract>
    
            <signature>
                String getToken()
            </signature>
                
            <returns>
                トークン <code>String</code> 、またはトークンが存在しない場合 <code>null</code> 。
            </returns>

            <see>
                <a href="#getTokenName()"><code>getTokenName()</code></a> メソッドに例があります。
            </see>

        </method>
    </section>

    <section name="getTokenName()">
        <primary>
        <method name="getTokenName()">
    
            <abstract>
                Returns the query parameter name under which a transaction token
                must be reported.
            </abstract>
    
            <signature>
                int getTokenName()
            </signature>
                
            <returns>
                The value of <code>org.apache.struts.taglib.html.Constants.TOKEN_KEY</code>
            </returns>

            <see>
                <a href="http://jakarta.apache.org/struts/api/org/apache/struts/action/Action.html">
                JavaDoc of class <code>org.apache.struts.action.Action</code></a> for more information on the 
                transaction token mechanism (I don't know of any better documentation of this Struts
                feature).
            </see>

       
            <description>
<sourcecode>## A hidden form field with the transaction token
&lt;input type="hidden" name="$form.getTokenName()"
value="$form.getToken()"&gt;

## Can also be written as
&lt;input type="hidden" name="$form.tokenName"
value="$form.token"&gt;</sourcecode>

<p>This produces output similar to:</p>

<sourcecode>&lt;input type="hidden" name="org.apache.struts.taglib.html.TOKEN" 
value="84c29b4dea56ecf69524ef6b965c5e80"&gt;</sourcecode>
            </description>

        </method>
        </primary>
        <method name="getTokenName()">
    
            <abstract>
                トランザクショントークンを通知するクエリパラメータの名称を返却します。
            </abstract>
    
            <signature>
                int getTokenName()
            </signature>
                
            <returns>
                <code>org.apache.struts.taglib.html.Constants.TOKEN_KEY</code> の値。
            </returns>

            <see>
                トランザクショントークンの仕組みの詳細については
                <a href="http://jakarta.apache.org/struts/api/org/apache/struts/action/Action.html">
                <code>org.apache.struts.action.Action</code> クラスの JavaDoc</a>
                を参照してください
                (この Struts の機能のドキュメントとして、これより良いものを私は知りません)。
            </see>

       
            <description>
<sourcecode>## トランザクショントークンの hidden フィールド
&lt;input type="hidden" name="$form.getTokenName()"
value="$form.getToken()"&gt;

## これはこのようにも書けます
&lt;input type="hidden" name="$form.tokenName()"
value="$form.token()"&gt;</sourcecode>

<p>このような出力が生成されます:</p>

<sourcecode>&lt;input type="hidden" name="org.apache.struts.taglib.html.TOKEN" 
value="84c29b4dea56ecf69524ef6b965c5e80"&gt;</sourcecode>
            </description>

        </method>
    </section>

 </body>
</document>
