<?xml version="1.0" encoding="ISO-8859-1" ?> | |
<!-- | |
Licensed to the Apache Software Foundation (ASF) under one | |
or more contributor license agreements. See the NOTICE file | |
distributed with this work for additional information | |
regarding copyright ownership. The ASF licenses this file | |
to you under the Apache License, Version 2.0 (the | |
"License"); you may not use this file except in compliance | |
with the License. You may obtain a copy of the License at | |
http://www.apache.org/licenses/LICENSE-2.0 | |
Unless required by applicable law or agreed to in writing, | |
software distributed under the License is distributed on an | |
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | |
KIND, either express or implied. See the License for the | |
specific language governing permissions and limitations | |
under the License. | |
--> | |
<document> | |
<properties> | |
<title>Converting From Standard JSF Tags to Apache Trinidad Tags</title> | |
</properties> | |
<body> | |
<section name="Converting From Standard JSF Tags to Apache Trinidad Tags"> | |
<p> | |
<ul> | |
<li> | |
<a href="#Overview">Overview</a> | |
</li> | |
<li> | |
<a href="#Getting Started">Getting Started</a> | |
</li> | |
<li> | |
<a href="#Differences">Differences</a> | |
</li> | |
<li> | |
<a href="#Additional features">Additional features</a> | |
</li> | |
</ul> | |
</p> | |
</section> | |
<section name="Overview"> | |
<p> | |
Apache Trinidad includes replacements for many of the tags in the JavaServer Faces (JSF) | |
specification. It is important to emphasize that there is no | |
requirement whatsoever that you convert from standard JSF tags | |
to Apache Trinidad tags. Standard JSF tags and Apache Trinidad tags can be | |
mixed freely within a single page. In general, the Apache Trinidad tags are | |
more powerful, because they: | |
<ul> | |
<li>Often offer more features than the standard tags</li> | |
<li>Can be used inside of the <code><tr:forEach></code> tag (it is, | |
unfortunately, not possible to support standard tags inside | |
<code><tr:forEach></code>)</li> | |
<li>Provide more efficient implementations of client-side state saving | |
(reduced per-component size)</li> | |
</ul> | |
Some of the enhanced features of Apache Trinidad tags are described <a href="#Table features">below</a>. | |
</p> | |
</section> | |
<section name="Getting Started"> | |
<p> | |
If you're using Apache Trinidad for the first time, and you're adding ADF | |
Faces tags into existing JSF pages, you'll need to know a few tips | |
to get everything working correctly. | |
</p> | |
<p> | |
First, Apache Trinidad needs its stylesheet in each page to look correct. You | |
should replace <HTML>, <HEAD>, and <BODY> tag | |
with our <tr:document> tag which creates these standard root elements as well as | |
includes our stylesheet in the page. | |
</p> | |
<p> | |
Second, if you call the Javascript <code>form.submit()</code> | |
function, you'll bypass the Apache Trinidad support for client-side | |
validation. Use the "autoSubmit" property on our input components or use the | |
command components. | |
</p> | |
</section> | |
<section name="Differences"> | |
<p> | |
Unless noted, the Apache Trinidad tag name is the same as the standard JSF tag with the exception of the prefix. Apache Trinidad tags use the prefix 'tr'. For example, <code><h:commandButton></code> is <code><tr:commandButton></code> in Apache Trinidad.</p> | |
<p> | |
The following list shows some of the common h: attributes and how they map to tr: attributes: | |
<ul> | |
<li><code>accesskey</code> - use <code>accessKey</code> </li> | |
<li><code>readonly</code> - use <code>readOnly</code> </li> | |
<li><code>alt</code> and/or <code>title</code> - use <code>shortDesc</code> </li> | |
<li><code>style</code> - use <code>inlineStyle</code> </li> | |
<li><code>dir</code>, <code>lang</code>, <code>tabindex</code> - n/a</li> | |
</ul> | |
The following table shows the standard JSF tags and how they map to Apache Trinidad tags. | |
</p> | |
<table> | |
<tr> | |
<th>Standard JSF tag</th><th>Apache Trinidad tag</th><th>Attribute Mapping/Notes</th> | |
</tr> | |
<tr><td><code> | |
<h:column></code></td> | |
<td><code><tr:column></code></td> | |
<td>The <code>tr:column</code> must be the immediate child of <code>tr:table</code>. See the | |
<a href="#Table features">Table features </a>section below. | |
</td></tr> | |
<tr><td><code> | |
<h:commandButton> </code></td> | |
<td><code><tr:commandButton> or <tr:resetButton> or <tr:objectImage></code></td> | |
<td> | |
<div><code><b>value - use text</b></code></div> | |
<div><code>type = "reset", use <tr:resetButton> tag</code></div> | |
<div><code>image - use <tr:objectImage> tag</code></div> | |
<div><code>onblur, onchange, onfocus, readonly - n/a.</code></div> | |
</td></tr> | |
<tr><td><code> | |
<h:commandLink> </code></td> | |
<td><code><tr:commandLink> </code></td> | |
<td> | |
<div><code><b>value - use text</b></code></div> | |
<div><code>charset, coords, hrefrel, rev, shape - n/a.</code></div> | |
</td></tr> | |
<tr><td><code> | |
<h:dataTable> </code></td> | |
<td><code><tr:table></code></td> | |
<td><code><b>see the <a href="#Table features">Table features </a>section below.</b> | |
</code></td></tr> | |
<tr><td><code><h:form></code></td> | |
<td><code><tr:form></code></td> | |
<td><code> | |
<div><code><b>enctype="multipart/form-data", use usesUpload="true"</b></code></div> | |
<div><code><b><a href="#NotANamingContainer">Not a NamingContainer</a></b></code></div> | |
<div><code>target - use targetFrame</code></div> | |
<div><code>accept, acceptcharset, endtype onreset - n/a.</code></div> | |
</code></td></tr> | |
<tr><td><code> | |
<h:graphicImage> </code></td> | |
<td><code><tr:objectImage></code></td> | |
<td><code> | |
<div><code><b>value or url - use source</b></code></div> | |
<div><code>ismap - use imageMapType="server"</code></div> | |
<div><code>longdesc - use longDescURL </code></div> | |
<div><code>usemap - n/a.</code></div> | |
</code></td></tr> | |
<tr><td><code><h:inputHidden></code></td> | |
<td><code><tr:inputHidden></code></td> | |
<td><code> | |
<div><code>required - n/a</code></div> | |
</code></td></tr> | |
<tr><td><code> | |
<h:inputSecret> </code></td> | |
<td><code><tr:inputText></code></td> | |
<td><code> | |
<div><code><b>set tr:inputText's "secret" attribute to true</b></code></div> | |
<div><code>maxlength - use maximumLength</code></div> | |
<div><code>size - use columns</code></div> | |
<div><code>redisplay - n/a.</code></div> | |
</code></td></tr> | |
<tr><td><code> | |
<h:inputText></code></td> | |
<td><code><tr:inputText></code></td> | |
<td><code> | |
<div><code>maxlength - use maximumLength</code></div> | |
<div><code>size - use columns</code></div> | |
</code></td></tr> | |
<tr><td><code> | |
<h:inputTextarea> </code></td> | |
<td><code><tr:inputText></code></td> | |
<td><code> | |
<div><code><b>set the tr:inputText's "rows" attribute to the desired number of rows > 1</b></code></div> | |
<div><code>cols - use columns</code></div> | |
</code></td></tr> | |
<tr><td><code> | |
<h:message></code></td> | |
<td><code><tr:message></code></td> | |
<td><code>showDetail, showSummary, xyzClass, xyzStyle, tooltip - n/a | |
</code></td></tr> | |
<tr><td><code> | |
<h:messages></code></td> | |
<td><code><tr:messages></code></td> | |
<td><code>globalOnly, showDetail, showSummary, xyzClass, xyzStyle, layout, tooltip - n/a | |
</code></td></tr> | |
<tr><td><code> | |
<h:outputFormat> </code></td> | |
<td><code><i> no tr: equivalent</i> | |
</code></td><td><br/></td></tr> | |
<tr><td><code> | |
<h:outputLabel> </code></td> | |
<td><code><tr:outputLabel></code></td> | |
<td><code> | |
<div><code>onblur, onfocus - n/a.</code></div> | |
</code></td></tr> | |
<tr><td><code> | |
<h:outputLink> </code></td> | |
<td><code><tr:goLink></code></td> | |
<td><code> | |
<div><code><b>value - use destination</b></code></div> | |
<div><code><b>use text for the link's text</b></code></div> | |
<div><code>target - use targetFrame</code></div> | |
<div><code>converter, charset, coords,hrefrel, rev, shape, type - n/a.</code></div> | |
</code></td></tr> | |
<tr><td><code> | |
<h:outputText> </code></td> | |
<td><code><tr:outputText></code></td> | |
<td><br/></td></tr> | |
<tr><td><code> | |
<h:panelGrid> </code></td><td><code><i> no tr: equivalent</i> | |
</code></td><td><br/></td></tr> | |
<tr><td><code> | |
<h:panelGroup></code></td> | |
<td><code><tr:panelGroup></code></td> | |
<td><br/></td></tr> | |
<tr><td><code> | |
<h:selectBooleanCheckbox></code></td> | |
<td><code><tr:selectBooleanCheckbox></code></td> | |
<td><br/></td></tr> | |
<tr><td><code> | |
<h:selectManyCheckbox></code></td> | |
<td><code><tr:selectManyCheckbox></code></td> | |
<td> | |
<div><code><b>layout - "vertical" and "horizontal" instead of "pageDirection" and "lineDirection"; also, the default is vertical, not horizontal</b></code></div> | |
</td></tr> | |
<tr><td><code> | |
<h:selectManyListbox></code></td> | |
<td><code><tr:selectManyListbox></code></td> | |
<td><br/></td></tr> | |
<tr><td><code> | |
<h:selectManyMenu> </code></td> | |
<td><code><tr:selectManyListbox></code></td> | |
<td><br/></td></tr> | |
<tr><td><code> | |
<h:selectOneListbox></code></td> | |
<td><code><tr:selectOneListbox></code></td> | |
<td><br/></td></tr> | |
<tr><td><code> | |
<h:selectOneMenu> </code></td> | |
<td><code><tr:selectOneChoice></code></td> | |
<td><br/></td></tr> | |
<tr><td><code> | |
<h:selectOneRadio> </code></td> | |
<td><code><tr:selectOneRadio></code></td> | |
<td> | |
<div><code>border, disabledClass, enabledClass, layout - n/a.</code></div> | |
</td></tr> | |
</table> | |
<p> | |
<a name="NotANamingContainer"></a>The ADF <code><tr:form></code> | |
component does not implement the JSF <code>NamingContainer</code> API. | |
When you use the <code><tr:form></code> tag, the ID in the generated HTML does not | |
include the form's ID as a prefix. For example: | |
<source> | |
<h:form id="foo"> | |
<!-- This inputText will have an id of "foo:bar" --> | |
<tr:inputText id="bar"/> | |
</h:form> | |
<tr:form id="foo2"> | |
<!-- This inputText will have an id of just "bar2" --> | |
<tr:inputText id="bar2"/> | |
</tr:form> | |
</source> | |
This makes it easier to write JavaScript (and results in smaller, more | |
concise HTML) - especially in cases where you may not know the ID of | |
the form - and enables the use of some CSS features on these fields. | |
On the other hand, this means that pages using multiple forms cannot | |
reuse IDs among forms. You can use the <code><f:subview></code> tag around | |
an <code><tr:form></code> if you need to reuse ID values, or you can just | |
continue using <code><h:form></code>. | |
</p> | |
</section> | |
<section name="Additional features"> | |
<p>As mentioned earlier, the Apache Trinidad tags offer some general features | |
that are not available with the standard JSF tags - such as <code><tr:forEach></code> support | |
and more efficient (smaller) client-side state saving. There are | |
many other features supported by the Apache Trinidad tags and components that are | |
not supported by the standard JSF tags. It'd take too much | |
space to discuss all of these features, but a couple of the more important | |
ones are discussed here.</p> | |
<subsection name="Label and message support"> | |
<p>Apache Trinidad input components make it much easier to support the | |
standard label-and-message pattern for laying out forms. Typically, | |
a JSF page might contain content like:</p> | |
<source> | |
<h:panelGrid columns="2"> | |
<!-- Use outputLabel; outputText doesn't support accessibility --> | |
<h:outputLabel for="nameInput" value="Name: "> | |
<h:panelGroup> | |
<h:inputText id="nameInput" value="Enter a name"/> | |
<f:verbatim><br></f:verbatim> | |
<h:message for="nameInput"/> | |
</h:panelGroup> | |
</h:panelGrid> | |
</source> | |
<p>All the Apache Trinidad input components automate this pattern; the | |
single entry of:</p> | |
<source> | |
<tr:inputText label="Name:" value="Enter a name"/> | |
</source> | |
<p>...gives you all the layout of the JSF example above - automatic | |
label and message layout and accessibility support. | |
When you use a series of Apache Trinidad input components, you'll | |
need to line up the labels and fields. For this purpose, Apache Trinidad | |
provides the <code><tr:panelForm></code> layout panel that will stack | |
Apache Trinidad input components.</p> | |
<source> | |
<tr:panelForm> | |
<tr:inputText label="First name:" value="/> | |
<tr:inputText label="Last name:" value="/> | |
</tr:panelForm> | |
</source> | |
<p>If you want to use an Apache Trinidad input component, but do not | |
want any of these features (because you require a more flexible | |
layout strategy, for example, or are already providing messaging), | |
set the "simple" attribute to "true": | |
</p> | |
<source> | |
<!-- No label or messaging --> | |
<tr:inputText simple="true" value="Enter a name"/> | |
</source> | |
</subsection> | |
<subsection name="Table features"> | |
<p>The Apache Trinidad <code><tr:table></code> component (a replacement for <code><h:dataTable></code>) | |
adds many features, including: | |
<ul> | |
<li>Built-in support for paging through data sets</li> | |
<li>Support for identifying rows by key instead of by index</li> | |
<li>No-code support for partial-page rendering (re-rendering only the table, | |
not the entire page)</li> | |
<li>Support for sorting</li> | |
<li>"Single" and "multiple" selection columns</li> | |
</ul> | |
For more information, see <a href="devguide/table.html">Using Apache Trinidad Tables</a> in <em>Development Guidelines for Apache MyFaces Trinidad Applications</em>. | |
</p> | |
</subsection> | |
<subsection name="Message customization"> | |
<p>In Apache Trinidad, for error messages that are reported for cases of invalid input for | |
editable components, during conversion and validation can be customized for | |
every converter or validator. This also applies to "required" validation on all input | |
components.</p> | |
<source> | |
<tr:selectInputDate id="mdf6" value="2004/09/06" | |
label="Date of birth" | |
tip="1/20/1972 or 1972/20/2"> | |
<tr:convertDateTime | |
secondaryPattern="d/M/yyyy" pattern="yyyy/M/d" | |
convertDateMessageDetail="&quot;{0}&quot; in &quot;{1}&quot; | |
is not a valid date. Example: &quot;{4}&quot;"/> | |
</tr:selectInputDate> | |
</source> | |
<p>For a invalid input value say 2004/15/1 - It would result in error message:<br/> | |
"2004/15/1" in "Date of birth" is not a valid date. Example: "2005/11/29".</p> | |
</subsection> | |
</section> | |
</body> | |
</document> |