Source

webwork / docs / wikidocs / TutorialLesson04-02.html

<html>
    <head>
        <title>WebWork 2 : TutorialLesson04-02</title>
	    <link rel="stylesheet" href="styles/site.css" type="text/css" />
        <META http-equiv="Content-Type" content="text/html; charset=UTF-8">	    
    </head>

    <body>
	    <table class="pagecontent" border="0" cellpadding="0" cellspacing="0" width="100%" bgcolor="#ffffff">
		    <tr>
			    <td valign="top" class="pagebody">
				    <div class="pageheader">
					    <span class="pagetitle">
                            WebWork 2 : TutorialLesson04-02
                                                    </span>
				    </div>
				    <div class="pagesubheading">
					    This page last changed on Sep 16, 2004 by <font color="#0050B2">vitorsouza</font>.
				    </div>

				    <p class="paragraph"><h1 style="margin: 4px 0px 4px 0px;" class="heading1"><a name="TutorialLesson04-02-Lesson4.2%3AUsingVelocitywithWebWork"> Lesson 4.2: Using Velocity with WebWork</a></h1></p>There are two ways of using Velocity as the view.<br/>

<ul class="star">
<li> Using the <tt class="monospaced">velocity</tt> result-type to render velocity templates;</li>
<li> Registering <tt class="monospaced">WebWorkVelocityServlet</tt> in your <tt class="monospaced">web.xml</tt> file to render Velocity templates accessed directly through browser requests.</li>
</ul><br/>
To use the second approach, we have to modify <tt class="monospaced">web.xml</tt> and add a servlet and a servlet mapping for <tt class="monospaced">WebWorkVelocityServlet</tt>, as demonstrated below:<br/>

<div class="code"><div class="codeContent">
<pre><span class="xml&#45;tag">&lt;servlet&gt;</span> &#10;	<span class="xml&#45;tag">&lt;servlet&#45;name&gt;</span>velocity<span class="xml&#45;tag">&lt;/servlet&#45;name&gt;</span> &#10;	<span class="xml&#45;tag">&lt;servlet&#45;class&gt;</span>com.opensymphony.webwork.views.velocity.WebWorkVelocityServlet<span class="xml&#45;tag">&lt;/servlet&#45;class&gt;</span> &#10;	<span class="xml&#45;tag">&lt;load&#45;on&#45;startup&gt;</span>1<span class="xml&#45;tag">&lt;/load&#45;on&#45;startup&gt;</span> &#10;<span class="xml&#45;tag">&lt;/servlet&gt;</span> &#10;&#10;<span class="xml&#45;tag">&lt;servlet&#45;mapping&gt;</span> &#10;	<span class="xml&#45;tag">&lt;servlet&#45;name&gt;</span>velocity<span class="xml&#45;tag">&lt;/servlet&#45;name&gt;</span> &#10;	<span class="xml&#45;tag">&lt;url&#45;pattern&gt;</span>&#42;.vm<span class="xml&#45;tag">&lt;/url&#45;pattern&gt;</span> &#10;<span class="xml&#45;tag">&lt;/servlet&#45;mapping&gt;</span></pre>
</div></div><br/>

<blockquote class="blockquote"> Read more: <a href="xwork.xml.html" title="xwork.xml">xwork.xml</a></blockquote><p class="paragraph">Using <tt class="monospaced">velocity</tt> result-type means that Velocity templates can only be rendered through an action, i.e., request to <tt class="monospaced">.vm</tt> pages will not render the file and it will be returned as plain text. If you choose this approach, it&#039;s recommended that you place your Velocity files under <tt class="monospaced">WEB-INF</tt> so they become unaccessible.</p>Using <tt class="monospaced">WebWorkVelocityServlet</tt> means that Velocity templates can be rendered through requests to <tt class="monospaced">.vm</tt> pages. That also means that you should implement security checks in your templates so an user doesn&#039;t access it directly witout going through an action first (if that is required). <p class="paragraph">No matter which approach you choose (and you can choose to use both at the same time), not only all the features from Velocity are available to you when you&#039;re writing templates, but also some other functionalities, specific of WebWork, are available. It is supposed that you are already familiar with Velocity, so we will focus only in the WebWork-specific features. If that&#039;s not the case, please <a href="http://jakarta.apache.org/velocity/getting-started.html" title="Visit page outside Confluence">get started with Velocity</a> before continuing.</p>The main feature of it is to provide easy access to objects that are on the Value Stack, which contains some things that WebWork provides to you automatically, because you may find them useful at some point. These are some of the things that are available in the value stack:<br/>

<ul class="star">
<li> The current <tt class="monospaced">HttpServletRequest</tt>;</li>
<li> The current <tt class="monospaced">HttpServletResponse</tt>;</li>
<li> The current <tt class="monospaced">OgnlValueStack</tt>;</li>
<li> An instance of <tt class="monospaced">OgnlTool</tt>;</li>
<li> All the properties of the current action class.</li>
</ul><br/>
To access the objects in the value stack, all you have to do is use appropriate Velocity references:<br/>

<ul class="star">
<li> <b class="strong"><tt class="monospaced">$req</tt></b> = <tt class="monospaced">HttpServletRequest</tt>;</li>
<li> <b class="strong"><tt class="monospaced">$res</tt></b> = <tt class="monospaced">HttpServletResponse</tt>;</li>
<li> <b class="strong"><tt class="monospaced">$stack</tt></b> = <tt class="monospaced">OgnlValueStack</tt>;</li>
<li> <b class="strong"><tt class="monospaced">$ognl</tt></b> = <tt class="monospaced">OgnlTool</tt>;</li>
<li> <b class="strong"><tt class="monospaced">$name-of-property</tt></b> = property of the current action class.</li>
</ul><br/>
The example below does the same thing as the Hello example from <a href="TutorialLesson03.html" title="TutorialLesson03">lesson 3</a>, but now, using a Velocity template as the result. Notice that the <tt class="monospaced">&lt;property value=&quot;person&quot; /&gt;</tt> tag was replaced by the <tt class="monospaced">$person</tt> reference, which returns the same thing: a property from the action class. In this example we chose to use the <em class="emphasis"><tt class="monospaced">velocity</tt> result-type</em> approach.<p class="paragraph"><h3 class="heading3"><a name="TutorialLesson04-02-xwork.xml%3A"> xwork.xml:</a></h3>
<div class="code"><div class="codeContent">
<pre><span class="xml&#45;tag">&lt;&#33;DOCTYPE xwork PUBLIC <span class="xml&#45;quote">&quot;&#45;//OpenSymphony Group//XWork 1.0//EN&quot;</span> &#10;<span class="xml&#45;quote">&quot;&#104;ttp://www.opensymphony.com/xwork/xwork&#45;1.0.dtd&quot;</span>&gt;</span>&#10;&#10;<span class="xml&#45;tag">&lt;xwork&gt;</span>&#10;	<span class="xml&#45;tag"><span class="xml&#45;comment">&lt;&#33;&#45;&#45; Include webwork defaults (from WebWork JAR). &#45;&#45;&gt;</span></span>&#10;	<span class="xml&#45;tag">&lt;include file=<span class="xml&#45;quote">&quot;webwork&#45;default.xml&quot;</span> /&gt;</span>&#10;	&#10;	<span class="xml&#45;tag"><span class="xml&#45;comment">&lt;&#33;&#45;&#45; Configuration for the default package. &#45;&#45;&gt;</span></span>&#10;	<span class="xml&#45;tag">&lt;package name=<span class="xml&#45;quote">&quot;default&quot;</span> extends=<span class="xml&#45;quote">&quot;webwork&#45;default&quot;</span>&gt;</span>&#10;		<span class="xml&#45;tag"><span class="xml&#45;comment">&lt;&#33;&#45;&#45; Default interceptor stack. &#45;&#45;&gt;</span></span> &#10;		<span class="xml&#45;tag">&lt;default&#45;interceptor&#45;ref name=<span class="xml&#45;quote">&quot;defaultStack&quot;</span> /&gt;</span> &#10;		&#10;		<span class="xml&#45;tag"><span class="xml&#45;comment">&lt;&#33;&#45;&#45; Action: Lesson 4.2: HelloAction using Velocity as result. &#45;&#45;&gt;</span></span>&#10;		<span class="xml&#45;tag">&lt;action name=<span class="xml&#45;quote">&quot;helloVelocity&quot;</span> class=<span class="xml&#45;quote">&quot;lesson03.HelloAction&quot;</span>&gt;</span>&#10;			<span class="xml&#45;tag">&lt;result name=<span class="xml&#45;quote">&quot;error&quot;</span> type=<span class="xml&#45;quote">&quot;dispatcher&quot;</span>&gt;</span>ex01&#45;index.jsp<span class="xml&#45;tag">&lt;/result&gt;</span>&#10;			<span class="xml&#45;tag">&lt;result name=<span class="xml&#45;quote">&quot;success&quot;</span> type=<span class="xml&#45;quote">&quot;velocity&quot;</span>&gt;</span>ex01&#45;success.vm<span class="xml&#45;tag">&lt;/result&gt;</span>&#10;		<span class="xml&#45;tag">&lt;/action&gt;</span>&#10;	<span class="xml&#45;tag">&lt;/package&gt;</span>&#10;<span class="xml&#45;tag">&lt;/xwork&gt;</span></pre>
</div></div></p><h3 class="heading3"><a name="TutorialLesson04-02-HelloAction.java%28sameaslesson3%29%3A"> HelloAction.java (same as lesson 3):</a></h3>
<div class="code"><div class="codeContent">
<pre><span class="java&#45;keyword">package</span> lesson03;&#10;&#10;<span class="java&#45;keyword">import</span> com.opensymphony.xwork.ActionSupport;&#10;&#10;<span class="java&#45;keyword">public</span> class HelloAction <span class="java&#45;keyword">extends</span> ActionSupport &#123;&#10;	<span class="java&#45;object">String</span> person;&#10;	<span class="java&#45;keyword">public</span>&#160;<span class="java&#45;object">String</span> getPerson() &#123;&#10;		<span class="java&#45;keyword">return</span> person;&#10;	&#125;&#10;	<span class="java&#45;keyword">public</span> void setPerson(<span class="java&#45;object">String</span> person) &#123;&#10;		<span class="java&#45;keyword">this</span>.person = person;&#10;	&#125;&#10;	<span class="java&#45;keyword">public</span>&#160;<span class="java&#45;object">String</span> execute() <span class="java&#45;keyword">throws</span> Exception &#123;&#10;		<span class="java&#45;keyword">if</span> ((person == <span class="java&#45;keyword">null</span>) || (person.length() == 0)) <span class="java&#45;keyword">return</span> ERROR;&#10;		<span class="java&#45;keyword">else</span>&#160;<span class="java&#45;keyword">return</span> SUCCESS;&#10;	&#125;&#10;&#125;</pre>
</div></div><p class="paragraph"><h3 class="heading3"><a name="TutorialLesson04-02-ex01index.jsp%28sameaslesson3%29%3A"> ex01-index.jsp (same as lesson 3):</a></h3>
<div class="code"><div class="codeContent">
<pre>&lt;html&gt;&#10;&lt;head&gt;&#10;&lt;title&gt;WebWork Tutorial &#45; Lesson 3 &#45; Example 2&lt;/title&gt;&#10;&lt;/head&gt;&#10;&#10;&lt;body&gt;&#10;&#10;&lt;p&gt;What&#039;s your name&#63;&lt;/p&gt;&#10;&#10;&lt;form action=<span class="java&#45;quote">&quot;hello.action&quot;</span> method=<span class="java&#45;quote">&quot;post&quot;</span>&gt;&#10;&lt;p&gt;&lt;input type=<span class="java&#45;quote">&quot;text&quot;</span> name=<span class="java&#45;quote">&quot;person&quot;</span> /&gt;&lt;input type=<span class="java&#45;quote">&quot;submit&quot;</span> /&gt;&lt;/p&gt;&#10;&lt;/form&gt;&#10;&#10;&lt;/body&gt;&#10;&lt;/html&gt;</pre>
</div></div></p><h3 class="heading3"><a name="TutorialLesson04-02-ex01success.vm%3A"> ex01-success.vm:</a></h3>
<div class="code"><div class="codeContent">
<pre>&lt;html&gt; &#10;&lt;head&gt; &#10;&lt;title&gt;WebWork Tutorial &#45; Lesson 4.2 &#45; Example 1&lt;/title&gt; &#10;&lt;/head&gt; &#10;&lt;body&gt; &#10;&#10;Hello, $person &#10;&#10;&lt;/body&gt; &#10;&lt;/html&gt;</pre>
</div></div><br/>

<blockquote class="blockquote"> <a href="TutorialExamples.html" title="TutorialExamples">Try the example!</a></blockquote>
<p class="paragraph"><h2 class="heading2"><a name="TutorialLesson04-02-UsingWebWorkTagsfromVelocity%3A"> Using WebWork Tags from Velocity:</a></h2></p>As you already know, when you switch from JSP to Velocity you lose the ability of using JSP Tags. But WebWork&#039;s Velocity Servlet provides a way of doing this through the use of <tt class="monospaced">#tag</tt>, <tt class="monospaced">#bodytag</tt> and <tt class="monospaced">#param</tt> velocimacros. The general syntax is:<br/>

<div class="code"><div class="codeContent">
<pre>#tag (name&#45;of&#45;tag list&#45;of&#45;attributes)</pre>
</div></div><p class="paragraph">&#8211; or &#8211;</p><div class="code"><div class="codeContent">
<pre>#bodytag (name&#45;of&#45;tag list&#45;of&#45;attributes)&#10;	#param (key value)&#10;	#param (key value)&#10;...&#10;#end</pre>
</div></div><p class="paragraph">Let&#039;s revisit <a href="TutorialLesson04-01-01.html" title="TutorialLesson04-01-01">lesson 4.1.1</a>&#039;s form example to demonstrate the usage of the UI tags from velocity:</p><h3 class="heading3"><a name="TutorialLesson04-02-xwork.xml%3A"> xwork.xml:</a></h3>
<div class="code"><div class="codeContent">
<pre><span class="xml&#45;tag">&lt;&#33;DOCTYPE xwork PUBLIC <span class="xml&#45;quote">&quot;&#45;//OpenSymphony Group//XWork 1.0//EN&quot;</span> &#10;<span class="xml&#45;quote">&quot;&#104;ttp://www.opensymphony.com/xwork/xwork&#45;1.0.dtd&quot;</span>&gt;</span>&#10;&#10;<span class="xml&#45;tag">&lt;xwork&gt;</span>&#10;	<span class="xml&#45;tag"><span class="xml&#45;comment">&lt;&#33;&#45;&#45; Include webwork defaults (from WebWork JAR). &#45;&#45;&gt;</span></span>&#10;	<span class="xml&#45;tag">&lt;include file=<span class="xml&#45;quote">&quot;webwork&#45;default.xml&quot;</span> /&gt;</span>&#10;	&#10;	<span class="xml&#45;tag"><span class="xml&#45;comment">&lt;&#33;&#45;&#45; Configuration for the default package. &#45;&#45;&gt;</span></span>&#10;	<span class="xml&#45;tag">&lt;package name=<span class="xml&#45;quote">&quot;default&quot;</span> extends=<span class="xml&#45;quote">&quot;webwork&#45;default&quot;</span>&gt;</span>&#10;		<span class="xml&#45;tag"><span class="xml&#45;comment">&lt;&#33;&#45;&#45; Default interceptor stack. &#45;&#45;&gt;</span></span> &#10;		<span class="xml&#45;tag">&lt;default&#45;interceptor&#45;ref name=<span class="xml&#45;quote">&quot;defaultStack&quot;</span> /&gt;</span> &#10;		&#10;		<span class="xml&#45;tag"><span class="xml&#45;comment">&lt;&#33;&#45;&#45; Actions: Lesson 4.2: FormProcessingAction using Velocity. &#45;&#45;&gt;</span></span> &#10;		<span class="xml&#45;tag">&lt;action name=<span class="xml&#45;quote">&quot;formProcessingVelocityIndex&quot;</span> class=<span class="xml&#45;quote">&quot;lesson04&#95;02.FormProcessingIndexAction&quot;</span>&gt;</span>&#10;			<span class="xml&#45;tag">&lt;result name=<span class="xml&#45;quote">&quot;success&quot;</span> type=<span class="xml&#45;quote">&quot;velocity&quot;</span>&gt;</span>ex02&#45;index.vm<span class="xml&#45;tag">&lt;/result&gt;</span>&#10;		<span class="xml&#45;tag">&lt;/action&gt;</span>&#10;		<span class="xml&#45;tag">&lt;action name=<span class="xml&#45;quote">&quot;formProcessingVelocity&quot;</span> class=<span class="xml&#45;quote">&quot;lesson04&#95;01&#95;01.FormProcessingAction&quot;</span>&gt;</span> &#10;			<span class="xml&#45;tag">&lt;result name=<span class="xml&#45;quote">&quot;input&quot;</span> type=<span class="xml&#45;quote">&quot;velocity&quot;</span>&gt;</span>ex02&#45;index.vm<span class="xml&#45;tag">&lt;/result&gt;</span> &#10;			<span class="xml&#45;tag">&lt;result name=<span class="xml&#45;quote">&quot;success&quot;</span> type=<span class="xml&#45;quote">&quot;velocity&quot;</span>&gt;</span>ex02&#45;success.vm<span class="xml&#45;tag">&lt;/result&gt;</span> &#10;			<span class="xml&#45;tag">&lt;interceptor&#45;ref name=<span class="xml&#45;quote">&quot;validationWorkflowStack&quot;</span> /&gt;</span> &#10;		<span class="xml&#45;tag">&lt;/action&gt;</span> &#10;	<span class="xml&#45;tag">&lt;/package&gt;</span>&#10;<span class="xml&#45;tag">&lt;/xwork&gt;</span></pre>
</div></div><p class="paragraph"><h3 class="heading3"><a name="TutorialLesson04-02-ex02index.vm%3A"> ex02-index.vm:</a></h3>
<div class="code"><div class="codeContent">
<pre>&lt;html&gt; &#10;&lt;head&gt; &#10;&lt;title&gt;WebWork Tutorial &#45; Lesson 4.2 &#45; Example 2&lt;/title&gt; &#10;&lt;style type=<span class="java&#45;quote">&quot;text/css&quot;</span>&gt; &#10;  .errorMessage &#123; color: red; &#125; &#10;&lt;/style&gt;   &#10;&lt;/head&gt; &#10;&#10;&lt;body&gt; &#10;&#10;&lt;p&gt;UI Form Tags Example using Velocity:&lt;/p&gt; &#10;&#10;#bodytag (Form <span class="java&#45;quote">&quot;action=&#039;formProcessingVelocity.action&#039;&quot;</span>&#160;<span class="java&#45;quote">&quot;method=&#039;post&#039;&quot;</span>) &#10;	#tag (Checkbox <span class="java&#45;quote">&quot;name=&#039;checkbox&#039;&quot;</span>&#160;<span class="java&#45;quote">&quot;label=&#039;A checkbox&#039;&quot;</span>&#160;<span class="java&#45;quote">&quot;fieldValue=&#039;checkbox&#95;value&#039;&quot;</span>) &#10;	#tag (File <span class="java&#45;quote">&quot;name=&#039;file&#039;&quot;</span>&#160;<span class="java&#45;quote">&quot;label=&#039;A file field&#039;&quot;</span>) &#10;	#tag (Hidden <span class="java&#45;quote">&quot;name=&#039;hidden&#039;&quot;</span>&#160;<span class="java&#45;quote">&quot;value=&#039;hidden&#95;value&#039;&quot;</span>) &#10;	#tag (Label <span class="java&#45;quote">&quot;label=&#039;A label&#039;&quot;</span>) &#10;	#tag (Password <span class="java&#45;quote">&quot;name=&#039;password&#039;&quot;</span>&#160;<span class="java&#45;quote">&quot;label=&#039;A password field&#039;&quot;</span>) &#10;	#tag (Radio <span class="java&#45;quote">&quot;name=&#039;radio&#039;&quot;</span>&#160;<span class="java&#45;quote">&quot;label=&#039;Radio buttons&#039;&quot;</span>&#160;<span class="java&#45;quote">&quot;list=&#123;&#039;One&#039;, &#039;Two&#039;, &#039;Three&#039;&#125;&quot;</span>) &#10;	#tag (Select <span class="java&#45;quote">&quot;name=&#039;select&#039;&quot;</span>&#160;<span class="java&#45;quote">&quot;label=&#039;A select list&#039;&quot;</span>&#160;<span class="java&#45;quote">&quot;list=&#123;&#039;One&#039;, &#039;Two&#039;, &#039;Three&#039;&#125;&quot;</span> &#10;		<span class="java&#45;quote">&quot;emptyOption=<span class="java&#45;keyword">true</span>&quot;</span>) &#10;	#tag (Textarea <span class="java&#45;quote">&quot;name=&#039;textarea&#039;&quot;</span>&#160;<span class="java&#45;quote">&quot;label=&#039;A text area&#039;&quot;</span>&#160;<span class="java&#45;quote">&quot;rows=&#039;3&#039;&quot;</span>&#160;<span class="java&#45;quote">&quot;cols=&#039;40&#039;&quot;</span>) &#10;	#tag (TextField <span class="java&#45;quote">&quot;name=&#039;textfield&#039;&quot;</span>&#160;<span class="java&#45;quote">&quot;label=&#039;A text field&#039;&quot;</span>) &#10;	#tag (Submit <span class="java&#45;quote">&quot;value=&#039;Send Form&#039;&quot;</span>) &#10;#end &#10;&#10;&lt;/body&gt; &#10;&lt;/html&gt;</pre>
</div></div></p><h3 class="heading3"><a name="TutorialLesson04-02-ex02success.vm%3A"> ex02-success.vm:</a></h3>
<div class="code"><div class="codeContent">
<pre>&lt;html&gt; &#10;&lt;head&gt; &#10;&lt;title&gt;WebWork Tutorial Lesson 4.2 &#45; Example 2&lt;/title&gt; &#10;&lt;/head&gt; &#10;&#10;&lt;body&gt; &#10;&#10;&lt;p&gt;UI Form Tags Example result using Velocity:&lt;/p&gt; &#10;&#10;&lt;ul&gt; &#10;	&lt;li&gt;checkbox: $&#33;checkbox&lt;/li&gt; &#10;	&lt;li&gt;&#102;ile: $&#33;file&lt;/li&gt; &#10;	&lt;li&gt;hidden: $&#33;hidden&lt;/li&gt; &#10;	&lt;li&gt;password: $&#33;password&lt;/li&gt; &#10;	&lt;li&gt;radio: $&#33;radio&lt;/li&gt; &#10;	&lt;li&gt;select: $&#33;select&lt;/li&gt; &#10;	&lt;li&gt;textarea: $&#33;textarea&lt;/li&gt; &#10;	&lt;li&gt;textfield: $&#33;textfield&lt;/li&gt; &#10;&lt;/ul&gt; &#10;&#10;&lt;/body&gt; &#10;&lt;/html&gt;</pre>
</div></div><p class="paragraph"><h3 class="heading3"><a name="TutorialLesson04-02-FormProcessingAction.java%28sameaslesson4.1.1%29%3A"> FormProcessingAction.java (same as lesson 4.1.1):</a></h3>
<div class="code"><div class="codeContent">
<pre><span class="java&#45;keyword">package</span> lesson04&#95;01&#95;01;&#10;&#10;<span class="java&#45;keyword">import</span> com.opensymphony.xwork.ActionSupport;&#10;&#10;<span class="java&#45;keyword">public</span> class FormProcessingAction <span class="java&#45;keyword">extends</span> ActionSupport &#123;&#10;	<span class="java&#45;keyword">private</span>&#160;<span class="java&#45;object">String</span> checkbox;&#10;	<span class="java&#45;keyword">private</span>&#160;<span class="java&#45;object">String</span> file;&#10;	<span class="java&#45;keyword">private</span>&#160;<span class="java&#45;object">String</span> hidden;&#10;	<span class="java&#45;keyword">private</span>&#160;<span class="java&#45;object">String</span> password;&#10;	<span class="java&#45;keyword">private</span>&#160;<span class="java&#45;object">String</span> radio;&#10;	<span class="java&#45;keyword">private</span>&#160;<span class="java&#45;object">String</span> select;&#10;	<span class="java&#45;keyword">private</span>&#160;<span class="java&#45;object">String</span> textarea;&#10;	<span class="java&#45;keyword">private</span>&#160;<span class="java&#45;object">String</span> textfield;&#10;	&#10;	<span class="java&#45;keyword">public</span>&#160;<span class="java&#45;object">String</span> getCheckbox() &#123; <span class="java&#45;keyword">return</span> checkbox; &#125;&#10;	<span class="java&#45;keyword">public</span>&#160;<span class="java&#45;object">String</span> getFile() &#123; <span class="java&#45;keyword">return</span> file; &#125;&#10;	<span class="java&#45;keyword">public</span>&#160;<span class="java&#45;object">String</span> getHidden() &#123; <span class="java&#45;keyword">return</span> hidden; &#125;&#10;	<span class="java&#45;keyword">public</span>&#160;<span class="java&#45;object">String</span> getPassword() &#123; <span class="java&#45;keyword">return</span> password; &#125;&#10;	<span class="java&#45;keyword">public</span>&#160;<span class="java&#45;object">String</span> getRadio() &#123; <span class="java&#45;keyword">return</span> radio; &#125;&#10;	<span class="java&#45;keyword">public</span>&#160;<span class="java&#45;object">String</span> getSelect() &#123; <span class="java&#45;keyword">return</span> select; &#125;&#10;	<span class="java&#45;keyword">public</span>&#160;<span class="java&#45;object">String</span> getTextarea() &#123; <span class="java&#45;keyword">return</span> textarea; &#125;&#10;	<span class="java&#45;keyword">public</span>&#160;<span class="java&#45;object">String</span> getTextfield() &#123; <span class="java&#45;keyword">return</span> textfield; &#125;&#10;	&#10;	<span class="java&#45;keyword">public</span> void setCheckbox(<span class="java&#45;object">String</span> checkbox) &#123; <span class="java&#45;keyword">this</span>.checkbox = checkbox; &#125;&#10;	<span class="java&#45;keyword">public</span> void setFile(<span class="java&#45;object">String</span> file) &#123; <span class="java&#45;keyword">this</span>.file = file; &#125;&#10;	<span class="java&#45;keyword">public</span> void setHidden(<span class="java&#45;object">String</span> hidden) &#123; <span class="java&#45;keyword">this</span>.hidden = hidden; &#125;&#10;	<span class="java&#45;keyword">public</span> void setPassword(<span class="java&#45;object">String</span> password) &#123; <span class="java&#45;keyword">this</span>.password = password; &#125;&#10;	<span class="java&#45;keyword">public</span> void setRadio(<span class="java&#45;object">String</span> radio) &#123; <span class="java&#45;keyword">this</span>.radio = radio; &#125;&#10;	<span class="java&#45;keyword">public</span> void setSelect(<span class="java&#45;object">String</span> select) &#123; <span class="java&#45;keyword">this</span>.select = select; &#125;&#10;	<span class="java&#45;keyword">public</span> void setTextarea(<span class="java&#45;object">String</span> textarea) &#123; <span class="java&#45;keyword">this</span>.textarea = textarea; &#125;&#10;	<span class="java&#45;keyword">public</span> void setTextfield(<span class="java&#45;object">String</span> textfield) &#123; <span class="java&#45;keyword">this</span>.textfield = textfield; &#125;&#10;	&#10;	<span class="java&#45;keyword">public</span>&#160;<span class="java&#45;object">String</span> execute() <span class="java&#45;keyword">throws</span> Exception &#123;&#10;		<span class="java&#45;keyword">return</span> SUCCESS;&#10;	&#125;&#10;&#125;</pre>
</div></div></p><h3 class="heading3"><a name="TutorialLesson04-02-FormProcessingActionvalidation.xml%28sameaslesson4.1.1%29%3A"> FormProcessingAction-validation.xml (same as lesson 4.1.1):</a></h3>
<div class="code"><div class="codeContent">
<pre><span class="xml&#45;tag">&lt;&#33;DOCTYPE validators PUBLIC <span class="xml&#45;quote">&quot;&#45;//OpenSymphony Group//XWork Validator &#10;1.0//EN&quot;</span>&#160;<span class="xml&#45;quote">&quot;&#104;ttp://www.opensymphony.com/xwork/xwork&#45;validator&#45;1.0.dtd&quot;</span>&gt;</span>&#10;&#10;<span class="xml&#45;tag">&lt;validators&gt;</span>&#10;  <span class="xml&#45;tag">&lt;field name=<span class="xml&#45;quote">&quot;checkbox&quot;</span>&gt;</span>&#10;    <span class="xml&#45;tag">&lt;field&#45;validator type=<span class="xml&#45;quote">&quot;requiredstring&quot;</span>&gt;</span>&#10;      <span class="xml&#45;tag">&lt;message&gt;</span>Please, check the checkbox.<span class="xml&#45;tag">&lt;/message&gt;</span>&#10;    <span class="xml&#45;tag">&lt;/field&#45;validator&gt;</span>&#10;  <span class="xml&#45;tag">&lt;/field&gt;</span>&#10;&#10;  <span class="xml&#45;tag">&lt;field name=<span class="xml&#45;quote">&quot;file&quot;</span>&gt;</span>&#10;    <span class="xml&#45;tag">&lt;field&#45;validator type=<span class="xml&#45;quote">&quot;requiredstring&quot;</span>&gt;</span>&#10;      <span class="xml&#45;tag">&lt;message&gt;</span>Please select a file.<span class="xml&#45;tag">&lt;/message&gt;</span>&#10;    <span class="xml&#45;tag">&lt;/field&#45;validator&gt;</span>&#10;  <span class="xml&#45;tag">&lt;/field&gt;</span>&#10;&#10;  <span class="xml&#45;tag">&lt;field name=<span class="xml&#45;quote">&quot;password&quot;</span>&gt;</span>&#10;    <span class="xml&#45;tag">&lt;field&#45;validator type=<span class="xml&#45;quote">&quot;requiredstring&quot;</span>&gt;</span>&#10;      <span class="xml&#45;tag">&lt;message&gt;</span>Please type something in the password field.<span class="xml&#45;tag">&lt;/message&gt;</span>&#10;    <span class="xml&#45;tag">&lt;/field&#45;validator&gt;</span>&#10;  <span class="xml&#45;tag">&lt;/field&gt;</span>&#10;&#10;  <span class="xml&#45;tag">&lt;field name=<span class="xml&#45;quote">&quot;radio&quot;</span>&gt;</span>&#10;    <span class="xml&#45;tag">&lt;field&#45;validator type=<span class="xml&#45;quote">&quot;requiredstring&quot;</span>&gt;</span>&#10;      <span class="xml&#45;tag">&lt;message&gt;</span>Please select a radio button.<span class="xml&#45;tag">&lt;/message&gt;</span>&#10;    <span class="xml&#45;tag">&lt;/field&#45;validator&gt;</span>&#10;  <span class="xml&#45;tag">&lt;/field&gt;</span>&#10;&#10;  <span class="xml&#45;tag">&lt;field name=<span class="xml&#45;quote">&quot;select&quot;</span>&gt;</span>&#10;    <span class="xml&#45;tag">&lt;field&#45;validator type=<span class="xml&#45;quote">&quot;requiredstring&quot;</span>&gt;</span>&#10;      <span class="xml&#45;tag">&lt;message&gt;</span>Please select an option from the list.<span class="xml&#45;tag">&lt;/message&gt;</span>&#10;    <span class="xml&#45;tag">&lt;/field&#45;validator&gt;</span>&#10;  <span class="xml&#45;tag">&lt;/field&gt;</span>&#10;&#10;  <span class="xml&#45;tag">&lt;field name=<span class="xml&#45;quote">&quot;textarea&quot;</span>&gt;</span>&#10;    <span class="xml&#45;tag">&lt;field&#45;validator type=<span class="xml&#45;quote">&quot;requiredstring&quot;</span>&gt;</span>&#10;      <span class="xml&#45;tag">&lt;message&gt;</span>Please type something in the text area.<span class="xml&#45;tag">&lt;/message&gt;</span>&#10;    <span class="xml&#45;tag">&lt;/field&#45;validator&gt;</span>&#10;  <span class="xml&#45;tag">&lt;/field&gt;</span>&#10;&#10;  <span class="xml&#45;tag">&lt;field name=<span class="xml&#45;quote">&quot;textfield&quot;</span>&gt;</span>&#10;    <span class="xml&#45;tag">&lt;field&#45;validator type=<span class="xml&#45;quote">&quot;requiredstring&quot;</span>&gt;</span>&#10;      <span class="xml&#45;tag">&lt;message&gt;</span>Please type something in the text field.<span class="xml&#45;tag">&lt;/message&gt;</span>&#10;    <span class="xml&#45;tag">&lt;/field&#45;validator&gt;</span>&#10;  <span class="xml&#45;tag">&lt;/field&gt;</span>&#10;<span class="xml&#45;tag">&lt;/validators&gt;</span></pre>
</div></div><br/>

<blockquote class="blockquote"> <a href="TutorialExamples.html" title="TutorialExamples">Try the example!</a></blockquote><p class="paragraph">&#8212;</p>The example above does not use the <tt class="monospaced">#param</tt> tag. So, let&#039;s revisit another example from <a href="TutorialLesson04-01-01.html" title="TutorialLesson04-01-01">lesson 4.1.1</a> - custom components:<p class="paragraph"><h3 class="heading3"><a name="TutorialLesson04-02-ex03.vm%3A"> ex03.vm:</a></h3>
<div class="code"><div class="codeContent">
<pre>&lt;html&gt; &#10;&lt;head&gt; &#10;&lt;title&gt;WebWork Tutorial &#45; Lesson 4.2 &#45; Example 3&lt;/title&gt; &#10;&lt;/head&gt; &#10;&#10;&lt;body&gt; &#10;&#10;&lt;p&gt;Custom Component Example:&lt;/p&gt; &#10;&#10;&lt;p&gt; &#10;#bodytag (Component <span class="java&#45;quote">&quot;template=datefield.vm&quot;</span>) &#10;	#param (<span class="java&#45;quote">&quot;label&quot;</span>&#160;<span class="java&#45;quote">&quot;Date&quot;</span>) &#10;	#param (<span class="java&#45;quote">&quot;name&quot;</span>&#160;<span class="java&#45;quote">&quot;mydatefield&quot;</span>) &#10;	#param (<span class="java&#45;quote">&quot;size&quot;</span>&#160;<span class="java&#45;quote">&quot;3&quot;</span>) &#10;#end &#10;&lt;/p&gt; &#10;&#10;&lt;/body&gt; &#10;&lt;/html&gt;</pre>
</div></div></p><h3 class="heading3"><a name="TutorialLesson04-02-%2Ftemplate%2Fxhtml%2Fdatefield.vm%28sameaslesson4.1.1%29%3A"> /template/xhtml/datefield.vm (same as lesson 4.1.1):</a></h3>
<div class="code"><div class="codeContent">
<pre>#set ($name = $parameters.get(&#039;name&#039;)) &#10;#set ($size = $parameters.get(&#039;size&#039;)) &#10;#set ($yearSize = $size &#42; 2) &#10;&#10;$parameters.get(&#039;label&#039;): &#10;&lt;input type=<span class="java&#45;quote">&quot;text&quot;</span> name=<span class="java&#45;quote">&quot;$&#123;name&#125;.day&quot;</span> size=<span class="java&#45;quote">&quot;$size&quot;</span> /&gt; / &#10;&lt;input type=<span class="java&#45;quote">&quot;text&quot;</span> name=<span class="java&#45;quote">&quot;$&#123;name&#125;.month&quot;</span> size=<span class="java&#45;quote">&quot;$size&quot;</span> /&gt; / &#10;&lt;input type=<span class="java&#45;quote">&quot;text&quot;</span> name=<span class="java&#45;quote">&quot;$&#123;name&#125;.year&quot;</span> size=<span class="java&#45;quote">&quot;$yearSize&quot;</span> /&gt; (dd/mm/yyyy)</pre>
</div></div><p class="paragraph">Notice that, this time, we did not enclose <tt class="monospaced">Date</tt> and <tt class="monospaced">mydatefield</tt> with single quotes, as we had to do when we used the JSP tag.</p><blockquote class="blockquote"> <a href="TutorialExamples.html" title="TutorialExamples">Try the example!</a></blockquote><p class="paragraph"><hr class="line"/></p><a href="TutorialLesson04-01.html" title="TutorialLesson04-01">Previous Lesson</a> | <a href="TutorialLesson04-03.html" title="TutorialLesson04-03">Next Lesson</a><br/>



				    
                    			    </td>
		    </tr>
	    </table>
	    <table border="0" cellpadding="0" cellspacing="0" width="100%">
			<tr>
				<td height="12" background="border/border_bottom.gif"><img src="border/spacer.gif" width="1" height="1" border="0"/></td>
			</tr>
		    <tr>
			    <td align="center"><font color="grey">Document generated by Confluence on Oct 18, 2004 00:08</font></td>
		    </tr>
	    </table>
    </body>
</html>
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.