Modified:
websites/production/tapestry/content/forms-and-form-components-faq.html
==============================================================================
--- websites/production/tapestry/content/forms-and-form-components-faq.html
(original)
+++ websites/production/tapestry/content/forms-and-form-components-faq.html Mon
May 21 05:20:56 2018
@@ -78,14 +78,14 @@
<div id="content">
<div id="ConfluenceContent"><h1
id="FormsandFormComponentsFAQ-FormsandFormComponents">Forms and Form
Components</h1><p>Main article: <a href="forms-and-validation.html">Forms and
Validation</a></p><h2
id="FormsandFormComponentsFAQ-Contents">Contents</h2><p><style
type="text/css">/*<![CDATA[*/
-div.rbtoc1523333999330 {padding: 0px;}
-div.rbtoc1523333999330 ul {list-style: disc;margin-left: 0px;}
-div.rbtoc1523333999330 li {margin-left: 0px;padding-left: 0px;}
+div.rbtoc1526880012977 {padding: 0px;}
+div.rbtoc1526880012977 ul {list-style: disc;margin-left: 0px;}
+div.rbtoc1526880012977 li {margin-left: 0px;padding-left: 0px;}
-/*]]>*/</style></p><div class="toc-macro rbtoc1523333999330">
+/*]]>*/</style></p><div class="toc-macro rbtoc1526880012977">
<ul class="toc-indentation"><li><a
href="#FormsandFormComponentsFAQ-Whatisthet:formdatahiddenfieldfor?">What is
the t:formdata hidden field for?</a></li><li><a
href="#FormsandFormComponentsFAQ-HowdoIchangethelabelforafieldonthefly?">How do
I change the label for a field on the fly?</a></li><li><a
href="#FormsandFormComponentsFAQ-Tapestryfocusesonthewrongfieldinmyform,howdoIfixthat?">Tapestry
focuses on the wrong field in my form, how do I fix that?</a></li></ul>
</div><h2
id="FormsandFormComponentsFAQ-Whatisthet:formdatahiddenfieldfor?">What is the
<code>t:formdata</code> hidden field for?</h2><p>In Tapestry, rendering a form
can be a complicated process; inside the body of the Form component are many of
field components: TextField, Select, TextArea, and so forth. Each of these must
pull data out of your data model and convert it to the string form used inside
the client web browser. In addition, JavaScript to support client-side
validation must be generated. This can be further complicated by the use of
Loop and If components, or made really complicated by the use of Block (to
render portions of other pages: this is what the BeanEditForm component
does).</p><p>Along the way, the Form is generating unique form control names
for each field component, as it renders.</p><p>When the client-side Form is
submitted, an event is triggered on the server-side Form component. It now
needs to locate each component, in turn, inform the component of its
control name, and allow the component to read the corresponding query
parameter. The component then converts the client-side string back into a
server-side value and performs validations before updating the data
model.</p><p>That's where <code>t:formdata</code> comes in. While components
are rendering, they are using the FormSupport environmental object to record
callbacks:</p><div class="code panel pdl" style="border-width: 1px;"><div
class="codeHeader panelHeader pdl" style="border-bottom-width:
1px;"><b>FormSupport.java (partial)</b></div><div class="codeContent
panelContent pdl">
-<pre class="brush: java; gutter: true; theme: Default"
style="font-size:12px;">public interface FormSupport extends ClientElement
+<pre class="syntaxhighlighter-pre" data-syntaxhighlighter-params="brush: java;
gutter: true; theme: Default" data-theme="Default">public interface FormSupport
extends ClientElement
{
/**
* Stores an action for execution during a later request. If the action
contains any mutable state, it should be in
@@ -104,21 +104,21 @@ div.rbtoc1523333999330 li {margin-left:
<T> void storeAndExecute(T component, ComponentAction<T>
action);
</pre>
</div></div><p>The <code>ComponentAction</code> objects are the callbacks.
<code>t:formdata</code> is simply an object stream of these callbacks,
compressed and encoded in Base64. When using Ajax, you may see multiple
<code>t:formdata</code> hidden fields (they are processed one after
another).</p><h2
id="FormsandFormComponentsFAQ-HowdoIchangethelabelforafieldonthefly?">How do I
change the label for a field on the fly?</h2><p>Tapestry tries to be smart
about generating the label string for a field. It has some smart default logic,
first checking for the <em>component-id</em><code>-label</code> in the
container's message catalog, then ultimately converting the component's id into
a user-presentable label.</p><p>You can override the label in two
ways:</p><p>First, you can supply a body to the <code>Label</code>
component:</p><div class="code panel pdl" style="border-width: 1px;"><div
class="codeContent panelContent pdl">
-<pre class="brush: java; gutter: true; theme: Default"
style="font-size:12px;"> <t:label
for="username">${usernameLabel}</t:label>
+<pre class="syntaxhighlighter-pre" data-syntaxhighlighter-params="brush: java;
gutter: true; theme: Default" data-theme="Default"> <t:label
for="username">${usernameLabel}</t:label>
<t:textfield t:id="username"/>
</pre>
</div></div><p>Here, the component class must provide a
<code>usernameLabel</code> property. That property becomes the text of the
label. An implementation of the property might look something like:</p><div
class="code panel pdl" style="border-width: 1px;"><div class="codeContent
panelContent pdl">
-<pre class="brush: java; gutter: true; theme: Default"
style="font-size:12px;"> public String getUsernameLabel()
+<pre class="syntaxhighlighter-pre" data-syntaxhighlighter-params="brush: java;
gutter: true; theme: Default" data-theme="Default"> public String
getUsernameLabel()
{
return systemPreferences.useEmailAddressForUserName() ? "Email address" :
"User name";
}
</pre>
</div></div><p>However, if there are any validations on the field, the error
message will include the default label (as discussed above).</p><p>To uniformly
update the label both on the page, and in any validation messages, bind the
TextField's <code>label</code> parameter:</p><div class="code panel pdl"
style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<pre class="brush: java; gutter: true; theme: Default"
style="font-size:12px;"> <t:label for="username"/>
+<pre class="syntaxhighlighter-pre" data-syntaxhighlighter-params="brush: java;
gutter: true; theme: Default" data-theme="Default"> <t:label
for="username"/>
<t:textfield t:id="username" label="prop:usernameLabel"/>
</pre>
</div></div><p>The "prop:" prefix identifies that "usernameLabel" is to be
interpreted as a property expression (normally, the binding for the
<code>label</code> parameter is interpreted as a string literal). The Label
component gets the text it displays from the TextField component, and the
TextField component uses the same text when generating server-side and
client-side validation messages.</p><h2
id="FormsandFormComponentsFAQ-Tapestryfocusesonthewrongfieldinmyform,howdoIfixthat?">Tapestry
focuses on the wrong field in my form, how do I fix that?</h2><p>Tapestry
normally figures out the correct field in your form to initially receive focus;
this is based on assigning a <a class="external-link"
href="http://tapestry.apache.org/current/apidocs/org/apache/tapestry5/FieldFocusPriority.html">FieldFocusPriority</a>
to each field as it renders, which works out to the following
logic:</p><ul><li>The first field which has an error</li><li>Or, the first
field which is required</li><li>Or,
the first field</li></ul><p>Occasionally, due a wide range of factors beyond
Tapestry's control, it's selection will not be quite what you want, and it is
necessary to supply an override. The information is tracked inside the <a
class="external-link"
href="http://tapestry.apache.org/current/apidocs/org/apache/tapestry5/services/javascript/JavaScriptSupport.html">JavaScriptSupport</a>
environmental. It's just a matter of injecting the component so that you can
determine its client id, then informing JavaScriptSupport about your
override.</p><p>Here's an example</p><div class="code panel pdl"
style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<pre class="brush: java; gutter: false; theme: Default"
style="font-size:12px;"> <t:textfield t:id="email"
t:mixins="OverrideFieldFocus" .../>
+<pre class="syntaxhighlighter-pre" data-syntaxhighlighter-params="brush: java;
gutter: false; theme: Default" data-theme="Default"> <t:textfield
t:id="email" t:mixins="OverrideFieldFocus" .../>
</pre>
</div></div><p>The <a class="external-link"
href="http://tapestry.apache.org/5.4/apidocs/org/apache/tapestry5/corelib/mixins/OverrideFieldFocus.html">OverrideFieldFocus</a>
mixin forces the email field to be the focus field, regardless.</p></div>
</div>
Modified: websites/production/tapestry/content/forms-and-validation.html
==============================================================================
--- websites/production/tapestry/content/forms-and-validation.html (original)
+++ websites/production/tapestry/content/forms-and-validation.html Mon May 21
05:20:56 2018
@@ -86,11 +86,13 @@
+
+
<h3>Related Articles</h3>
<ul class="content-by-label"><li>
<div>
- <span class="icon aui-icon aui-icon-small
aui-iconfont-page-default" title="Page">Page:</span> </div>
+ <span class="icon aui-icon content-type-page"
title="Page">Page:</span> </div>
<div class="details">
<a href="forms-and-validation.html">Forms and
Validation</a>
@@ -99,7 +101,7 @@
</div>
</li><li>
<div>
- <span class="icon aui-icon aui-icon-small
aui-iconfont-page-default" title="Page">Page:</span> </div>
+ <span class="icon aui-icon content-type-page"
title="Page">Page:</span> </div>
<div class="details">
<a href="forms-and-form-components-faq.html">Forms
and Form Components FAQ</a>
@@ -108,7 +110,7 @@
</div>
</li><li>
<div>
- <span class="icon aui-icon aui-icon-small
aui-iconfont-page-default" title="Page">Page:</span> </div>
+ <span class="icon aui-icon content-type-page"
title="Page">Page:</span> </div>
<div class="details">
<a href="bean-validation.html">Bean Validation</a>
@@ -120,11 +122,11 @@
<p> </p><p>Tapestry provides support for creating and rendering forms,
populating their fields, and validating user input. For simple cases, input
validation is declarative, meaning you simply tell Tapestry what validations to
apply to a given field, and it takes care of it on the server and (optionally)
on the client as well. In addition, you can provide event handler
methods in your page or component classes to handle more complex
validation scenarios.</p><p>Finally, Tapestry not only makes it easy to present
errors messages to the user, but it can also automatically highlight form
fields when validation fails.</p><p><strong>Contents</strong></p><p><style
type="text/css">/*<![CDATA[*/
-div.rbtoc1523334080187 {padding: 0px;}
-div.rbtoc1523334080187 ul {list-style: disc;margin-left: 0px;}
-div.rbtoc1523334080187 li {margin-left: 0px;padding-left: 0px;}
+div.rbtoc1526880006248 {padding: 0px;}
+div.rbtoc1526880006248 ul {list-style: disc;margin-left: 0px;}
+div.rbtoc1526880006248 li {margin-left: 0px;padding-left: 0px;}
-/*]]>*/</style></p><div class="toc-macro rbtoc1523334080187">
+/*]]>*/</style></p><div class="toc-macro rbtoc1526880006248">
<ul class="toc-indentation"><li>Related Articles</li></ul>
<ul><li><a href="#FormsandValidation-TheFormComponent">The Form Component</a>
<ul class="toc-indentation"><li><a href="#FormsandValidation-FormEvents">Form
Events</a></li><li><a href="#FormsandValidation-HandlingEvents">Handling
Events</a></li><li><a
href="#FormsandValidation-TrackingValidationErrors">Tracking Validation
Errors</a></li><li><a
href="#FormsandValidation-StoringDataBetweenRequests">Storing Data Between
Requests</a></li><li><a
href="#FormsandValidation-ConfiguringFieldsandLabels">Configuring Fields and
Labels</a></li></ul>
@@ -134,14 +136,14 @@ div.rbtoc1523334080187 li {margin-left:
</li><li><a
href="#FormsandValidation-ConfiguringValidatorContraintsintheMessageCatalog">Configuring
Validator Contraints in the Message Catalog</a></li><li><a
href="#FormsandValidation-ValidationMacros">Validation Macros</a></li><li><a
href="#FormsandValidation-OverridingtheTranslatorwithEvents">Overriding the
Translator with Events</a></li></ul>
</li></ul></div><h1 id="FormsandValidation-TheFormComponent">The Form
Component</h1><p>The core of Tapestry's form support is the <a
class="external-link"
href="http://tapestry.apache.org/current/apidocs/org/apache/tapestry5/corelib/components/Form.html">Form</a>
component. The Form component encloses (wraps around) all the other <em>field
components</em> such as <a class="external-link"
href="http://tapestry.apache.org/current/apidocs/org/apache/tapestry5/corelib/components/TextField.html">TextField</a>,
<a class="external-link"
href="http://tapestry.apache.org/current/apidocs/org/apache/tapestry5/corelib/components/TextArea.html">TextArea</a>,
<a class="external-link"
href="http://tapestry.apache.org/current/apidocs/org/apache/tapestry5/corelib/components/Checkbox.html">Checkbox</a>,
etc.</p><h2 id="FormsandValidation-FormEvents">Form Events</h2><p>The Form
component emits a number of <a href="component-events.html">component
events</a>. You'll want to provide event handler m
ethods for some of these.</p><p>When rendering, the Form component emits two
events: first, "prepareForRender", then "prepare". These allow the Form's
container to set up any fields or properties that will be referenced in the
form. For example, this is a good place to create a temporary entity object to
be rendered, or to load an entity from a database to be edited.</p><p>When user
submits the form on the client, a series of steps occur on the
server.</p><p>First, the Form emits a "prepareForSubmit" event, then a
"prepare" event. These allow the container to ensure that objects are set up
and ready to receive information from the form submission.</p><p>Next, all the
fields inside the form are <em>activated</em> to pull values out of the
incoming request, validate them and (if valid) store the changes.</p><div
class="navmenu" style="float:right; width:25%; background:#eee; margin:3px;
padding:3px">
<p><em>For Tapestry 4 Users:</em> Tapestry 5 does not use the fragile "form
rewind" approach from Tapestry 4. Instead, a hidden field generated during the
render stores the information needed to process the form
submission.</p></div> <p>After the fields have done their processing, the
Form emits a "validate" event. This is your chance to perform any cross-form
validation that can't be described declaratively.</p><p>Next, the Form
determines if there have been any validation errors. If there have been, then
the submission is considered a failure, and a "failure" event is emitted. If
there have been no validation errors, then a "success" event is
emitted.</p><p>Finally, the Form emits a "submit" event, for logic that doesn't
care about success or failure.</p><div class="table-wrap"><table
class="confluenceTable"><tbody><tr><th colspan="1" rowspan="1"
class="confluenceTh"><p>Form Event (in order)</p></th><th colspan="1"
rowspan="1" class="confluenceTh"><p>Phase</p></th><th colspan
="1" rowspan="1" class="confluenceTh"><p>When emitted (and typical
use)</p></th><th colspan="1" rowspan="1" class="confluenceTh">Method
Name</th><th colspan="1" rowspan="1" class="confluenceTh">@OnEvent
Constant</th></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><strong>prepareForRender</strong></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p>Render</p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p>Before rendering the form (e.g. load an
entity from a database to be edited)</p></td><td colspan="1" rowspan="1"
class="confluenceTd">onPrepareForRender()</td><td colspan="1" rowspan="1"
class="confluenceTd">EventConstants.PREPARE_FOR_RENDER</td></tr><tr><td
colspan="1" rowspan="1"
class="confluenceTd"><p><strong>prepare</strong></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p>Render</p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p>Before rendering the form, but after
<em>prepareForRender</em></p></td><td colspan="1" rowspan="1" c
lass="confluenceTd">onPrepare()</td><td colspan="1" rowspan="1"
class="confluenceTd">EventConstants.PREPARE</td></tr><tr><td colspan="1"
rowspan="1"
class="confluenceTd"><p><strong>prepareForSubmit</strong></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p>Submit</p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p>Before the submitted form is
processed</p></td><td colspan="1" rowspan="1"
class="confluenceTd">onPrepareForSubmit()</td><td colspan="1" rowspan="1"
class="confluenceTd">EventConstants.PREPARE_FOR_SUBMIT</td></tr><tr><td
colspan="1" rowspan="1"
class="confluenceTd"><p><strong>prepare</strong></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p>Submit</p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p>Before the submitted form is processed, but after
<em>prepareForSubmit</em></p></td><td colspan="1" rowspan="1"
class="confluenceTd">onPrepare()</td><td colspan="1" rowspan="1"
class="confluenceTd">EventConstants.PREPARE</td></tr><tr><td cols
pan="1" rowspan="1"
class="confluenceTd"><p><strong>validate</strong></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p>Submit</p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p>After fields have been populated from submitted values
and validated (e.g. perform cross-field validation)</p></td><td colspan="1"
rowspan="1" class="confluenceTd">onValidate</td><td colspan="1" rowspan="1"
class="confluenceTd">EventConstants.VALIDATE</td></tr><tr><td colspan="1"
rowspan="1" class="confluenceTd"><p><strong>validateForm</strong></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p>Submit</p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p>same as <em>validate (deprecated – do
not use)<br clear="none"></em></p></td><td colspan="1" rowspan="1"
class="confluenceTd"><em>onValidateForm</em></td><td colspan="1" rowspan="1"
class="confluenceTd"> </td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><strong>failure</strong></p></td><td colspan=
"1" rowspan="1" class="confluenceTd"><p>Submit</p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p>After one or more validation errors have
occurred</p></td><td colspan="1" rowspan="1"
class="confluenceTd">onFailure()</td><td colspan="1" rowspan="1"
class="confluenceTd">EventConstants.FAILURE</td></tr><tr><td colspan="1"
rowspan="1" class="confluenceTd"><p><strong>success</strong></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p>Submit</p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p>When validation has completed
<em>without</em> any errors (e.g. save changes to the database)</p></td><td
colspan="1" rowspan="1" class="confluenceTd">onSuccess()</td><td colspan="1"
rowspan="1" class="confluenceTd">EventConstants.SUCCESS</td></tr><tr><td
colspan="1" rowspan="1"
class="confluenceTd"><p><strong>submit</strong></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p>Submit</p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p>After all validation (s
uccess or failure) has finished</p></td><td colspan="1" rowspan="1"
class="confluenceTd">onSubmit()</td><td colspan="1" rowspan="1"
class="confluenceTd">EventConstants.SUBMIT</td></tr><tr><td colspan="1"
rowspan="1" class="confluenceTd"><strong>canceled</strong></td><td colspan="1"
rowspan="1" class="confluenceTd">Submit</td><td colspan="1" rowspan="1"
class="confluenceTd">Whenever a <em>Submit</em> or <em>LinkSubmit</em>
component containing <em>mode="cancel"</em> or <em>mode="unconditional"</em> is
clicked</td><td colspan="1" rowspan="1"
class="confluenceTd">onCanceled()</td><td colspan="1" rowspan="1"
class="confluenceTd">EventConstants.CANCELED</td></tr></tbody></table></div><p>Note
that the "prepare" event is emitted during both form rendering and form
submission.</p><h2 id="FormsandValidation-HandlingEvents">Handling
Events</h2><p>Main Article: <a href="component-events.html">Component
Events</a></p><p>You handle events by providing methods in your page or
component class, ei
ther following the
on<strong><em>Event</em></strong>From<strong><em>Component</em></strong>()
naming convention or using the OnEvent annotation. For example:</p><div
class="code panel pdl" style="border-width: 1px;"><div class="codeHeader
panelHeader pdl" style="border-bottom-width: 1px;"><b>Event Handler Using
Naming Convention</b></div><div class="codeContent panelContent pdl">
-<pre class="brush: java; gutter: false; theme: Default"
style="font-size:12px;"> void onValidateFromPassword() { ...}</pre>
+<pre class="syntaxhighlighter-pre" data-syntaxhighlighter-params="brush: java;
gutter: false; theme: Default" data-theme="Default"> void
onValidateFromPassword() { ...}</pre>
</div></div><p>or the equivalent using @OnEvent:</p><div class="code panel
pdl" style="border-width: 1px;"><div class="codeHeader panelHeader pdl"
style="border-bottom-width: 1px;"><b>Event Handler Using @OnEvent
Annotation</b></div><div class="codeContent panelContent pdl">
-<pre class="brush: java; gutter: false; theme: Default"
style="font-size:12px;"> @OnEvent(value=EventConstants.VALIDATE,
component="password")
+<pre class="syntaxhighlighter-pre" data-syntaxhighlighter-params="brush: java;
gutter: false; theme: Default" data-theme="Default">
@OnEvent(value=EventConstants.VALIDATE, component="password")
void verifyThePassword() { ...}</pre>
</div></div><h2 id="FormsandValidation-TrackingValidationErrors">Tracking
Validation Errors</h2><p>Associated with the Form is a <a
class="external-link"
href="http://tapestry.apache.org/current/apidocs/org/apache/tapestry5/ValidationTracker.html">ValidationTracker</a>
that tracks all the provided user input and validation errors for every field
in the form. The tracker can be provided to the Form via the Form's tracker
parameter, but this is rarely necessary.</p><p>The Form includes methods
<code>isValid()</code> and <code>getHasErrors()</code>, which are used to see
if the Form's validation tracker contains any errors.</p><p>In your own logic,
it is possible to record your own errors. Form includes two different versions
of method <code>recordError()</code>, one of which specifies a <a
class="external-link"
href="http://tapestry.apache.org/current/apidocs/org/apache/tapestry5/Field.html">Field</a>
(an interface implemented by all form element components), and one of which is
for
"global" errors, not associated with any particular field. If the error
concerns only a single field, you should use the first version so that the
field will be highlighted.</p><h2
id="FormsandValidation-StoringDataBetweenRequests">Storing Data Between
Requests</h2><p></p><div class="navmenu" style="float:right; width:40%;
background:white; margin:3px; padding:3px">
<div class="confluence-information-macro
confluence-information-macro-information"><p class="title">New in Tapestry
5.4</p><span class="aui-icon aui-icon-small aui-iconfont-info
confluence-information-macro-icon"></span><div
class="confluence-information-macro-body">
<p>Starting in Tapestry 5.4, the default behavior for server-side validation
failures is to re-render the page within the same request (rather than emitting
a redirect). This removes the need to use a session-persistent field to store
the validation tracker when validation failures occur.</p></div></div></div>As
with other action requests, the result of a form submission (except when using
<a href="forms-and-validation.html">Zones</a>) is to send a redirect to the
client, which results in a second request (to re-render the page). The
ValidationTracker must be <a href="persistent-page-data.html">persisted</a>
(generally in the HttpSession) across these two requests in order to prevent
the loss of validation information. Fortunately, the default ValidationTracker
provided by the Form component is persistent, so you don't normally have to
worry about it.<p>However, for the same reason, the individual fields updated
by the components should also be persisted across requests, and this
is something you <strong>do</strong> need to do yourself – generally
with the @Persist annotation.</p><p>For example, a Login page class, which
collects a user name and a password, might look like:</p><div class="code panel
pdl" style="border-width: 1px;"><div class="codeHeader panelHeader pdl"
style="border-bottom-width: 1px;"><b>Login.java Example</b></div><div
class="codeContent panelContent pdl">
-<pre class="brush: java; gutter: false; theme: Default"
style="font-size:12px;">package com.example.newapp.pages;
+<pre class="syntaxhighlighter-pre" data-syntaxhighlighter-params="brush: java;
gutter: false; theme: Default" data-theme="Default">package
com.example.newapp.pages;
import com.example.newapp.services.UserAuthenticator;
@@ -191,7 +193,7 @@ public class Login {
</div></div><p></p><div class="navmenu" style="float:right; width:40%;
background:white; margin:3px; padding:3px">
<div class="confluence-information-macro
confluence-information-macro-information"><span class="aui-icon aui-icon-small
aui-iconfont-info confluence-information-macro-icon"></span><div
class="confluence-information-macro-body">
<p>Note that the onValidateFromLoginForm() and onSuccess() methods are not
public; event handler methods can have any visibility, even private. Package
private (that is, no modifier) is the typical use, as it allows the component
to be tested, from a test case class in the same
package.</p></div></div></div>Because a form submission is really <em>two</em>
requests: the submission itself (which results in a redirect response), then a
second request for the page (which results in a re-rendering of the page), it
is necessary to persist the userName field between the two requests, by using
the @Persist annotation. This would be necessary for the password field as
well, except that the <a class="external-link"
href="http://tapestry.apache.org/current/apidocs/org/apache/tapestry5/corelib/components/PasswordField.html">PasswordField</a>
component never renders a value.<div class="confluence-information-macro
confluence-information-macro-tip"><span class="aui-icon aui-icon-small
aui-iconfo
nt-approve confluence-information-macro-icon"></span><div
class="confluence-information-macro-body"><p>To avoid data loss, fields whose
values are stored in the HttpSession (such as userName, above) must be
serializable, particularly if you want to be able to cluster your application
or preserve sessions across server restarts.</p></div></div><p>The Form only
emits a "success" event if the there are no prior validation errors. This means
it is not necessary to write <code>if (form.getHasErrors()) return;</code> as
the first line of the method.</p><p>Finally, notice how business logic fits
into validation. The UserAuthenticator service is responsible for ensuring that
the userName and (plaintext) password are valid. When it returns false, we ask
the Form component to record an error. We provide the PasswordField instance as
the first parameter; this ensures that the password field, and its label, are
decorated when the Form is re-rendered, to present the errors to the
user.</p><h2 id
="FormsandValidation-ConfiguringFieldsandLabels">Configuring Fields and
Labels</h2><p>The Login page template below contains a minimal amount of
Tapestry instrumentation and references some of the <a class="external-link"
href="http://getbootstrap.com" rel="nofollow">Bootstrap</a> CSS classes
(Bootstrap is automatically integrated into each page by default, starting with
Tapestry 5.4).</p><div class="code panel pdl" style="border-width: 1px;"><div
class="codeHeader panelHeader pdl" style="border-bottom-width:
1px;"><b>Login.tml Example</b></div><div class="codeContent panelContent pdl">
-<pre class="brush: xml; gutter: false; theme: Default"
style="font-size:12px;"><html t:type="layout" title="newapp com.example"
+<pre class="syntaxhighlighter-pre" data-syntaxhighlighter-params="brush: xml;
gutter: false; theme: Default" data-theme="Default"><html t:type="layout"
title="newapp com.example"
xmlns:t="http://tapestry.apache.org/schema/tapestry_5_4.xsd">
<div class="row">
@@ -208,15 +210,15 @@ public class Login {
</html>
</pre>
</div></div><p>Rendering the page gives a reasonably pleasing first
pass:</p><p><span class="confluence-embedded-file-wrapper image-center-wrapper
confluence-embedded-manual-size"><img class="confluence-embedded-image
confluence-external-resource confluence-content-image-border image-center"
width="500"
src="https://cwiki-test.apache.org/confluence/download/attachments/22872109/newapp_com_example.png?version=3&modificationDate=1428088849000&api=v2"
data-image-src="https://cwiki-test.apache.org/confluence/download/attachments/22872109/newapp_com_example.png?version=3&modificationDate=1428088849000&api=v2"></span></p><p>The
Tapestry Form component is responsible for creating the necessary URL for the
form submission (this is Tapestry's responsibility, not yours).</p><p><span>For
the TextField, we provide a component id, userName. We could specify the
</span><code>value</code><span> parameter, but the default is to match the
TextField's id against a property of the cont
ainer, the Login page, if such a property exists. </span></p><p>As a rule
of thumb, you should always give your fields a specific id (this id will be
used to generate the <code>name</code> and <code>id</code> attributes of the
rendered tag). Being allowed to omit the value parameter helps to keep the
template from getting too cluttered.</p><p>The FormGroup mixin decorates the
field with some additional markup, including a <label> element; this
leverages more of Bootstrap.</p><div class="code panel pdl"
style="border-width: 1px;"><div class="codeHeader panelHeader pdl"
style="border-bottom-width: 1px;"><b>userName component as
rendered</b></div><div class="codeContent panelContent pdl">
-<pre class="brush: xml; gutter: false; theme: Default"
style="font-size:12px;"><div class="form-group">
+<pre class="syntaxhighlighter-pre" data-syntaxhighlighter-params="brush: xml;
gutter: false; theme: Default" data-theme="Default"><div
class="form-group">
<label for="userName" class="control-label">User Name</label>
<input id="userName" class="form-control" name="userName" type="text">
</div></pre>
</div></div><p> </p><h1 id="FormsandValidation-FormValidation"><span
style="color: rgb(83,145,38);">Form Validation</span></h1><p>The above example
is a very basic form which allows the fields to be empty. However, with a
little more effort we can add client-side validation to prevent the user from
submitting the form with either field empty.</p><p>Validation in Tapestry
involves associating one or more <em>validators</em> with a form element
component, such as TextField or PasswordField. This is done using the
<strong>validate</strong> parameter:</p><div class="code panel pdl"
style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<pre class="brush: xml; gutter: false; theme: Default"
style="font-size:12px;"><t:textfield t:id="userName" validate="required"
t:mixins="formgroup"/>
+<pre class="syntaxhighlighter-pre" data-syntaxhighlighter-params="brush: xml;
gutter: false; theme: Default" data-theme="Default"><t:textfield
t:id="userName" validate="required" t:mixins="formgroup"/>
<t:passwordfield t:id="password" value="password" validate="required"
t:mixins="formgroup"/></pre>
</div></div><h2 id="FormsandValidation-AvailableValidators"><span
style="color: rgb(83,145,38);">Available Validators</span></h2><p>Tapestry
provides the following built-in validators:</p><div class="table-wrap"><table
class="confluenceTable"><tbody><tr><th colspan="1" rowspan="1"
class="confluenceTh"><p>Validator</p></th><th colspan="1" rowspan="1"
class="confluenceTh"><p>Constraint Type</p></th><th colspan="1" rowspan="1"
class="confluenceTh"><p>Description</p></th><th colspan="1" rowspan="1"
class="confluenceTh"><p>Example</p></th></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p>email</p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p>–</p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p>Ensures that the given input looks like a valid e-mail
address</p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p><code><t:textfield value="userEmail"
validate="email" /></code></p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p>
max</p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p>long</p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p>Enforces a maximum integer value</p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><code><t:textfield
value="age" validate="max=120,min=0" /></code></p></td></tr><tr><td
colspan="1" rowspan="1" class="confluenceTd"><p>maxLength</p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p>int</p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p>Makes sure that a string value has a
maximum length</p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p><code><t:textfield value="zip"
validate="maxlength=7" /></code></p></td></tr><tr><td colspan="1"
rowspan="1" class="confluenceTd"><p>min</p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p>long</p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p>Enforces a minimum integer value</p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><code><t:textfield value
="age" validate="max=120,min=0" /></code></p></td></tr><tr><td colspan="1"
rowspan="1" class="confluenceTd"><p>minLength</p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p>int</p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p>Makes sure that a string value has a minimum
length</p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p><code><t:textfield value="somefield"
validate="minlength=1" /></code></p></td></tr><tr><td colspan="1"
rowspan="1" class="confluenceTd"><p>none</p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p>–</p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p>Does nothing (used to override a @Validate
annotation)</p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p><code><t:textfield value="somefield" validate="none"
/></code></p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p>regexp</p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p>pattern</p></td><td colspan="1" rowspan
="1" class="confluenceTd"><p>Makes sure that a string value conforms to a
given pattern</p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p><code><t:textfield value="letterfield"
validate="regexp=^</code><code>[A-Za-z]+$" /></code></p></td></tr><tr><td
colspan="1" rowspan="1" class="confluenceTd"><p>required</p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p>–</p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p>Makes sure that a string value is not null
and not the empty string</p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p><code><t:textfield value="name" validate="required"
/></code></p></td></tr></tbody></table></div><h2
id="FormsandValidation-CentralizingValidationwith@Validate">Centralizing
Validation with @Validate</h2><p>The @<a class="external-link"
href="http://tapestry.apache.org/current/apidocs/org/apache/tapestry5/beaneditor/Validate.html">Validate</a>
annotation can take the place of the validate parameter of TextF
ield, PasswordField, TextArea and other components. When the validate
parameter is not bound in the template file, the component will check for the
@Validate annotation and use its value as the validation definition.</p><p>The
annotation may be placed on the getter or setter method, or on the field
itself.</p><p>Let's update the two fields of the Login page:</p><div
class="code panel pdl" style="border-width: 1px;"><div class="codeContent
panelContent pdl">
-<pre class="brush: java; gutter: false; theme: Default"
style="font-size:12px;"> @Persist
+<pre class="syntaxhighlighter-pre" data-syntaxhighlighter-params="brush: java;
gutter: false; theme: Default" data-theme="Default"> @Persist
@Property
@Validate("required")
private String userName;
@@ -225,11 +227,11 @@ public class Login {
@Validate("required")
private String password;</pre>
</div></div><p>Now, we'll rebuild the app, refresh the browser, and just hit
enter:</p><p><span class="confluence-embedded-file-wrapper image-center-wrapper
confluence-embedded-manual-size"><img class="confluence-embedded-image
confluence-external-resource confluence-content-image-border image-center"
width="500"
src="https://cwiki-test.apache.org/confluence/download/attachments/22872109/newapp_com_example.png?version=3&modificationDate=1428088849000&api=v2"
data-image-src="https://cwiki-test.apache.org/confluence/download/attachments/22872109/newapp_com_example.png?version=3&modificationDate=1428088849000&api=v2"></span></p><p>The
form has updated, in place, to present the errors. You will not be able to
submit the form until some value is provided for each field.</p><h2
id="FormsandValidation-HTML5Client-sideValidation">HTML5 Client-side
Validation</h2><p>When the <a
href="configuration.html"><code>tapestry.enable-html5-support</code></a> <span
class="conflue
nce-link">configuration symbol</span> is set to true (it is
<strong><em>false</em></strong> by default), the Tapestry's built-in validators
will automatically enable the HTML5-specific "type" and validation attributes
to the rendered HTML of Tapestry's form components, triggering the HTML5
client-side validation behavior built into most modern browsers. For example,
if you use the "email" and "required" validators, like this:</p><div
class="code panel pdl" style="border-width: 1px;"><div class="codeContent
panelContent pdl">
-<pre class="brush: xml; gutter: false; theme: Default"
style="font-size:12px;"><t:textfield validate="email,required" .../></pre>
+<pre class="syntaxhighlighter-pre" data-syntaxhighlighter-params="brush: xml;
gutter: false; theme: Default" data-theme="Default"><t:textfield
validate="email,required" .../></pre>
</div></div><p>then the output HTML will look like this:</p><div class="code
panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<pre class="brush: xml; gutter: false; theme: Default"
style="font-size:12px;"><input type="email" required ...></pre>
+<pre class="syntaxhighlighter-pre" data-syntaxhighlighter-params="brush: xml;
gutter: false; theme: Default" data-theme="Default"><input type="email"
required ...></pre>
</div></div><p>which causes modern browsers to present a validation error
message whenever text is entered that doesn't look like an email address, or if
the field is left blank.</p><p>The browser's built-in validation is performed
<em>before</em> Tapestry's own client-side validation. This is so that older
browsers will still perform client-side validation as expected.</p><p>The
following behaviors are included:</p><ul><li>The "<strong>required</strong>"
validator adds the "required" attribute to the rendered HTML</li><li>The
"<strong>regexp</strong>" validator adds the "pattern" attribute to the
rendered HTML</li><li>The "<strong>email</strong>" validator sets
the <code>type</code> attribute to "email" in the rendered
HTML</li><li>The "<strong>min</strong>" validator sets the <code>type</code>
attribute to "number" and adds the "min" attribute in the rendered
HTML</li><li>The "<strong>max</strong>" validator sets the <code>type</code>
attribute to "number" and adds the "max"
attribute in the rendered HTML</li><li>When bound to a <strong>number</strong>
type, the TextField component sets the <code>type</code> attribute to
"number" in the rendered HTML</li></ul><h2
id="FormsandValidation-ServerSideValidation">Server Side Validation</h2><p>Some
validation can't, or shouldn't, be done on the client side. How do we know if
the password is correct? Short of downloading all users and passwords to the
client, we really need to do the validation on the server.</p><p>In fact, all
client-side validation (via the validate parameter, or @Validate
annotation) is performed again on the server.</p><p>It is also possible to
perform extra validation there.</p><div class="code panel pdl"
style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<pre class="brush: java; gutter: false; theme: Default"
style="font-size:12px;"> /**
+<pre class="syntaxhighlighter-pre" data-syntaxhighlighter-params="brush: java;
gutter: false; theme: Default" data-theme="Default"> /**
* Do the cross-field validation
*/
void onValidateFromLoginForm() {
@@ -241,10 +243,10 @@ public class Login {
</pre>
</div></div><p>This is the validate event handler from the loginForm
component. It is invoked once all the components have had a chance to read
values out of the request, do their own validations, and update the properties
they are bound to.</p><p>In this case, the authenticator is used to decide if
the userName and password is valid. In a real application, this would be where
a database or other external service was consulted.</p><p>If the combination is
not valid, then the password field is marked as in error. The form is used to
record an error, about a component (the passwordField) with an error
message.</p><p>Entering any two values into the form and submitting will cause
a round trip; the form will re-render to present the error to the
user:</p><p><span class="confluence-embedded-file-wrapper image-center-wrapper
confluence-embedded-manual-size"><img class="confluence-embedded-image
confluence-external-resource confluence-content-image-border image-center"
width="500" src="htt
ps://cwiki-test.apache.org/confluence/download/attachments/22872109/newapp_com_example.png?version=3&modificationDate=1428088849000&api=v2"
data-image-src="https://cwiki-test.apache.org/confluence/download/attachments/22872109/newapp_com_example.png?version=3&modificationDate=1428088849000&api=v2"></span></p><p>Notice
that the cursor is placed directly into the password field.</p><div
class="confluence-information-macro confluence-information-macro-note"><span
class="aui-icon aui-icon-small aui-iconfont-warning
confluence-information-macro-icon"></span><div
class="confluence-information-macro-body"><p>In versions of Tapestry prior to
5.4, a form with validation errors would result in a redirect response to the
client; often, temporary server-side data (such as the userName field) would be
lost. Starting in 5.4, submitting a form with validation errors results in the
new page being rendered in the same request as the form
submission.</p></div></div><h2 id="FormsandVal
idation-CustomizingValidationMessages">Customizing Validation
Messages</h2><p>Each validator (such as "required" or "minlength") has a
default message used (on the client side and the server side) when the
constraint is violated; that is, when the user input is not valid.</p><p>The
message can be customized by adding an entry to the page's <a
href="localization.html">message catalog</a> (or the containing component's
message catalog). As with any localized property, this can also go into the
application's message catalog.</p><p>The first key checked is
<em>formId</em>-<em>fieldId</em>-<em>validatorName</em>-message.</p><ul><li>formId:
the local component id of the Form component</li><li>fieldId: the local
component id of the field (TextField, etc.)</li><li>validatorName: the name of
the validator, i.e., "required" or "minlength"</li></ul><p>If there is no
message for that key, a second check is made, for
<em>fieldId</em>-<em>validatorName</em>-message. <span>If</span><span>
60;that does not match a message, then the built-in default validation message
is used.</span></p><p><span>For example, if the form ID is "loginForm", the
field ID is "userName", and the validator is "required" then Tapestry will
first look for a "loginForm-userName-required-message" key in the message
catalog, and then for a "<span>userName-required-message"
key.</span></span></p><p>The validation message in the message catalog may
contain <a class="external-link"
href="https://docs.oracle.com/javase/7/docs/api/java/util/Formatter.html"
rel="nofollow">printf-style format strings</a> (such as %s) to indicate
where the validate parameter's value will be inserted. For example, if the
validate parameter in the template is minLength=3 and the validation message is
"User name must be at least %s characters" then the corresponding error message
would be <span>"User name must be at least 5 characters".</span></p><h3
id="FormsandValidation-CustomizingValidationMessagesforBeanEdit
Form">Customizing Validation Messages for BeanEditForm</h3><p>The <a
href="beaneditform-guide.html">BeanEditForm</a> component also supports
validation message customizing. The search for messages is similar; the
<em>formId</em> is the component id of the BeanEditForm component (not the Form
component it contains). The <em>fieldId</em> is the property name.</p><h2
id="FormsandValidation-ConfiguringValidatorContraintsintheMessageCatalog">Configuring
Validator Contraints in the Message Catalog</h2><p>It is possible to omit the
validation constraint from the validate parameter (or @Validator annotation),
in which case it is expected to be stored in the message catalog.</p><p>This is
useful when the validation constraint is awkward to enter inline, such as a
regular expression for use with the regexp validator.</p><p>The key here is
similar to customizing the validation message:
<em>formId</em>-<em>fieldId</em>-<em>validatorName</em> or just
<em>fieldId</em>-<em>validatorName</em>.</p>
<p>For example, your template may have the following:</p><div class="code
panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<pre class="brush: xml; gutter: false; theme: Default"
style="font-size:12px;"> <t:textfield t:id="ssn"
validate="required,regexp"/>
+<pre class="syntaxhighlighter-pre" data-syntaxhighlighter-params="brush: xml;
gutter: false; theme: Default" data-theme="Default"> <t:textfield
t:id="ssn" validate="required,regexp"/>
</pre>
</div></div><p>And your message catalog can contain:</p><div class="code panel
pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<pre class="brush: java; gutter: false; theme: Default"
style="font-size:12px;">ssn-regexp=\d{3}-\d{2}-\d{4}
+<pre class="syntaxhighlighter-pre" data-syntaxhighlighter-params="brush: java;
gutter: false; theme: Default" data-theme="Default">ssn-regexp=\d{3}-\d{2}-\d{4}
ssn-regexp-message=Social security numbers are in the format 12-34-5678.
</pre>
</div></div><p>This technique also works with the BeanEditForm; as with
validation messages, the formId is the BeanEditForm component's id, and the
fieldId is the name of the property being editted.</p><h2
id="FormsandValidation-ValidationMacros">Validation Macros</h2>
@@ -254,20 +256,20 @@ ssn-regexp-message=Social security numbe
</div><p>Lists of validators can be combined into <em>validation macros</em>.
This mechanism is convenient for ensuring consistent validation rules across an
application. To create a validation macro, just contribute to the
ValidatorMacro Service in your module class (normally AppModule.java), by
adding a new entry to the configuration object, as shown below. The first
parameter is the name of your macro, the second is a comma-separated list of
validators:</p><div class="code panel pdl" style="border-width: 1px;"><div
class="codeHeader panelHeader pdl" style="border-bottom-width:
1px;"><b>AppModule.java (partial)</b></div><div class="codeContent panelContent
pdl">
-<pre class="brush: java; gutter: false; theme: Default"
style="font-size:12px;">@Contribute(ValidatorMacro.class)
+<pre class="syntaxhighlighter-pre" data-syntaxhighlighter-params="brush: java;
gutter: false; theme: Default"
data-theme="Default">@Contribute(ValidatorMacro.class)
public static void combinePasswordValidators(MappedConfiguration<String,
String> configuration) {
configuration.add("passwordValidator","required,minlength=5,maxlength=15");
}
</pre>
</div></div><p>Then, you can use this new macro in component templates and
classes:</p><div class="code panel pdl" style="border-width: 1px;"><div
class="codeContent panelContent pdl">
-<pre class="brush: xml; gutter: false; theme: Default"
style="font-size:12px;"><input t:type="textField" t:id="password"
t:validate="passwordValidator" />
+<pre class="syntaxhighlighter-pre" data-syntaxhighlighter-params="brush: xml;
gutter: false; theme: Default" data-theme="Default"><input
t:type="textField" t:id="password" t:validate="passwordValidator" />
</pre>
</div></div><div class="code panel pdl" style="border-width: 1px;"><div
class="codeContent panelContent pdl">
-<pre class="brush: java; gutter: false; theme: Default"
style="font-size:12px;">@Validate("password")
+<pre class="syntaxhighlighter-pre" data-syntaxhighlighter-params="brush: java;
gutter: false; theme: Default" data-theme="Default">@Validate("password")
private String password;
</pre>
</div></div><h2
id="FormsandValidation-OverridingtheTranslatorwithEvents">Overriding the
Translator with Events</h2><p>The TextField, PasswordField and TextArea
components all have a translate parameter, a <a class="external-link"
href="http://tapestry.apache.org/current/apidocs/org/apache/tapestry5/FieldTranslator.html">FieldTranslator</a>
object that is used to convert values on the server side to strings on the
client side.</p><p>In most cases, the translate parameter is not set
explicitly; Tapestry derives an appropriate value based on the type of property
being editted by the field.</p><p>In certain cases, you may want to override
the translator. This can be accomplished using two events triggered on the
component, "toclient" and "parseclient".</p><p>The "toclient" event is passed
the current object value and returns a string, which will be the default value
for the field. When there is no event handler, or when the event handler
returns null, the default Translator is used to
convert the server side value to a string.</p><p>For example, you may have a
quantity field that you wish to display as blank, rather than zero,
initially:</p><div class="code panel pdl" style="border-width: 1px;"><div
class="codeContent panelContent pdl">
-<pre class="brush: java; gutter: false; theme: Default"
style="font-size:12px;"> <t:textfield t:id="quantity" size="10"/>
+<pre class="syntaxhighlighter-pre" data-syntaxhighlighter-params="brush: java;
gutter: false; theme: Default" data-theme="Default"> <t:textfield
t:id="quantity" size="10"/>
. . .
@@ -281,7 +283,7 @@ private String password;
}
</pre>
</div></div><p>This is good so far, but if the field is optional and the user
submits the form, you'll get a validation error, because the empty string is
not valid as an integer.</p><p>That's where the "parseclient" event comes
in:</p><div class="code panel pdl" style="border-width: 1px;"><div
class="codeContent panelContent pdl">
-<pre class="brush: java; gutter: false; theme: Default"
style="font-size:12px;"> Object onParseClientFromQuantity(String input)
+<pre class="syntaxhighlighter-pre" data-syntaxhighlighter-params="brush: java;
gutter: false; theme: Default" data-theme="Default"> Object
onParseClientFromQuantity(String input)
{
if ("".equals(input)) return 0;
@@ -289,7 +291,7 @@ private String password;
}
</pre>
</div></div><p>The event handler method has precedence over the translator.
Here it checks for the empty string (and note that the input may be null!) and
evaluates that as zero.</p><p>Again, returning null lets the normal translator
do its work.</p><p>The event handler may also throw a <a class="external-link"
href="http://tapestry.apache.org/current/apidocs/org/apache/tapestry5/ValidationException.html">ValidationException</a>
to indicate a value that can't be parsed.</p><p>Now, what if you want to
perform your own custom validation? That's another event: "validate":</p><div
class="code panel pdl" style="border-width: 1px;"><div class="codeContent
panelContent pdl">
-<pre class="brush: java; gutter: false; theme: Default"
style="font-size:12px;"> void onValidateFromCount(Integer value) throws
ValidationException
+<pre class="syntaxhighlighter-pre" data-syntaxhighlighter-params="brush: java;
gutter: false; theme: Default" data-theme="Default"> void
onValidateFromCount(Integer value) throws ValidationException
{
if (value.equals(13)) throw new ValidationException("Thirteen is an
unlucky number.");
}
Modified: websites/production/tapestry/content/general-questions.html
==============================================================================
--- websites/production/tapestry/content/general-questions.html (original)
+++ websites/production/tapestry/content/general-questions.html Mon May 21
05:20:56 2018
@@ -78,11 +78,11 @@
<div id="content">
<div id="ConfluenceContent"><h1
id="GeneralQuestions-GeneralQuestions">General Questions</h1><h2
id="GeneralQuestions-Contents">Contents</h2><p><style
type="text/css">/*<![CDATA[*/
-div.rbtoc1523334064883 {padding: 0px;}
-div.rbtoc1523334064883 ul {list-style: disc;margin-left: 0px;}
-div.rbtoc1523334064883 li {margin-left: 0px;padding-left: 0px;}
+div.rbtoc1526880007666 {padding: 0px;}
+div.rbtoc1526880007666 ul {list-style: disc;margin-left: 0px;}
+div.rbtoc1526880007666 li {margin-left: 0px;padding-left: 0px;}
-/*]]>*/</style></p><div class="toc-macro rbtoc1523334064883">
+/*]]>*/</style></p><div class="toc-macro rbtoc1526880007666">
<ul class="toc-indentation"><li><a
href="#GeneralQuestions-HowdoIgetstartedwithTapestry?">How do I get started
with Tapestry?</a></li><li><a
href="#GeneralQuestions-WhydoesTapestryusePrototype(inversionsbefore5.4)?WhynotinsertfavoriteJavaScriptlibraryhere?">Why
does Tapestry use Prototype (in versions before 5.4)? Why not insert favorite
JavaScript library here?</a></li><li><a
href="#GeneralQuestions-WhydoesTapestryhaveitsownInversionofControlContainer?WhynotSpringorGuice?">Why
does Tapestry have its own Inversion of Control Container? Why not Spring or
Guice?</a></li><li><a
href="#GeneralQuestions-HowdoIupgradefromTapestry4toTapestry5?">How do I
upgrade from Tapestry 4 to Tapestry 5?</a></li><li><a
href="#GeneralQuestions-HowdoIupgradefromoneversionofTapestry5toanother?">How
do I upgrade from one version of Tapestry 5 to another?</a></li><li><a
href="#GeneralQuestions-WhyaretherebothRequestandHttpServletRequest?">Why are
there both Request and HttpServletRequest?</a></li></ul
>
</div><h2 id="GeneralQuestions-HowdoIgetstartedwithTapestry?">How do I get
started with Tapestry?</h2><p class="confluence-link">The easiest way to get
started is to use <a class="external-link"
href="http://maven.apache.org">Apache Maven</a> to create your initial project;
Maven can use an <em>archetype</em> (a kind of project template) to create a
bare-bones Tapestry application for you. See the <a
href="getting-started.html">Getting Started</a> page for more
details.</p><p>Even without Maven, Tapestry is quite easy to set up. You just
need to <a href="general-questions.html">download</a> the binaries and setup
your build to place them inside your WAR's WEB-INF/lib folder. The rest is just
some one-time <a href="configuration.html">configuration of the web.xml
deployment descriptor</a>.</p><h2
id="GeneralQuestions-WhydoesTapestryusePrototype(inversionsbefore5.4)?WhynotinsertfavoriteJavaScriptlibraryhere?">Why
does Tapestry use Prototype (in versions before 5.4)? Why not <
em>insert favorite JavaScript library here</em>?</h2><p>An important goal for
Tapestry is seamless DHTML and Ajax integration. To serve that goal, it was
important that the built in components be capable of Ajax operations, such as
dynamically re-rendering parts of the page. Because of that, it made sense to
bundle a well-known JavaScript library as part of Tapestry.</p><p>At the time
(this would be 2006-ish), Prototype and Scriptaculous were well known and well
documented, whereas jQuery was just getting started.</p><p>The intent has
always been to make this aspect of Tapestry pluggable. Tapestry 5.4 includes
the option of either Prototype or jQuery, and future versions of Tapestry will
likely remove Prototype as an option..</p><h2
id="GeneralQuestions-WhydoesTapestryhaveitsownInversionofControlContainer?WhynotSpringorGuice?">Why
does Tapestry have its own Inversion of Control Container? Why not Spring or
Guice?</h2><p>An Inversion of Control Container is <em>the</em> key piece of
Tapestry's infrastructure. It is absolutely necessary to create software as
robust, performant and extensible as Tapestry.</p><p>Tapestry IoC includes a
number of features that distinguish itself from other
containers:</p><ul><li>Configured in code, not XML</li><li>Built-in extension
mechanism for services: configurations and contributions</li><li>Built-in
aspect oriented programming model (service decorations and advice)</li><li>Easy
modularization</li><li>Best-of-breed exception reporting</li></ul><p>Because
Tapestry is implemented on top of its IoC container, and because the container
makes it easy to extend or replace any service inside the container, it is
possible to make the small changes to Tapestry needed to customize it to any
project's needs.</p><p>In addition – and this is critical –
Tapestry allows 3rd party libraries to be built that fully participate in the
configurability of Tapestry itself. This means that such libraries can be
configured the same w
ay Tapestry itself is configured, and such libraries can also configure
Tapestry itself. This <em>distributed configuration</em> requires an IOC
container that fully supports such configurability.</p><h2
id="GeneralQuestions-HowdoIupgradefromTapestry4toTapestry5?">How do I upgrade
from Tapestry 4 to Tapestry 5?</h2><p>There is no existing tool that supports
upgrading from Tapestry 4 to Tapestry 5; Tapestry 5 is a complete
rewrite.</p><p>Many of the basic concepts in Tapestry 4 are still present in
Tapestry 5, but refactored, improved, streamlined, and simplified. The basic
concept of pages, templates and components are largely the same. Other aspects,
such as server-side event handling, is markedly different.</p><p>Tapestry 5 is
designed so that it can live side-by-side in the same servlet as a Tapestry 4
app, without package namespace conflicts, sharing session data and common
resources such as images and CSS. This means that you can gradually migrate a
Tapestry 4 app to Tapestry 5
one page (or one portion of the app) at a time.</p><h2
id="GeneralQuestions-HowdoIupgradefromoneversionofTapestry5toanother?">How do I
upgrade from one version of Tapestry 5 to another?</h2><p>Main Article: <a
href="how-to-upgrade.html">How to Upgrade</a>.</p><p>A lot of effort goes into
making an upgrade from one Tapestry 5 release to another go smoothly. In the
general case, it is just a matter of updating the version number in your Maven
<code>build.xml</code> or Gradle <code>build.gradle</code> file and executing
the appropriate commands (e.g., <code>gradle idea</code> or <code>mvn
eclipse:eclipse</code>) to bring your local workspace up to date with the
latest binaries.</p><p>After changing dependencies, you should always perform a
clean recompile of your application.</p><p>We make every effort to ensure
backwards-compatibility. Tapestry is mostly coded in terms of interfaces; those
interfaces are stable to a point: interfaces your code is expected to implement
are usually co
mpletely frozen; interfaces your code is expected to invoke, such as the
interfaces to IoC services, are stable, but may have new methods added in a
release; existing methods are not changed.</p><p>In <em>rare</em> cases a
choice is necessary between fixing bugs (or adding essential functionality) and
maintaining complete backwards compatibility; in those cases, an incompatible
change may be introduced. These are always discussed in detail in the <a
href="release-notes.html">Release Notes</a> for the specific release. You
should always read the release notes before attempting an upgrade, and always
(really, <em>always</em>) be prepared to retest your application
afterwards.</p><p>Note that you should be careful any time you make use of
<strong>internal</strong> APIs (you can tell an API is internal by the package
name, <code>org.apache.tapestry5.internal). </code>Internal APIs may change
<em>at any time</em>; there's no guarantee of backwards compatibility. Please
always check
on the documentation, or consult the user mailing list, to see if there's a
stable, public alternative. If you do make use of internal APIs, be sure to get
a discussion going so that your needs can be met in the future by a stable,
public API.</p><h2
id="GeneralQuestions-WhyaretherebothRequestandHttpServletRequest?"><span
style="color: rgb(83,145,38);">Why are there both Request and
HttpServletRequest?</span></h2><p>Tapestry's Request interface is <em>very</em>
close to the standard HttpServletRequest interface. It differs in a few ways,
omitting some unneeded methods, and adding a couple of new methods (such as
<code>isXHR()</code>), as well as changing how some existing methods operate.
For example, <code>getParameterNames()</code> returns a sorted List of Strings;
HttpServletRequest returns an Enumeration, which is a very dated
approach.</p><p>However, the stronger reason for Request (and the related
interfaces Response and Session) is to enable the support for Portlets at some
point in the future. By writing code in terms of Tapestry's Request, and not
HttpServletRequest, you can be assured that the same code will operate in both
Servlet Tapestry and Portlet Tapestry.</p></div>
</div>
Modified: websites/production/tapestry/content/hibernate-statistics.html
==============================================================================
--- websites/production/tapestry/content/hibernate-statistics.html (original)
+++ websites/production/tapestry/content/hibernate-statistics.html Mon May 21
05:20:56 2018
@@ -92,7 +92,7 @@
<h1
id="HibernateStatistics-HibernateConfigurationtoenabletheStatistics">Hibernate
Configuration to enable the Statistics</h1>
<div class="code panel pdl" style="border-width: 1px;"><div class="codeContent
panelContent pdl">
-<pre class="brush: java; gutter: false; theme: Default"
style="font-size:12px;">
+<pre class="syntaxhighlighter-pre" data-syntaxhighlighter-params="brush: java;
gutter: false; theme: Default" data-theme="Default">
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
Modified: websites/production/tapestry/content/hibernate-support-faq.html
==============================================================================
--- websites/production/tapestry/content/hibernate-support-faq.html (original)
+++ websites/production/tapestry/content/hibernate-support-faq.html Mon May 21
05:20:56 2018
@@ -78,11 +78,11 @@
<div id="content">
<div id="ConfluenceContent"><h1
id="HibernateSupportFAQ-HibernateSupport">Hibernate Support</h1><p>Main
article: <a href="hibernate.html">Hibernate</a></p><h2
id="HibernateSupportFAQ-Contents">Contents</h2><p><style
type="text/css">/*<![CDATA[*/
-div.rbtoc1523334064361 {padding: 0px;}
-div.rbtoc1523334064361 ul {list-style: disc;margin-left: 0px;}
-div.rbtoc1523334064361 li {margin-left: 0px;padding-left: 0px;}
+div.rbtoc1526880017574 {padding: 0px;}
+div.rbtoc1526880017574 ul {list-style: disc;margin-left: 0px;}
+div.rbtoc1526880017574 li {margin-left: 0px;padding-left: 0px;}
-/*]]>*/</style></p><div class="toc-macro rbtoc1523334064361">
+/*]]>*/</style></p><div class="toc-macro rbtoc1526880017574">
<ul class="toc-indentation"><li><a
href="#HibernateSupportFAQ-HowdoIgetHibernatetostartupupwhentheapplicationstartsup,ratherthanlazilywiththefirstrequestfortheapplication?">How
do I get Hibernate to startup up when the application starts up, rather than
lazily with the first request for the application?</a></li></ul>
</div><h2
id="HibernateSupportFAQ-HowdoIgetHibernatetostartupupwhentheapplicationstartsup,ratherthanlazilywiththefirstrequestfortheapplication?">How
do I get Hibernate to startup up when the application starts up, rather than
lazily with the first request for the application?</h2><p>This was a minor
problem in 5.0; by 5.1 it is just a matter of overriding the configuration
system <code>tapestry.hibernate-early-startup</code> to "true".</p></div>
</div>
Modified: websites/production/tapestry/content/injection-faq.html
==============================================================================
--- websites/production/tapestry/content/injection-faq.html (original)
+++ websites/production/tapestry/content/injection-faq.html Mon May 21 05:20:56
2018
@@ -78,28 +78,28 @@
<div id="content">
<div id="ConfluenceContent"><h1
id="InjectionFAQ-Injection">Injection</h1><p>Main article:  <a
href="injection.html">Injection</a></p><h2
id="InjectionFAQ-Contents">Contents</h2><p><style type="text/css">/*<![CDATA[*/
-div.rbtoc1523334019697 {padding: 0px;}
-div.rbtoc1523334019697 ul {list-style: disc;margin-left: 0px;}
-div.rbtoc1523334019697 li {margin-left: 0px;padding-left: 0px;}
+div.rbtoc1526880014244 {padding: 0px;}
+div.rbtoc1526880014244 ul {list-style: disc;margin-left: 0px;}
+div.rbtoc1526880014244 li {margin-left: 0px;padding-left: 0px;}
-/*]]>*/</style></p><div class="toc-macro rbtoc1523334019697">
+/*]]>*/</style></p><div class="toc-macro rbtoc1526880014244">
<ul class="toc-indentation"><li><a
href="#InjectionFAQ-What'sthedifferencebetweenthe@Componentand@InjectComponentannotations?">What's
the difference between the @Component and @InjectComponent
annotations?</a></li><li><a
href="#InjectionFAQ-What'sthedifferencebetweenthe@InjectPageand@InjectContainerannotations?">What's
the difference between the @InjectPage and @InjectContainer
annotations?</a></li><li><a
href="#InjectionFAQ-IgetanexceptionbecauseIhavetwoserviceswiththesameinterface,howdoIhandlethis?">I
get an exception because I have two services with the same interface, how do I
handle this?</a></li><li><a
href="#InjectionFAQ-What'sthedifferencebetween@Injectand@Environmental?">What's
the difference between @Inject and @Environmental?</a></li><li><a
href="#InjectionFAQ-Butwait...IseeIusedthe@Injectannotationanditstillworked.Whatgives?">But
wait ... I see I used the @Inject annotation and it still worked. What
gives?</a></li><li><a href="#InjectionFAQ-Ok,butRequestisasingleto
nservice,notanenvironmental,andIcaninjectthat.IsTapestryreallythreadsafe?">Ok,
but Request is a singleton service, not an environmental, and I can inject
that. Is Tapestry really thread safe?</a></li><li><a
href="#InjectionFAQ-Iuse@Injectonafieldtoinjectaservice,butthefieldisstillnull,whathappened?">I
use @Inject on a field to inject a service, but the field is still null, what
happened?</a></li></ul>
</div><h2
id="InjectionFAQ-What'sthedifferencebetweenthe@Componentand@InjectComponentannotations?">What's
the difference between the <code>@Component</code> and
<code>@InjectComponent</code> annotations?</h2><p>The <code>@Component</code>
annotation is used to define the <em>type</em> of component, and its parameter
bindings. When using <code>@Component</code>, the template must not define the
type, and any parameter bindings are merged in:</p><div class="code panel pdl"
style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<pre class="brush: java; gutter: true; theme: Default"
style="font-size:12px;"> <a t:id="home" class="nav">Back to
home</a>
+<pre class="syntaxhighlighter-pre" data-syntaxhighlighter-params="brush: java;
gutter: true; theme: Default" data-theme="Default"> <a t:id="home"
class="nav">Back to home</a>
</pre>
</div></div><div class="code panel pdl" style="border-width: 1px;"><div
class="codeContent panelContent pdl">
-<pre class="brush: java; gutter: true; theme: Default"
style="font-size:12px;"> @Component(parameters={ "page=index" })
+<pre class="syntaxhighlighter-pre" data-syntaxhighlighter-params="brush: java;
gutter: true; theme: Default" data-theme="Default"> @Component(parameters={
"page=index" })
private PageLink home;
</pre>
</div></div><p>Here the type of component is defined by the field type. The
field name is matched against the <code>t:id</code> in the template. The
<code>page</code> parameter is set in the Java class, and the informal
<code>class</code> parameter is set in the template. If the tag in the template
was <code><t:pagelink></code>, or if the template tag included the
attribute <code>t:type="pagelink"</code>, then you would see an
exception.</p><p>By contrast, <code>@InjectComponent</code> expects the
component to be already defined, and doesn't allow any configuration of
it:</p><div class="code panel pdl" style="border-width: 1px;"><div
class="codeContent panelContent pdl">
-<pre class="brush: java; gutter: true; theme: Default"
style="font-size:12px;"> <t:form t:id="login"> .... </t:form>
+<pre class="syntaxhighlighter-pre" data-syntaxhighlighter-params="brush: java;
gutter: true; theme: Default" data-theme="Default"> <t:form
t:id="login"> .... </t:form>
</pre>
</div></div><div class="code panel pdl" style="border-width: 1px;"><div
class="codeContent panelContent pdl">
-<pre class="brush: java; gutter: true; theme: Default"
style="font-size:12px;"> @InjectComponent
+<pre class="syntaxhighlighter-pre" data-syntaxhighlighter-params="brush: java;
gutter: true; theme: Default" data-theme="Default"> @InjectComponent
private Form login;
</pre>
</div></div><p>Again, we're matching the field name to the component id, and
you would get an error if the component is not defined in the template.</p><h2
id="InjectionFAQ-What'sthedifferencebetweenthe@InjectPageand@InjectContainerannotations?">What's
the difference between the <code>@InjectPage</code> and
<code>@InjectContainer</code> annotations?</h2><p>The <code>@InjectPage</code>
annotation is used to inject some page in the application into a field of some
other page. You often see it used from event handler methods:</p><div
class="code panel pdl" style="border-width: 1px;"><div class="codeContent
panelContent pdl">
-<pre class="brush: java; gutter: true; theme: Default"
style="font-size:12px;"> @InjectPage
+<pre class="syntaxhighlighter-pre" data-syntaxhighlighter-params="brush: java;
gutter: true; theme: Default" data-theme="Default"> @InjectPage
private ConfirmRegistration confirmRegistration;
Object onSuccessFromRegistrationForm()
@@ -111,15 +111,15 @@ div.rbtoc1523334019697 li {margin-left:
}
</pre>
</div></div><p>This code pattern is used to configure peristent properties of
a page before returning it; Tapestry will send a client redirect to the page to
present the data.</p><p><code>@InjectContainer</code> can be used inside a
component or a mixin. In a component, it injects the immediate container of the
component; this is often the top-level page object.</p><p>In a mixin, it
injects the component to which the mixin is attached.</p><h2
id="InjectionFAQ-IgetanexceptionbecauseIhavetwoserviceswiththesameinterface,howdoIhandlethis?">I
get an exception because I have two services with the same interface, how do I
handle this?</h2><p>It's not uncommon to have two or more services that
implement the exact same interface. When you inject, you might start by just
identifying the type of service to inject:</p><div class="code panel pdl"
style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<pre class="brush: java; gutter: true; theme: Default"
style="font-size:12px;"> @Inject
+<pre class="syntaxhighlighter-pre" data-syntaxhighlighter-params="brush: java;
gutter: true; theme: Default" data-theme="Default"> @Inject
private ComponentEventResultProcessor processor;
</pre>
</div></div><p>Which results in the error: <strong>Service interface
org.apache.tapestry5.services.ComponentEventResultProcessor is matched by 3
services: AjaxComponentEventResultProcessor, ComponentEventResultProcessor,
ComponentInstanceResultProcessor. Automatic dependency resolution requires that
exactly one service implement the interface.</strong></p><p>We need more
information than just the service interface type in order to identify which of
the three services to inject. One possibility is to inject with the correct
service id:</p><div class="code panel pdl" style="border-width: 1px;"><div
class="codeContent panelContent pdl">
-<pre class="brush: java; gutter: true; theme: Default"
style="font-size:12px;"> @InjectService("ComponentEventResultProcessor")
+<pre class="syntaxhighlighter-pre" data-syntaxhighlighter-params="brush: java;
gutter: true; theme: Default" data-theme="Default">
@InjectService("ComponentEventResultProcessor")
private ComponentEventResultProcessor processor;
</pre>
</div></div><p>This works ... but it is clumsy. If the service id,
"ComponentEventResultProcessor", ever changes, this code will break. It's not
<em>refactoring safe</em>.</p><p>Instead, we should use marker annotations. If
we look at <code>TapestryModule</code>, where the ComponentEventResultProcessor
service is defined, we'll see it identifies the necessary markers:</p><div
class="code panel pdl" style="border-width: 1px;"><div class="codeContent
panelContent pdl">
-<pre class="brush: java; gutter: true; theme: Default"
style="font-size:12px;"> @Marker(
+<pre class="syntaxhighlighter-pre" data-syntaxhighlighter-params="brush: java;
gutter: true; theme: Default" data-theme="Default"> @Marker(
{ Primary.class, Traditional.class })
public ComponentEventResultProcessor buildComponentEventResultProcessor(
Map<Class, ComponentEventResultProcessor> configuration)
@@ -128,12 +128,12 @@ div.rbtoc1523334019697 li {margin-left:
}
</pre>
</div></div><p>When a service has marker annotations, the annotations present
at the <em>point of injection</em> (the field, method parameter, or constructor
parameter) are used to select a matching service. The list of services that
match by type is then filtered to only include services that have all of the
marker annotations present at the point of injection.</p><div class="code panel
pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<pre class="brush: java; gutter: true; theme: Default"
style="font-size:12px;"> @Inject
+<pre class="syntaxhighlighter-pre" data-syntaxhighlighter-params="brush: java;
gutter: true; theme: Default" data-theme="Default"> @Inject
@Traditional @Primary
private ComponentEventResultProcessor processor;
</pre>
</div></div><p>The two marker annotations, <code>@Traditional</code> and
<code>@Primary</code>, ensure that only a single service matches.</p><h2
id="InjectionFAQ-What'sthedifferencebetween@Injectand@Environmental?">What's
the difference between <code>@Inject</code> and
<code>@Environmental</code>?</h2><p><code>@Inject</code> is relatively general;
it can be used to inject resources specific to a page or component (such as
ComponentResources, Logger, or Messages), or it can inject services or other
objects obtained from the Tapestry IoC container. Once the page is loaded, the
values for these injections never change.</p><p><code>@Environmental</code> is
different; it exposes a request-scoped, dynamically bound
value:</p><ul><li>"Request scoped": different threads (processing different
requests) will see different values when reading the
field.</li><li>"Dynamically bound": the value is explicitly placed into the
Environment, and can be overridden at any time.</li></ul><p>Environmenta
ls are a form of loosely connected communication between an outer component
(or even a service) and an inner component. Example: the Form component places
a <code>FormSupport</code> object into the environment. Other components, such
as TextField, use the <code>FormSupport</code> when rendering to perform
functions such as allocate unique control names or register client-side
validations. The TextField doesn't require that the Form component be the
immediate container component, or even an ancestor: a Form on one page may,
indirectly, communicate with a TextField on some entirely different page.
Neither component directly links to the other, the <code>FormSupport</code> is
the conduit that connects them.</p><p>The term "Environmental" was chosen as
the value "comes from the environment".</p><h2
id="InjectionFAQ-Butwait...IseeIusedthe@Injectannotationanditstillworked.Whatgives?">But
wait ... I see I used the <code>@Inject</code> annotation and it still worked.
What gives?</h2><p>In c
ertain cases, Tapestry exposes a service (which can be injected) that is a
proxy to the environmental; this is primarily for common environmentals, such
as <a class="external-link"
href="http://tapestry.apache.org/current/apidocs/org/apache/tapestry5/services/javascript/JavaScriptSupport.html">JavaScriptSupport</a>,
that may be needed outside of component classes. You can see this in
TapestryModule:</p><div class="code panel pdl" style="border-width: 1px;"><div
class="codeHeader panelHeader pdl" style="border-bottom-width:
1px;"><b>TapestryModule.java (partial)</b></div><div class="codeContent
panelContent pdl">
-<pre class="brush: java; gutter: false; theme: Default"
style="font-size:12px;"> /**
+<pre class="syntaxhighlighter-pre" data-syntaxhighlighter-params="brush: java;
gutter: false; theme: Default" data-theme="Default"> /**
* Builds a proxy to the current {@link JavaScriptSupport} inside this
thread's {@link Environment}.
*
* @since 5.2.0
@@ -144,7 +144,7 @@ div.rbtoc1523334019697 li {margin-left:
}
</pre>
</div></div><p>This kind of logic is based on the <a class="external-link"
href="http://tapestry.apache.org/current/apidocs/org/apache/tapestry5/services/EnvironmentalShadowBuilder.html">EnvironmentalShadowBuilder</a>
service.</p><h2
id="InjectionFAQ-Ok,butRequestisasingletonservice,notanenvironmental,andIcaninjectthat.IsTapestryreallythreadsafe?">Ok,
but Request is a singleton service, not an environmental, and I can inject
that. Is Tapestry really thread safe?</h2><p>Yes, of course Tapestry is thread
safe. The Request service is another special case, as seen in
TapestryModule:</p><div class="code panel pdl" style="border-width: 1px;"><div
class="codeHeader panelHeader pdl" style="border-bottom-width:
1px;"><b>TapestryModule.java (partial)</b></div><div class="codeContent
panelContent pdl">
-<pre class="brush: java; gutter: false; theme: Default"
style="font-size:12px;"> public Request buildRequest()
+<pre class="syntaxhighlighter-pre" data-syntaxhighlighter-params="brush: java;
gutter: false; theme: Default" data-theme="Default"> public Request
buildRequest()
{
return shadowBuilder.build(requestGlobals, "request", Request.class);
}