You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@velocity.apache.org by ge...@apache.org on 2002/06/06 14:53:37 UTC
cvs commit: jakarta-velocity/docs user-guide_es.html
geirm 2002/06/06 05:53:37
Added: docs user-guide_es.html
Log:
rendered version of user's guide, spanish version
Revision Changes Path
1.1 jakarta-velocity/docs/user-guide_es.html
Index: user-guide_es.html
===================================================================
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<!-- Content Stylesheet for Site -->
<!-- start the processing -->
<!-- ====================================================================== -->
<!-- Main Page Section -->
<!-- ====================================================================== -->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/>
<meta name="author" value="Velocity Documentation Team">
<meta name="email" value="jvanzyl@zenplex.com">
<meta name="author" value="John Castura">
<meta name="email" value="jcastura@kw.igs.net">
<meta name="author" value="Juan Pablo Morales">
<meta name="email" value="ju-moral@uniandes.edu.co">
<title>Velocity - Velocity User Guide</title>
</head>
<body bgcolor="#ffffff" text="#000000" link="#525D76">
<table border="0" width="100%" cellspacing="0">
<!-- TOP IMAGE -->
<tr>
<td align="left">
<a href="http://jakarta.apache.org"><img src="http://jakarta.apache.org/images/jakarta-logo.gif" border="0"/></a>
</td>
<td align="right">
<a href="http://jakarta.apache.org/velocity/"><img src="./images/logo.gif" alt="Velocity" border="0"/></a>
</td>
</tr>
</table>
<table border="0" width="100%" cellspacing="4">
<tr><td colspan="2">
<hr noshade="" size="1"/>
</td></tr>
<tr>
<!-- LEFT SIDE NAVIGATION -->
<td width="20%" valign="top" nowrap="true">
<p><strong>About</strong></p>
<ul>
<li> <a href="./index.html">Overview</a>
</li>
<li> <a href="./getting-started.html">Getting Started</a>
</li>
<li> <a href="http://jakarta.apache.org/builds/jakarta-velocity/">Download</a>
</li>
<li> <a href="./install.html">Install</a>
</li>
<li> <a href="./design.html">Design</a>
</li>
<li> <a href="./contributors.html">Contributors</a>
</li>
<li> <a href="./changes.html">ChangeLog</a>
</li>
<li> <a href="./code-standards.html">Coding Standards</a>
</li>
<li> <a href="./license.html">License</a>
</li>
<li> <a href="./todo.html">TODO</a>
</li>
<li> <a href="http://nagoya.apache.org/bugzilla/enter_bug.cgi?product=Velocity">Report Issues</a>
</li>
</ul>
<p><strong>Community</strong></p>
<ul>
<li> <a href="./powered.html">Powered By Velocity</a>
</li>
<li> <a href="http://jakarta.apache.org/site/getinvolved.html">Get Involved</a>
</li>
<li> <a href="http://jakarta.apache.org/site/mail.html">Mailing Lists</a>
</li>
<li> <a href="http://jakarta.apache.org/site/cvsindex.html">CVS Repositories</a>
</li>
</ul>
<p><strong>Docs</strong></p>
<ul>
<li> <a href="./user-guide.html">User's Guide (English)</a>
</li>
<li> <a href="./user-guide_fi.html">User's Guide (Finnish)</a>
</li>
<li> <a href="./developer-guide.html">Developer's Guide</a>
</li>
<li> <a href="./vtl-reference-guide.html">VTL Reference Guide</a>
</li>
<li> <a href="./specification.html">Specification</a>
</li>
<li> <a href="./api/index.html">Javadoc</a>
</li>
</ul>
<p><strong>Tools</strong></p>
<ul>
<li> <a href="./toolsubproject.html">Tool Subproject</a>
</li>
<li> <a href="./anakia.html">Anakia : XML->doc tool</a>
</li>
<li> <a href="./texen.html">Texen : text generation</a>
</li>
<li> <a href="./dvsl/index.html">DVSL : XML xformation</a>
</li>
<li> <a href="./veltag.html">Veltag : JSP taglib</a>
</li>
<li> <a href="./migration.html">Migration to Velocity</a>
</li>
<li> <a href="./devtools.html">Editors and IDEs</a>
</li>
</ul>
<p><strong>Comparisons</strong></p>
<ul>
<li> <a href="./ymtd/ymtd.html">YMTD</a>
</li>
<li> <a href="./differences.html">VM/WM Differences</a>
</li>
<li> <a href="./casestudy1.html">JSP vs. Velocity</a>
</li>
<li> <a href="./casestudy2.html">XMLC vs. Velocity</a>
</li>
</ul>
<p><strong>Site Translations</strong></p>
<ul>
<li> <a href="http://jakarta.apache.org/velocity/">English</a>
</li>
<li> <a href="http://www.ingrid.org/jajakarta/velocity/velocity-1.2-rc2/docs-ja/index.html">Japanese</a>
</li>
</ul>
</td>
<td width="80%" align="left" valign="top">
<table border="0" cellspacing="0" cellpadding="2" width="100%">
<tr><td bgcolor="#525D76">
<font color="#ffffff" face="arial,helvetica,sanserif">
<a name="Table of Contents"><strong>Table of Contents</strong></a>
</font>
</td></tr>
<tr><td>
<blockquote>
<ol>
<li><a href="#About this Guide">Acerca de esta gu�a</a></li>
<li><a href="#What is Velocity?">�Qu� es Velocity?</a></li>
<li><a href="#What can Velocity do for me?">�Qu� puede hacer Velocity por mi?</a>
<ol>
<li><a href="#The Mud Store Example">El Ejemplo de la tienda de
Lodo</a></li>
</ol>
</li>
<li><a href="#Velocity Template Language (VTL): An Introduction">El Lenguaje de Plantillas de Velocity (VTL): Una Introducci�n</a></li>
<li><a href="#Hello Velocity World!">Hola Mundo Velocity!</a></li>
<li><a href="#Comments">Comentarios</a></li>
<li><a href="#References">Referencias</a>
<ol>
<li><a href="#Variables">Variables</a></li>
<li><a href="#Properties">Propiedades</a></li>
<li><a href="#Methods">M�todos</a></li>
</ol>
</li>
<li><a href="#Formal Reference Notation">Notaci�n Formal de Referencias</a></li>
<li><a href="#Quiet Reference Notation">Notaci�n Sileciosa de Referencias</a></li>
<li><a href="#Getting literal">Literalmente</a>
<ol>
<li><a href="#Currency">Dinero</a></li>
<li><a href="#Escaping Valid VTL References">Escapando Referencias VTL V�lidas</a></li>
</ol>
</li>
<li><a href="#Case Substitution">Sustituci�n de May�sculas y Min�sculas</a></li>
<li><a href="#Directives">Directivas</a>
<ol>
<li><a href="#Set">Set</a></li>
<li><a href="#String Literals">Cadenas de Caracteres</a></li>
<li><a href="#Conditionals">Sentencias If-Else</a>
<ol>
<li><a href="#Relational and Logical Operators">Operadores L�gicos y Relacionales</a></li>
</ol>
</li>
<li><a href="#Loops">Ciclos Foreach</a></li>
<li><a href="#Include">Include</a></li>
<li><a href="#Parse">Parse</a></li>
<li><a href="#Stop">Stop</a></li>
<li><a href="#Velocimacros">Velocimacros</a></li>
</ol>
</li>
<li><a href="#Escaping VTL Directives">Escapando Directivas VTL</a></li>
<li><a href="#VTL: Formatting Issues">VTL: Asuntos de Formato</a></li>
<li><a href="#Other Features and Miscellany">Otras Caracter�sticas y Miscel�nea</a>
<ol>
<li><a href="#Math">Matem�ticas</a></li>
<li><a href="#Range Operator">El Operador de Rango</a></li>
<li><a href="#Advanced Issues: Escaping and !">Temas Avanzados: Escapando y !</a></li>
<li><a href="#Velocimacro Miscellany">Miscel�nea de Velocimacro</a></li>
<li><a href="#String Concatenation">Concatenaci�n de Cadenas</a></li>
</ol>
</li>
<li><a href="#Feedback">Retroalimentaci�n</a></li>
</ol>
</blockquote>
</p>
</td></tr>
<tr><td><br/></td></tr>
</table>
<table border="0" cellspacing="0" cellpadding="2" width="100%">
<tr><td bgcolor="#525D76">
<font color="#ffffff" face="arial,helvetica,sanserif">
<a name="About this Guide"><strong>About this Guide</strong></a>
</font>
</td></tr>
<tr><td>
<blockquote>
<p>
La Gu�a del usuario de Velocity busca ayudar a los dise�adores de p�ginas y a
los proveedores de contenido a sentirse a gusto con Velocity y con la sint�xis
de su simple pero poderoso lenguaje de script, el Lenguaje de Plantillas de
Velocity (VTL por sus siglas en ingl�s). Muchos de los ejemplos de esta gu�a
muestran como usar Velocity para incluir contenidos din�micos en sitios web,
pero todos los ejemplos de VTL son igualmente aplicables a otras p�ginas y
plantillas.
</p>
<p>Gracias por escoger Velocity!</p>
</blockquote>
</p>
</td></tr>
<tr><td><br/></td></tr>
</table>
<table border="0" cellspacing="0" cellpadding="2" width="100%">
<tr><td bgcolor="#525D76">
<font color="#ffffff" face="arial,helvetica,sanserif">
<a name="What is Velocity?"><strong>What is Velocity?</strong></a>
</font>
</td></tr>
<tr><td>
<blockquote>
<p>
Velocity es un motor de plantillas basado en Java. Le permite a los dise�adores
de p�ginas hacer referencia a m�todos definidos dentro del c�digo Java. Los
dise�adores Web pueden trabajar en paralelo con los programadores Java para
desarrollar sitios de acuerdo al modelo de Modelo-Vista-Controlador (MVC),
permitiendo que los dise�adores se concentren �nicamente en crear un sitio bien
dise�ado y que los programadores se encarguen solamente de escribir c�digo de
primera calidad. Velocity separa el c�digo Java de las p�ginas Web, haciendo el
sitio m�s mantenible a largo plazo y presentando una alternativa viable a <a href="http://java.sun.com/products/jsp/">Java Server Pages</a> (JSP) o <a href="http://www.php.net">PHP</a>.
</p>
<p>
Velocity se puede utilizar para crear p�ginas web, SQL, PostScript y cualquier
otro tipo de salida de plantillas. Se puede utilizar como una aplicaci�n
independiente para generar c�digo fuente y reportes, o como un componente
integrado en otros sistemas. Cuando este completo Velocity proveer� servicios
para el conjunto de aplicaciones web de <a href="http://jakarta.apache.org/turbine">Turbine</a>. Velocity+Turbine
proveer� un servicio de plantillas que facilitar� el desarrollo de aplicaciones
web de acuerdo a un verdadero modelo MVC.
</p>
</blockquote>
</p>
</td></tr>
<tr><td><br/></td></tr>
</table>
<table border="0" cellspacing="0" cellpadding="2" width="100%">
<tr><td bgcolor="#525D76">
<font color="#ffffff" face="arial,helvetica,sanserif">
<a name="What can Velocity do for me?"><strong>What can Velocity do for me?</strong></a>
</font>
</td></tr>
<tr><td>
<blockquote>
<table border="0" cellspacing="0" cellpadding="2" width="100%">
<tr><td bgcolor="#828DA6">
<font color="#ffffff" face="arial,helvetica,sanserif">
<a name="The Mud Store Example"><strong>The Mud Store Example</strong></a>
</font>
</td></tr>
<tr><td>
<blockquote>
<p>
Suponga que usted es un dise�ador para una tienda en l�nea que se especializa
en vender lodo a la que llamaremos "La Tienda de Lodo en l�nea". Los negocios
est�n muy bien. Sus clientes ordenan diferentes tipos y cantidades de
lodo.
Ellos ingresan en su sitio con su nombre de usuario y su clave secreta, lo que
les permite ver sus �rdenes y pedir m�s lodo. En estos momentos el Lodo
Terracota, que es muy popular, esta en oferta. Una minor�a de sus clientes
usualmente compra Lodo Rojo Brillante, que tambi�n esta en oferta, pero no es
tan popular y usualmente esta relegado al m�rgen de su p�gina web. La
informaci�n sobre cada cliente esta dentro de su base de datos por lo que surge
la pregunta: �Por qu� no usar Velocity para enfocar las ofertas especiales para
los clientes que est�n m�s interesados en ciertas clases de lodo?
</p>
<p>
Velocity hace f�cil el personalizar las p�ginas para sus visitantes. Como un
dise�ador dentro de "El Cuarto de Lodo", usted quiere crear la p�gina que sus
usuarios ver�n despu�s de entrar a su sitio.
</p>
<p>
Usted se encuentra con los ingenieros de su compa��a, y todos acuerdan que
<em>$cliente</em> contendr� la informaci�n pertienente al cliente que est�
dentro de la p�gina en un momento dado, que <em>$lodosEnOferta</em> contendr�
todos los tipos de lodo que est�n en oferta hoy en d�a. Adem�s, el objeto
<em>$flogger</em> contendr� m�todos para ayudar con la promoci�n. Para la tarea
actual, solo se utilizar�n estas tres referencias. Recuerde, usted no necesita
preocuparse por como los ingenieros de software extraen la informaci�n
necesaria de la base de datos; s�lo tiene que saber que funciona. Esto le
permite a usted continuar con su trabajo a la vez que deja a los ingenieros
hacer el de ellos.
</p>
<p>Usted podr�a incluir el siguiente c�digo VTL dentro de su p�gina:</p>
<div align="left">
<table cellspacing="4" cellpadding="0" border="0">
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#ffffff"><pre>
<HTML>
<BODY>
Hello $cliente.Nombre!
<table>
#foreach( $lodo in $lodosEnOferta )
#if ( $cliente.haComprado($lodo) )
<tr>
<td>
$flogger.obtenerPromocion( $lodo )
</td>
</tr>
#end
#end
</table>
</pre></td>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
</table>
</div>
<p>
Los detalles exactos de la sentencia <i>foreach</i> ser�n descritos en
profundidad pr�ximamente; lo que es importante es el impacto que este peque�o
script pueda tener en su sitio. Cuando un cliente con una debilidad por el
Lodo Rojo Brillante ingrese, si el Lodo Rojo Brillante esta en oferta, eso
ser� lo que el cliente ver�, de manera prominente. Si otro cliente, con una
historia larga de compras de Lodo Terracota ingresa, entonces para �l la
noticia de un rebaja de Lodo Terracota estar� en un lugar muy importante. La
flexibilidad de Velocity es enorme y s�lo esta limitada por su creatividad.
</p>
<p>
En la referencia de VTL est�n documentados muchos otros elementos de Velocity
que, colectivamente le dan el poder y la flexibilidad que usted necesita para
hacer de su sitio en la red una <em>presencia</em> en la red. A medida que
usted se familiarice con estos elementos usted comenzar� a aprovechar el poder
de Velocity.
</p>
</blockquote>
</td></tr>
<tr><td><br/></td></tr>
</table>
</blockquote>
</p>
</td></tr>
<tr><td><br/></td></tr>
</table>
<table border="0" cellspacing="0" cellpadding="2" width="100%">
<tr><td bgcolor="#525D76">
<font color="#ffffff" face="arial,helvetica,sanserif">
<a name="Velocity Template Language (VTL): An Introduction"><strong>Velocity Template Language (VTL): An Introduction</strong></a>
</font>
</td></tr>
<tr><td>
<blockquote>
<p>
El Lenguaje de Plantillas de Velocity (VTL) fue creado para prover la
manera mas f�cil, simple y limpia de incorporar contenido din�mico
dentro de una p�gina web. Incluso un desarrollador de p�ginas web con
poca y ninguna experiencia puede r�pidamente ser capaz de utilizar VTL
para incluir contenido din�mico en un sitio web.
</p>
<p>
VTL usa <em>referencias</em> para incluir contenido din�mico dentro
de un sitio web. Una variable es un tipo de referencia que puede
referirse a algo definido dentro del c�digo Java o obtener su valor
de un <em>enunciado</em> VTL en la p�gina misma. A continuaci�n hay
un ejemplo de un enunciado VTL que se puede incluir en un documento
HTML:
</p>
<div align="left">
<table cellspacing="4" cellpadding="0" border="0">
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#ffffff"><pre>
#set( $a = "Velocity" )
</pre></td>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
</table>
</div>
<p>
Este enunciado VTL, como todos los enunciados VTL comienza con el
caracter <em>#</em> y contiene una directiva: <em>set</em>. Cuando
un visitante solicita su p�gina, el Motor de Plantillas de Velocity
buscar� dentro del contenido de su p�gina y encontrar� todos los
s�mbolos <em>#</em>, para luego determinar cu�les marcan el comienzo
de enunciados VTL y cu�les no tienen nada que ver con VTL.
</p>
<p>
El caracter <em>#</em> viene seguido por una directiva <em>set</em>.
La directiva <em>set</em> utiliza una expresi�n (encerrada entre
par�ntesis) -- una ecuaci�n que asigna un <em>valor</em> a una
<em>variable</em>.
La variable se encuentra en el lado derecho y el valor est� en el lado
izquierdo; los dos se encuentran separados por un signo igual
(<em>=</em>).
</p>
<p>
En el ejemplo en la parte superior, la variable es <em>$a</em> y el
valor es <em>Velocity</em>. Esta variable, al igual que todas las
referencias, comienza con el caracter <em>$</em>. Los valores siempre
se encuentran ente comillas; con Velocity no hay confusi�n acerca de
los tipos de datos, ya que solamente cadenas (informaci�n basada en
texto) pueden ser pasados a las variables.
</p>
<p>
La siguiente regla puede ser �til para entender mejor como funciona
Velocity: <strong>Las Referencias comienzan con <em>$</em> y se
utilizan para obtener algo. Las directivas comienzan con <em>#</em>
y se utilizan para hacer algo</strong>
</p>
<p>
En el ejemplo anterior <em>#set</em> se utiliz� para asignarle un valor
a una variable. La variable, <em>$a</em>, puede utilizarse dentro de la
plantilla para escribir la palabara "Velocity".
</p>
</blockquote>
</p>
</td></tr>
<tr><td><br/></td></tr>
</table>
<table border="0" cellspacing="0" cellpadding="2" width="100%">
<tr><td bgcolor="#525D76">
<font color="#ffffff" face="arial,helvetica,sanserif">
<a name="Hello Velocity World!"><strong>Hello Velocity World!</strong></a>
</font>
</td></tr>
<tr><td>
<blockquote>
<p>
Una vez un valor ha sido asignado a una variable, usted puede
referenciar la variable en cualquier lugar dentro del documento
HTML. En el ejemplo siguiente, un valor es asignado a la variable
<em>$foo</em>, que luego es referenciada.
</p>
<div align="left">
<table cellspacing="4" cellpadding="0" border="0">
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#ffffff"><pre>
<html>
<body>
#set( $foo = "Velocity" )
Hola Mundo $foo!
</body>
<html>
</pre></td>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
</table>
</div>
<p>
El resultado es una p�gina web que imprime "Hola Mundo Velocity!"
</p>
<p>
Para hacer los enunciados con directivas VTL m�s legibles, nosotros le
recomendamos comenzar cada enunciado VTL en una nueva l�nea, aunque
usted no esta obligado a hacerlo as�. La directiva <em>set</em> ser
ver� con mayor detalle m�s adelante.
</p>
</blockquote>
</p>
</td></tr>
<tr><td><br/></td></tr>
</table>
<table border="0" cellspacing="0" cellpadding="2" width="100%">
<tr><td bgcolor="#525D76">
<font color="#ffffff" face="arial,helvetica,sanserif">
<a name="Comments"><strong>Comments</strong></a>
</font>
</td></tr>
<tr><td>
<blockquote>
<p>
Los comentarios es posible incluir texto que no aparecer� como parte de
la salida del motor de plantillas. Los comentarios sirven para recordar
e indicar a otros que es lo que est�n haciendo los enunciados VTL, o
para cualquier otro prop�sito que usted considere �til. A continuaci�n
hay un ejemplo de un comentario de VTL.
</p>
<div align="left">
<table cellspacing="4" cellpadding="0" border="0">
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#ffffff"><pre>
## Este es un comentario de una sola l�nea
</pre></td>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
</table>
</div>
<p>
Un comentario de una sola l�nea comienza con <em>##</em> y termina
al final de la l�nea. Si usted desea escribir varias l�neas de
comentario no es necesario tener numerosos comentarios de una s�la
l�nea. Los comentarios de varias l�neas, que comienzan con
<em>#*</em> y terminan con <em>*#</em> le permiten manejar
f�cilmente esta situaci�n.
</p>
<div align="left">
<table cellspacing="4" cellpadding="0" border="0">
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#ffffff"><pre>
Este es un texto que esta fuera de un comentario de m�ltiples l�neas.
Los visitantes de su p�gina lo pueden ver.
#*
He aqu� un comentario de varias l�neas. Los visitantes
de su sitio no ver�n esto, ya que el Motor de Plantillas
de Velocity lo ignorar�
*#
Aqu� hay texto fuera del comentario, este si es visible.
</pre></td>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
</table>
</div>
<p>
A continuaci�n hay algunos ejemplos para aclarar como funcionan
los comentarios de una y varias l�neas:
</p>
<div align="left">
<table cellspacing="4" cellpadding="0" border="0">
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#ffffff"><pre>
Este texto es visible. ## Este no lo es
Este texto es visible.
Este texto es visible. #* Este texto, como parte de un comentario de
varias l�neas, no es visible. Este texto no es visible; tambi�s es parte
del comentario. Este texto a�n no es visible. *# Este texto esta fuera
del comentario, por lo que es visible.
## Este texto no es visible.
</pre></td>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
</table>
</div>
<p>
Existe un tercer tipo de comentario, el bloque de comentario VTL,
que puede ser utilizado para almacenar datos como el autor y la
informaci�n de versiones:
</p>
<div align="left">
<table cellspacing="4" cellpadding="0" border="0">
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#ffffff"><pre>
#**
Este es un bloque de comentario VTL y
puede utilizarse para almacenar datos
como el nombre del autor y la
informaci�n de versiones:
@author
@version 5
*#
</pre></td>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
</table>
</div>
</blockquote>
</p>
</td></tr>
<tr><td><br/></td></tr>
</table>
<table border="0" cellspacing="0" cellpadding="2" width="100%">
<tr><td bgcolor="#525D76">
<font color="#ffffff" face="arial,helvetica,sanserif">
<a name="References"><strong>References</strong></a>
</font>
</td></tr>
<tr><td>
<blockquote>
<p>
Existen tres tipos de referencias en VTL: variables, propiedades y
m�todos. Como un dise�ador que utilizar VTL, usted y sus ingenieros
deben llegar a un acuerdo respecto a los nombres de las referencias
para que usted pueda utilizarlas correctamente en sus plantillas.
</p>
<p>
Todo lo que entra y sale de una referencia se trata como una cadena
de caracteres (un objeto String). Si existe un objeto que representa
<em>$foo</em> (por ejemplo, un objeto Integer), entonces Velocity
llamar� el m�todo <code>.toString()</code> de ese objeto para
convertirlo en una cadena de caracteres.
</p>
<p>
<a name="Variables"><strong>Variables</strong></a>
<br />
La notaci�n breve de una variable esta compuesta por un signo "$"
inicial seguido de un <em>Identificador</em>. Un identificador VTL
debe comenzar con un caracter alfab�tico (a .. z � A .. Z). El resto
de los caracteres deb ser de alguno de los siguiente tipos:
</p>
<p>
<ul>
<li>alfab�tico (a .. z, A .. Z)</li>
<li>num�rico (0 .. 9)</li>
<li>l�nea ("-")</li>
<li>underscore ("_")</li>
</ul>
</p>
<p>
A continuaci�n hay algunos ejemplos de referencias v�lidas en VTL:
</p>
<div align="left">
<table cellspacing="4" cellpadding="0" border="0">
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#ffffff"><pre>
$foo
$lanzaLodo
$lanza-lodo
$lanza_lodo
$lanzaLodo1
</pre></td>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
</table>
</div>
<p>
Cuando VTL hace referencia una variable, po ejemplo, <em>$foo</em>,
la variable puede obtener su valor de una directiva <em>set</em>
dentro de la plantilla, o del c�digo Java. Por ejemplo, si la
variable de Java <em>$foo</em> tiene el valor <em>bar</em> en el
momento en que se solicita la plantilla, entonces <em>bar</em>
reemplaza todas las ocurrencias (o instancias) de <em>$foo</em>
dentro de la p�gina web. De manera alterna, si se incluye el
enunciado
</p>
<div align="left">
<table cellspacing="4" cellpadding="0" border="0">
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#ffffff"><pre>
#set( $foo = "bar" )
</pre></td>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
</table>
</div>
<p>
La salida ser� la misma para todas las instancias de <em>$foo</em>
que se encuentren a continuaci�n es esta directiva.
</p>
<p>
<a name="Properties"><strong>Propiedades</strong></a>
<br />
El segundo sabor de referencias VTL son las propiedades; las
propiedades tienen un formato particular. La versi�n corta se
compone de un signo <em>$</em> seguido de un identificador VTL,
seguido de un punto y de otro identificador VTL. A continuaci�n hay
ejemplos de referencias de propiedades v�lidas en VTL:
</p>
<div align="left">
<table cellspacing="4" cellpadding="0" border="0">
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#ffffff"><pre>
$cliente.Direccion
$compra.Total
</pre></td>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
</table>
</div>
<p>
Tome el primer ejemplo, <em>$cliente.Direccion</em>. Puede tener dos
significados. Puede significar, Busque en la tabla de hashing
identificada como <em>cliente</em> y devuelva el valor asociado con
la llave <em>Direccion</em>. Pero <em>$customer.Address</em> puede
tambi�n referirse a un m�todo (las referencias que se relacionan con
m�todos se discutir�n en la secci�n siguiente);
<em>$customer.Address</em> puede ser una manera corta de escribir
<em>$customer.getAddress()</em>. Cuando su p�gina sea solicitada
Velocity determinar� cu�l de las dos posibilidades tiene sentido, y
luego devolver� el valor apropiado.
</p>
<p>
<a name="Methods"><strong>Methods</strong></a>
<br />
Un m�todo esta definido dentro del c�digo de Java y es capaz de
hacer algo �til, como desarrollar un c�lculo o llegar a una
decisi�n. Los m�todos son referencias compuestas de un signo "$"
inicial seguido en un identificador VTL, seguido de un <em>Cuerpo de
M�todo</em> VTL. Un cuerpo de m�todo VTL, a su vez esta formado
por un identificador VTL seguido por un par�ntesis izquierdo ("("),
seguido, opcionalmente, por una lista de par�metros, para terminar
en un par�ntesis derecho. A continuaci�n hay ejemplos de referencias
de m�todos v�lidas dentro de VTL:
</p>
<div align="left">
<table cellspacing="4" cellpadding="0" border="0">
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#ffffff"><pre>
$cliente.getDireccion()
$compra.getTotal()
$pagina.setTitulo( "My P�gina Principal" )
$persona.establecerAtributos( ["Extra�o", "Raro", "Excitado"] )
</pre></td>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
</table>
</div>
<p>
Los primeros dos ejemplos -- <em>$cliente.getDireccion()</em> y
<em>$compra.getTotal()</em> -- pueden parecer similares a aquellos
utilizados en la secci�n de propiedades, <em>$cliente.Direccion</em>
y <em>$compra.Total</em>. Si usted supuso que estos ejemplos est�n
relacionados de alguna manera, usted esta en lo cierto.
</p>
<p>
Las Propiedades VTL pueden utilizarse como notaci�n abreviada para
los m�todos de VTL. La propiedad <em>$cliente.Direccion</em> tiene
exactamente el mismo efecto que el m�todo
<em>$cliente.getDireccion()</em> (N�tese el uso de la palabra
inglesa <em>get</em> en lugar de la castellana <em>obtener</em>).
Generalmente es preferible utilizar una Propiedad si esta
disponible. La diferencia principal entre las propiedades y los
m�todos es que usted le puede dar una lista de par�metros a un
M�todo.
</p>
<p>
La notaci�n breve se puede utilizar en los M�todos siguientes:
</p>
<div align="left">
<table cellspacing="4" cellpadding="0" border="0">
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#ffffff"><pre>
$sol.getPlanetas()
$anhelido.getMugre()
$album.getFoto()
</pre></td>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
</table>
</div>
<p>
Podr�amos esperar que estos m�todos devolvieran los nombres de los
planetas que giran alrededor del sol, alimentaran un gusano de
tierra y extrajeran una foro de un album. Los siguientes M�todos
solo se pueden referenciar por medio de la notaci�n larga:
</p>
<div align="left">
<table cellspacing="4" cellpadding="0" border="0">
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#ffffff"><pre>
$sol.getPlaneta( ["Tierra", "Marte", "Neptuno"] )
## No es posible pasar una lista de par�metros con $sun.Planets
$sisifo.empujarPiedra()
## Si dijera $sisifo.piedra Velocity asumir�a $sisifo.pushPiedra()
$libro.setTitulo( "Homenaje a Colombia" )
## No se puede pasar un par�metro en la notaci�n abreviada.
</pre></td>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
</table>
</div>
<p>
<a name="Formal Reference Notation"><strong>Notaci�n Formal de
Referncias</strong></a>
<br />
La notaci�n abreviada para referencias fue utilizada en los ejemplos
anteriores, pero tambi�n existe una notaci�n formal para referencias,
que se demuestra a continuaci�n:
</p>
<div align="left">
<table cellspacing="4" cellpadding="0" border="0">
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#ffffff"><pre>
${lanzaLodo}
${cliente.Direccion}
${compra.getTotal()}
</pre></td>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
</table>
</div>
<p>
Casi en todos los casos usted utilizar� la notaci�n abreviada, pero
existen escenarios en los cuales la notaci�n formal se requiere para
procesar corectamente la plantilla.
</p>
<p>
Suponga que usted estuviera creando una frase en la que <em>$vicio</em>
se utilizar� como prefijo para el ajetivo de una clase. La idea es
permitir a algui�n escoger la palabra base para producir uno de los dos
siguientes resultados: "Juan es un pir�mano." � "Juan es un
clept�mano.". En este caso la notaci�n abreviada no es apropiada;
considere el siguiente ejemplo:
</p>
<div align="left">
<table cellspacing="4" cellpadding="0" border="0">
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#ffffff"><pre>
Juan is a $viciomano.
</pre></td>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
</table>
</div>
<p>
Hay ambig�edad aqu�, y Velocity asume que <em>$viciomano</em>, no
<em>$vicio</em>, es el Identificador que usted quer�a utilizar. Al no
encontrar ning�n valor para <em>$viciomano</em> Velocity escribir�
simplemente <em>$viciomano</em>. Este problema se resueklve usando
notaci�n formal.
</p>
<div align="left">
<table cellspacing="4" cellpadding="0" border="0">
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#ffffff"><pre>
Juan es un ${vicio}mano.
</pre></td>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
</table>
</div>
<p>
Ahora Velocity save que la referencia es <em>$vicio</em> y no
<em>$viciomano</em>. La notaci�n formal es �til cuando las
referencias est�n ubicadas directamente al lado del texto dentro de
una plantilla.
</p>
<p>
<a name="Quiet Reference Notation"><strong>Notaci�n de Referenias
Silenciosas</strong></a>
<br />
Cuando Velocity encuentra una referencia indefinida, su
comportamiento normal es es de escribir el nombre de la referencia.
Por ejemplo, suponga que la siguiente referencia aparece como parte
de una plantilla VTL.
</p>
<div align="left">
<table cellspacing="4" cellpadding="0" border="0">
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#ffffff"><pre>
<input type="text" name="correo" value="$correo"/>
</pre></td>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
</table>
</div>
<p>
Cuando el formulario se carga por primera vez la referencia
<em>$correo</em> no tiene valor, pero usted probablemente preferir�a
un texto en blanco a uno con el valor de "$correo". Usando la
notaci�n de referencias silenciosa se pasa por alto el
comportamiento normal de Velocity. Para lograr eso en lugar de
<em>$correo</em> en el VTL usted utilizar�a <em>$!correo</em>. Con
esta modificaci�n el ejemplo anterior quedar�a as�:
</p>
<div align="left">
<table cellspacing="4" cellpadding="0" border="0">
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#ffffff"><pre>
<input type="text" name="correo" value="$!correo"/>
</pre></td>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
</table>
</div>
<p>
Ahora cuando el formulario se carga por primera vez y $correo no
tenga valor una cadena vac�a se escribir� en lugar de "$correo".
</p>
<p>
La notaci�n formal y la silenciosa se puede usar juntas como se
muestra en el ejemplo siguiente:
</p>
<div align="left">
<table cellspacing="4" cellpadding="0" border="0">
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#ffffff"><pre>
<input type="text" name="correo" value="$!{correo}"/>
</pre></td>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
</table>
</div>
</blockquote>
</p>
</td></tr>
<tr><td><br/></td></tr>
</table>
<table border="0" cellspacing="0" cellpadding="2" width="100%">
<tr><td bgcolor="#525D76">
<font color="#ffffff" face="arial,helvetica,sanserif">
<a name="Getting literal"><strong>Getting literal</strong></a>
</font>
</td></tr>
<tr><td>
<blockquote>
<p>
VTL hace uso de caracteres especiales, como <em>$</em> y <em>#</em>,
para hacer su trabajo por lo que se debe tener algo de cuidado en el
momento de utilizar estos caracteres dentro de las plantillas. Esta
secci�n habla de como escapar el caracter <em>$</em>.
</p>
<p>
<a name="Currency"><strong>Dinero</strong></a>
<br />
No hay ning�n problema en escribir "Yo compr� un saco de ma�z de
2 kg. en el mercado de lagranja por s�lo $2.50!". Como se mencion�
anteriormente, un identificador VTL siempre comienza con una letra
may�scula o min�scula por lo que $2.50 no se confunde con una
referencia.
</p>
<p>
<a name="Escaping Valid VTL References"><strong>Escapando Referencias
VTL V�lidas</strong></a>
<br />
Pueden existir casos en donde haya la posibilidad de que Velocity se
confunda. <em>Escapar</em> caracteres especiales es la mejor manera de
manejar los caracteres part�culares de VTL dentro de sus plantillas, y
esto se puede hacer utilizando el caracter palote o backslash (
<em>\</em> ).
</p>
<div align="left">
<table cellspacing="4" cellpadding="0" border="0">
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#ffffff"><pre>
#set( $correo = "foo" )
$correo
</pre></td>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
</table>
</div>
<p>
Si Velocity encuentra una referencia en su plantilla VTL a
<em>$correo</em>, el buscar� el contexto ppor un valor
correspondiente. En este caso el resultado ser� <em>foo</em> por
qu� <em>$correo</em> esta definido. Si <em>$correo</em> no esta
definido el resultado ser� <em>$correo</em>.
</p>
<p>
Suponga que <em>$correo</em> est� definido (por ejemplo, que tiene
el valor <em>foo</em>) y que usted desea escribir <em>$correo</em>.
Existen varias maneras de hacer esto pero la m�s sencilla es usar el
caracter de escape.
</p>
<div align="left">
<table cellspacing="4" cellpadding="0" border="0">
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#ffffff"><pre>
## La siguiente l�nea define $correo en esta plantilla:
#set( $correo = "foo" )
$correo
\$correo
\\$correo
\\\$correo
</pre></td>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
</table>
</div>
<p>
se muestra como
</p>
<div align="left">
<table cellspacing="4" cellpadding="0" border="0">
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#ffffff"><pre>
foo
$correo
\foo
\$correo
</pre></td>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
</table>
</div>
<p>
Note que el caracter <em>\</em> se asocia con <em>$</em> por la
izquierda. La regla de asociaci�n por la izquierda hace que
<em>\\\$correo</em> se muestre como <em>\\$correo</em>. Compare estos
ejemplos con lo siguientes, en los que <em>$correo</em> no esta
definido.
</p>
<div align="left">
<table cellspacing="4" cellpadding="0" border="0">
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#ffffff"><pre>
$correo
\$correo
\\$correo
\\\$correo
</pre></td>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
</table>
</div>
<p>
se muestra como
</p>
<div align="left">
<table cellspacing="4" cellpadding="0" border="0">
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#ffffff"><pre>
$correo
\$correo
\\$correo
\\\$correo
</pre></td>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
</table>
</div>
<p>
Note que Velocity maneja de manera diferentes las referencias que
est�n definidas de aquellas que no lo est�n. A continuaci�n se
encuentra una directiva que da a <em>$foo</em> el valor
<em>verde</em>.
</p>
<div align="left">
<table cellspacing="4" cellpadding="0" border="0">
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#ffffff"><pre>
#set( $foo = "verde" )
$luna = $foo
</pre></td>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
</table>
</div>
<p>
La salida ser�: <em>$luna = verde</em> -- donde <em>$luna</em> se
escribe literalmente porqu� esta indefinido y <em>verde</em> se escribe
en lugar de <em>$foo</em>
</p>
<p>
Tambi�n es posible escapar directivas de VTL; esto se describe con
m�s detalle en la secci�n de Directivas.
</p>
</blockquote>
</p>
</td></tr>
<tr><td><br/></td></tr>
</table>
<table border="0" cellspacing="0" cellpadding="2" width="100%">
<tr><td bgcolor="#525D76">
<font color="#ffffff" face="arial,helvetica,sanserif">
<a name="Case Substitution"><strong>Case Substitution</strong></a>
</font>
</td></tr>
<tr><td>
<blockquote>
<p>
Ahora que usted esta familiarizado con las referencias, puede comenzar a
aplicarlas de manera efectiva en sus plantillas. Las referencias de
Velocity aprovechan algunos principios de Java que los dise�adores de
plantillas encontrar�nm f�ciles de utilizar. Por ejemplo:
</p>
<div align="left">
<table cellspacing="4" cellpadding="0" border="0">
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#ffffff"><pre>
$foo
$foo.getBar()
## el lo mismo que
$foo.Bar
$data.getUser("jon")
## es lo mismo que
$data.User("jon")
$data.getRequest().getServerName()
## es lo mismo que
$data.Request.ServerName
## que a su vez, es igual a
${data.Request.ServerName}
</pre></td>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
</table>
</div>
<p>
Estos ejemplos ilustran usos alternativos para la mismas referencias.
Velocity se aprovechas de la instrospecci�n y las capacidades de beans
de Java para resolver los nombre de referencias tanto en el Contexto
como en los m�todos de los objetos. Es posible incluir y evaluar
referencias casi en cualquier lugar de su plantilla.
</p>
<p>
Velocity, que ha sido modelado con las especificaciones de Bean
definidas por Sun Microsystems, distingue entre may�sculas y
min�sculas; sin embargo sus desarrolladores se han esforzado para
encontrar y corregir los errores del usuario cuando sea posible.
Cuando el m�todo <em>getFoo()</em> es referenciado dentro de una
plantilla como <code>$bar.foo</code>, Velocity intentar� primero
<code>getfoo()</code>. Si esto falla, intentar� <code>getFoo()</code>.
De la misma manera, cuando una plantilla se refiera a
<code>$bar.Foo</code>, Velocity intentar� <em>$getFoo()</em> primero
y luego <em>getfoo()</em>.
</p>
<p>
Nota: <em>Las Referencias a variables de instancia dentro de una
plantilla no se resuelven.</em> Solo las referencias a los
atributos get y set de los JavaBeans se resuelven (i.e.
<code>$foo.Nombre</code> se resuelve como el m�todo de instancia
<code>getNombre()</code> de la clase Foo, pero no como su variable
de instancia <code>Nombre</code>).
</p>
</blockquote>
</p>
</td></tr>
<tr><td><br/></td></tr>
</table>
<table border="0" cellspacing="0" cellpadding="2" width="100%">
<tr><td bgcolor="#525D76">
<font color="#ffffff" face="arial,helvetica,sanserif">
<a name="Directives"><strong>Directives</strong></a>
</font>
</td></tr>
<tr><td>
<blockquote>
<p>
Las Referencias le permiten a los dise�adores de plantillas generar
contenido din�mico para sitios web, mientras que las
<em>directivas</em> -- elementos de script f�ciles de usar que se
pueden usar para manipular de manera creativa la salida del c�digo
Java -- les permiten a los dise�adores realmente estar a cargo de la
apariencia y en contenido del sitio web.
</p>
<a name="Set"><strong>#set</strong></a>
<p>
La directiva <em>#set</em> se utiliza para establecer el valor de una
referencia. El valor se puede asignar a una referencia de variable o
una referencia de propiedad, siempre entre par�ntesis, como se muestra
a continuaci�n:
</p>
<div align="left">
<table cellspacing="4" cellpadding="0" border="0">
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#ffffff"><pre>
#set( $primate = "mono" )
#set( $cliente.Comportamiento = $primate )
</pre></td>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
</table>
</div>
<p>
El lado izquierdo (LI) de la asignaci�n debe ser una referencia de
variable o una referencia de propiedad. El lado derecho (LD) puede
ser de alguno de los siguientes tipos:
</p>
<p>
<ul>
<li>Referencia de Variable</li>
<li>Constante de Cadena</li>
<li>Referencia de Propiedad</li>
<li>Referencia de M�todo</li>
<li>Literal Num�rico</li>
<li>Lista de elementos como arreglo</li>
</ul>
</p>
<p>
These examples demonstrate each of the aforementioned types:
</p>
<div align="left">
<table cellspacing="4" cellpadding="0" border="0">
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#ffffff"><pre>
#set( $mono = $pedro ) ## Referencia de Variable
#set( $mono.Amigo = "monica" ) ## Constante de Cadena
#set( $mono.Culpar = $casablanca.Fuga ) ## referencia de propiedad
#set( $mono.Plan = $doctor.llamar($web) ) ## referencia de m�todo
#set( $mono.Numero = 123 ) ##Literal Num�rico
#set( $mono.Decir = ["No", "es", $mi, "culpa"] ) ##Arreglo
</pre></td>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
</table>
</div>
<p>
NOTA: En el �ltimo ejemplo los elementos definidos con el operador
[..] son accesibles usando los m�todos definidos en la clase ArrayList.
As�, por ejemplo, usted podr�a acceder el primer elemento del arreglo utilizando $mono.Decir.get(0), con lo que obtendr�a la palabra "No".
</p>
<p>
El lado derecho tambi�n puede ser una expresi�n aritm�tica sencilla:
</p>
<div align="left">
<table cellspacing="4" cellpadding="0" border="0">
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#ffffff"><pre>
#set( $value = $foo + 1 )
#set( $value = $bar - 1 )
#set( $value = $foo * $bar )
#set( $value = $foo / $bar )
</pre></td>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
</table>
</div>
<p>
Si el Lado Derecho es una propiedad o referencia de m�todo que se
eval�a como <em>null</em>, <b>no</b> ser� asignada al lado
izquierdo. No es posible remover una referencia existente del
contexto utilizando este mecanismo. Esto puede ser confuso para los
reci�n llegados a Velocity. Por ejemplo:
</p>
<div align="left">
<table cellspacing="4" cellpadding="0" border="0">
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#ffffff"><pre>
#set( $resultado = $consulta.criterio("nombre") )
El resultado de la primera consulta en $resultado
#set( $resultado = $consulta.criterio("direccion") )
El resultado de la segunda consulta es $resultado
</pre></td>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
</table>
</div>
<p>
Si <em>$consulta.criterio("nombre")</em> retorna la cadena "pedro",
y <em>$consulta.criterio("direccion")</em> retorna <em>null</em>, el
VTL anterio se mostrar�a de la siguiente manera:
</p>
<div align="left">
<table cellspacing="4" cellpadding="0" border="0">
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#ffffff"><pre>
El resultado de la primera consulta en pedro
El resultado de la primera consulta en pedro
</pre></td>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
</table>
</div>
<p>
Esto tiende a confundir a quines est�n comenzando, que construyen
ciclos <em>#foreach</em> que intentan hacer <em>#set</em> de una
referencia por medio de una propiedad o un m�todo e inmediatamente
eval�an la referencia con una directiva <em>#if</em>. Por ejemplo:
</p>
<div align="left">
<table cellspacing="4" cellpadding="0" border="0">
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#ffffff"><pre>
#set( $criterios = ["nombre", "direccion"] )
#foreach( $criterio in $criterios )
#set( $resultado = $consulta.criterios($criterio) )
#if( $result )
La consulta tuvo �xito
#end
#end
</pre></td>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
</table>
</div>
<p>
En el ejemplo anterior, no ser�a inteligente confiar en la
evaluaci�n de <em>$resultado</em> para determinar si una consulta
tuvo �xito. Despu�s de que <em>$result</em> ha sido agregado al
contexto (por medio de una directiva <em>#set</em>), no puede volver
a establecerse a <em>null</em> (quitarse del contexto). Los detalles
de las directivas <em>#if</em> y <em>#foreach</em> son cubiertos con
mayor detalle posteriormente en esta gu�a.
</p>
<p>
Una soluci�n para este problema puede ser predefinir
<em>$resultado</em> a <em>false</em>. Luego, si la llamada a
<em>$consulta.criterios()</em> falla, es posible verificar.
</p>
<div align="left">
<table cellspacing="4" cellpadding="0" border="0">
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#ffffff"><pre>
#set( $criterios = ["nombre", "direccion"] )
#foreach( $criterio in $criterios )
#set( $resultado = false )
#set( $resultado = $consulta.criterios($criterio) )
#if( $resultado )
La consulta tuvo �xito
#end
#end
</pre></td>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
</table>
</div>
<p>
A diferencia de algunas de las otras directivas de Velocity, la
directiva <em>#set</em> no tiene un enunciado <em>#end</em>.
</p>
<a name="String Literals"><strong>Cadenas de Caracteres</strong></a>
<p>
Cuando se utiliza la directiva <em>#set</em>, los literales de
cadena que est�n encerrados en comillas dobles ser�n evaluados y
mostrados en la plantilla, como se demuestra a continuaci�n:
</p>
<div align="left">
<table cellspacing="4" cellpadding="0" border="0">
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#ffffff"><pre>
#set( $directorioRaiz = "www" )
#set( $nombrePlantilla = "indice.vm" )
#set( $plantilla = "$directorioRaiz/$nombrePlantilla" )
$plantilla
</pre></td>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
</table>
</div>
<p>
La salida ser�:
</p>
<div align="left">
<table cellspacing="4" cellpadding="0" border="0">
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#ffffff"><pre>
www/indice.vm
</pre></td>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
</table>
</div>
<p>
Sin embargo, cuando la cadena de caracteres esta encerrada en
comillas sencillas, no ser� evaluada:
</p>
<div align="left">
<table cellspacing="4" cellpadding="0" border="0">
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#ffffff"><pre>
#set( $foo = "bar" )
$foo
#set( $blarg = '$foo' )
$blarg
</pre></td>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
</table>
</div>
<p>Se muestra como:</p>
<div align="left">
<table cellspacing="4" cellpadding="0" border="0">
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#ffffff"><pre>
bar
$foo
</pre></td>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
</table>
</div>
<p>
Por defecto, la caracter�stica de las comillas sencillas para
mostrar texto sin evaluar esta disponible en Velocity; sin embargo
este valor por defecto se puede cambiar editando el archivo
<code>velocity.properties</code> de tal manera que
<code>stringliterals.interpolate=false</code>.
</p>
</blockquote>
</p>
</td></tr>
<tr><td><br/></td></tr>
</table>
<table border="0" cellspacing="0" cellpadding="2" width="100%">
<tr><td bgcolor="#525D76">
<font color="#ffffff" face="arial,helvetica,sanserif">
<a name="Conditionals"><strong>Conditionals</strong></a>
</font>
</td></tr>
<tr><td>
<blockquote>
<strong>Condicionales</strong>
<p>
La directiva <em>#if</em> en Velocity permite que se incluya texto
dentro de la plantilla generada, con la condici�n de que el
enunciado condicional evalue a verdadero. Por ejemplo:
</p>
<div align="left">
<table cellspacing="4" cellpadding="0" border="0">
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#ffffff"><pre>
#if( $foo )
<strong>Velocity!</strong>
#end
</pre></td>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
</table>
</div>
<p>
La variable <em>$foo</em> se eval�a para determinar si es verdadera,
cosa que ocurrir� bajo una de dos circunstancias: (i) <em>$foo</em>
es un valor booleano (verdadero � falso) que tiene un valor de
verdadero, � (ii) el valor no es <em>null</em>. Recuerde que el
contexto de Velocity solamente contiene objetos, por lo que cuando
se dice 'booleano' se habla en realidad de la clase Boolean. Esto es
cierto incluso para los m�todos que devuelven un valor de tipo
<code>boolean</code> - la infraestructura de introspecci�n devolver�
un <code>Boolean</code> del mismo valor l�gico.
</p>
<p>
El contenido que se encuentra entre el enunciado <em>#if</em> y el
enunciado <em>#end</em> es lo que se escribe en la plantilla si la
evaluaci�n resulta en un valor verdadero. En este caso, si
<em>$foo</em> es verdadero, la salida ser�: "Velocity!". De manera
an�loga, si <em>$foo</em> tiene un valor <em>null</em>, o evalua a
falso, entonces el enunciado completo es falso y no se escribe nada.
</p>
<p>
Un elemento <em>#elseif</em> � <em>#else</em> puede utilizarse junto
con una sentencia <em>#if</em> para indicar condiciones adicionales
o la labor por defecto. Note que el Motor de Plantillas de Velocity
parar� en la primera expresi�n que evalue a verdadero. En el ejemplo
siguiente suponga que <em>$foo</em> tiene un valor de 15 y
<em>$bar</em> tiene un valor de 6.
</p>
<div align="left">
<table cellspacing="4" cellpadding="0" border="0">
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#ffffff"><pre>
#if( $foo < 10 )
<strong>Vaya hac�a el Norte</strong>
#elseif( $foo == 10 )
<strong>Vaya hac�a el Este</strong>
#elseif( $bar == 6 )
<strong>Vaya al Sur</strong>
#else
<strong>Vaya al Oeste</strong>
#end
</pre></td>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
</table>
</div>
<p>En este ejemplo, <em>$foo</em> es mayor que diez, por lo que las
dos primeras comparaciones fallan. A continuaci�n se compara
<em>$bar</em> con 6, como son iguales, la salida es <strong>Vaya al
Sur</strong>
</p>
<p>
Actualmente las comparaciones num�ricas de Velocity est�n
restringidas a los elementos de la clase Integer - cualquier otra
cosa evaluar� a <em>falso</em>. La �nica excepci�n a esta regla es
la igualdad, '==', donde Velocity exige que los objetos a cada lado
del '==' sean de la <em>misma</em> clase.
</p>
<p>
<a name="Relational and Logical Operators"><strong>Operadores
L�gicos y Relacionales</strong></a>
</p>
<p>
Velocity usa el operador de equivalencia para determinar las
relaciones entre las variables. A continuaci�n hay un ejemplo
sencillo para ilustrar como se utiliza el operador de igualdad.
</p>
<div align="left">
<table cellspacing="4" cellpadding="0" border="0">
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#ffffff"><pre>
#set ($foo = "�cido desoxiribonucleico")
#set ($bar = "�cido ribonucleico")
#if ($foo == $bar)
En este caso es claro que no son equivalentes por lo que....
In this case it's clear they aren't equivalent. So...
#else
No son equivalentes y esta ser� la salida.
#end
</pre></td>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
</table>
</div>
<p>
Velocity tiene tambi�n operadores l�gicos para el Y, el O y el NO
(AND, OR y NOT). Para mayor informaci�n vea la <a href="vtl-reference-guide.html">Gu�a de Referencia VTL</a>.
A continuaci�n se encuentran ejemplos que demuestran la utilizaci�n
de los operadores l�gicos AND, OR y NOT.
</p>
<div align="left">
<table cellspacing="4" cellpadding="0" border="0">
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#ffffff"><pre>
## Y l�gico
#if( $foo && $bar )
<strong>Esto Y aquello</strong>
#end
</pre></td>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
</table>
</div>
<p>
La directiva <em>#if()</em> solamente evaluar� a verdadero si tanto
<em>$foo</em> como <em>$bar</em> son ciertos. Si <em>$foo</em> es
falso la expresi�n evaluar� a falso; <em>$bar</em> no ser� evaluada.
Si <em>$foo</em> es verdadero el Motor de Plantillas de Velocity
verificar� el valor de <em>$bar</em>; si <em>$bar</em> es cierto,
entonces toda la expresi�n es cierto y la salida es <strong>Esto Y
aquello</strong>. Si <em>$bar</em> es falso, entonces no habr�
ninguna salida porque toda la expresi�n es falsa.
</p>
<p>
El O l�gico trabaja de la misma manera, pero s�lo una de las
referencias debe evaluar a verdadero para que toda la expresi�n
evalue a verdadero. Considere el ejemplo siguiente.
</p>
<div align="left">
<table cellspacing="4" cellpadding="0" border="0">
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#ffffff"><pre>
## O l�gico
#if( $foo || $bar )
<strong>Esto O Aquello</strong>
#end
</pre></td>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
</table>
</div>
<p>
Si <em>$foo</em> es verdadero, el Motor de Plantillas de Velocity no
necesita consultar <em>$bar,</em>; sin importar si <em>$bar</em> es
cierto o falso, la expresi�n ser� cierta, y <strong>Esto O
Aquello</strong> ser� la salida. Si <em>$foo</em> es falso, en
cambio, es necesario verificar <em>$bar</em>. En este caso, si
<em>$bar</em> es falso, entonces la expresi�n es falsa y no se
escribe nada. De otro lado, si <em>$bar</em> es verdadero, entonces
toda la expresi�n es verdadera y el resultado es <strong>Esto O
Aquello</strong>
</p>
<p>
Con el operador l�gico NO, solo hay un argumento :
</p>
<div align="left">
<table cellspacing="4" cellpadding="0" border="0">
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#ffffff"><pre>
## NO l�gico
#if( !$foo )
<strong>eso NO</strong>
#end
</pre></td>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
</table>
</div>
<p>
Aqu� si <em>$foo</em> es cierto, entonces <em>!$foo</em> es falso, y
no se escribe nada. Por el contrario, si <em>$foo</em> es falso,
entonces <em>!$foo</em> ser� verdadero y <strong>eso NO</strong>
ser� escrito. Tenga cuidado de no confundir este operador con la
<em>referencia sileciosa $!foo</em>, que es algo completamente
distinto.
</p>
</blockquote>
</p>
</td></tr>
<tr><td><br/></td></tr>
</table>
<table border="0" cellspacing="0" cellpadding="2" width="100%">
<tr><td bgcolor="#525D76">
<font color="#ffffff" face="arial,helvetica,sanserif">
<a name="Loops"><strong>Loops</strong></a>
</font>
</td></tr>
<tr><td>
<blockquote>
<strong>Ciclo Foreach</strong>
<p>
El elemento <em>#foreach</em> permite la construcci�n de ciclos. Por
ejemplo:
</p>
<div align="left">
<table cellspacing="4" cellpadding="0" border="0">
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#ffffff"><pre>
<ul>
#foreach( $producto in $todosProductos )
<li>$producto</li>
#end
</ul>
</pre></td>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
</table>
</div>
<p>
Este cilco <em>#foreach</em> hace que el objeto correspondiente a la
lista de $todosProductos sea iterado buscando todos los productos de
la lista. En cada iteraci�n del ciclo, el valor de
<em>$todosProductos</em> se asigna a la variable <em>$producto</em>.
</p>
<p>
El contenido de la variable <em>$todosProductos</em> es un Vector,
una tabla de Hashing (Hashtable) o un arreglo (Array). El valor
asignado a la variable <em>$producto</em> es un objeto Java y se
puede referenciar desde una variabkle como tal. Por ejemplo, si
<em>$product</em> fuera realmente un elemento de la clase Producto
en Java, su nombre se podr�a obtener referenciando el m�todo
<em>$producto.Nombre</em> (ie: <em>$Product.getName()</em>).
</p>
<p>
Ahora supongamos que <em>$todosProductos</em> es una tabla de
Hashing. Si usted quisiera recuperar los valores de las llaves de la
tabla de Hashing, al igual que los objetos dentro de esta, usted
podr�a utilizar c�digo como el siguiente:
</p>
<div align="left">
<table cellspacing="4" cellpadding="0" border="0">
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#ffffff"><pre>
<ul>
#foreach( $llave in $todosProductos.keySet() )
<li>Llave: $llave -> Valor: $todosProductos.get($llave)</li>
#end
</ul>
</pre></td>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
</table>
</div>
<p>
Velocity proporciona una manera sencilla de obtener el contador del
ciclo para que usted pueda hacer algo como lo siguiente:
</p>
<div align="left">
<table cellspacing="4" cellpadding="0" border="0">
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#ffffff"><pre>
<table>
#foreach( $cliente in $listaClientes )
<tr><td>$velocityCount</td><td>$cliente.Nombre</td></tr>
#end
</table>
</pre></td>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
</table>
</div>
<p>
El nombre por defecto para la referencia de la variable contador del
ciclo, que se especifica en el archivo
<code>velocity.properties</code>, es
$velocityCount. Por defecto el contador comienza en 1, pero esto se
puede hacer 0 o 1 en el archivo <code>velocity.properties</code>. A
continuaci�n se muestra el fragmento de este archivo que corresponde
al contador de ciclo (en ingl�s, tal como aparece en el archivo
original):
</p>
<div align="left">
<table cellspacing="4" cellpadding="0" border="0">
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#ffffff"><pre>
# Default name of the loop counter
# variable reference.
directive.foreach.counter.nombre = velocityCount
# Default starting value of the loop
# counter variable reference.
directive.foreach.counter.initial.value = 1
</pre></td>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
</table>
</div>
</blockquote>
</p>
</td></tr>
<tr><td><br/></td></tr>
</table>
<table border="0" cellspacing="0" cellpadding="2" width="100%">
<tr><td bgcolor="#525D76">
<font color="#ffffff" face="arial,helvetica,sanserif">
<a name="Include"><strong>Include</strong></a>
</font>
</td></tr>
<tr><td>
<blockquote>
<p>
El elemento de script <em>#include</em> le permite al dise�ador de
plantillas importar un archivo local, que despu�s es insertado en la
localizaci�n donde se encuentra la sentencia <em>#include</em>. Los
contenidos del archivo no se muestran por intermedio del motor de
plantillas por lo que si se hacen referencias dentro del archivo,
estas no ser�n reemplazadas. Por motivos de seguridad el archivo que
va a ser incluido debe encontrarse en el directorio indicado por la
propiedad TEMPLATE_ROOT.
</p>
<div align="left">
<table cellspacing="4" cellpadding="0" border="0">
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#ffffff"><pre>
#include( "uno.txt" )
</pre></td>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
</table>
</div>
<p>
El archivo al que se refiere la directiva <em>#include</em> se
encierra entre comillas. Si mas de un archivo ser� incluido, los
nombres de los archivos a incluir deben ir separados por comas.
</p>
<div align="left">
<table cellspacing="4" cellpadding="0" border="0">
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#ffffff"><pre>
#include( "uno.gif","dos.txt","tres.htm" )
</pre></td>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
</table>
</div>
<p>
El archivo a incluir no tiene que ser referenciado por nombre, de
hecho, muchas veces es preferible usar una variable, en lugar de un
nombre de archivo. Esto puede ser �til para dirigir la salida de
acuerdo a criterios determinados cuando la solicitud de la p�gina es
enviada, es decir, que dependa de factores como los datos del
usuario que visita la p�gina, el momento del d�a, etc. A
continuaci�n se muestra un ejemplo en el que se usan tanto un nombre
como una variable.
</p>
<div align="left">
<table cellspacing="4" cellpadding="0" border="0">
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#ffffff"><pre>
#include( "greetings.txt", $seasonalstock )
</pre></td>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
</table>
</div>
</blockquote>
</p>
</td></tr>
<tr><td><br/></td></tr>
</table>
<table border="0" cellspacing="0" cellpadding="2" width="100%">
<tr><td bgcolor="#525D76">
<font color="#ffffff" face="arial,helvetica,sanserif">
<a name="Parse"><strong>Parse</strong></a>
</font>
</td></tr>
<tr><td>
<blockquote>
<p>
El elemento de script <em>#parse</em> le permite al dise�adore de
plantillas importar un archivo local que contiene VTL. Velocity
procesar� el VTL y mostrar� la plantilla especificada.
</p>
<div align="left">
<table cellspacing="4" cellpadding="0" border="0">
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#ffffff"><pre>
#parse( "yo.vm" )
</pre></td>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
</table>
</div>
<p>
Al igual que la directiva <em>#include</em>, <em>#parse</em> puede
utilizar una variable, en lugar de una plantilla. Todas las
plantillas a las que <em>#parse</em> se refiera deben incluirse bajo
TEMPLATE_ROOT. A diferencia de la directva <em>#include</em>,
<em>#parse</em> solo recibe un argumento.
</p>
<p>
Las plantillas de VTL puede tener sentencias <em>#parse</em> que se
refieran a plantillas que a su vez tengan sentencias
<em>#parse</em>. La l�nea <em>parse_directive.maxdepth</em> del
archivo <code>velocity.properties</code>, cuyo valor por defecto es
10, permite a los usuarios configurar el m�ximo n�mero de
referencias a <em>#parse</em> que pueden ocurrir desde una �nica
plantilla. (Nota: Si la propiedad <em>parse_directive.maxdepth</em>
no esta dentro del archivo <code>velocity.properties</code>,
Velocity establecer� el valor por defecto en 10.) La recursi�n esta
permitida, por ejemplo, si la plantilla <code>hacerfoo.vm</code>
contiene las siguientes l�neas:
</p>
<div align="left">
<table cellspacing="4" cellpadding="0" border="0">
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#ffffff"><pre>
Cuenta Regresiva.
#set( $cuenta = 8 )
#parse( "parsefoo.vm" )
Listo hacerfoo.vm!
</pre></td>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
</table>
</div>
<p>
Hay una referencia a la plantilla <code>parsefoo.vm</code>, que
contiene el siguiente c�digo VTL:
</p>
<div align="left">
<table cellspacing="4" cellpadding="0" border="0">
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#ffffff"><pre>
$cuenta
#set( $cuenta = $cuenta - 1 )
#if( $cuenta > 0 )
#parse( "parsefoo.vm" )
#else
Listo parsefoo.vm!
#end
</pre></td>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
</table>
</div>
<p>
Despu�s de que se muestra "Cuenta Regresiva.", Velocity pasa por
<code>parsefoo.vm</code>, contando hac�a abajo desde 8. Cuando el
conteo llegue a 0, mostrar� el mensaje "Listo parsefoo.vm!". En este
punto Velocity volver� a <code>dofoo.vm</code> y escribir� el
mensaje "Listo hacerfoo.vm!".
</p>
</blockquote>
</p>
</td></tr>
<tr><td><br/></td></tr>
</table>
<table border="0" cellspacing="0" cellpadding="2" width="100%">
<tr><td bgcolor="#525D76">
<font color="#ffffff" face="arial,helvetica,sanserif">
<a name="Stop"><strong>Stop</strong></a>
</font>
</td></tr>
<tr><td>
<blockquote>
<p>
El elemento de script <em>#stop</em> permite al dise�ador parar la
ejecuci�n del motor de plantillas y volver. Esto es �til para prop�sitos
de correcci�n de errores.
</p>
<div align="left">
<table cellspacing="4" cellpadding="0" border="0">
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#ffffff"><pre>
#stop
</pre></td>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
</table>
</div>
</blockquote>
</p>
</td></tr>
<tr><td><br/></td></tr>
</table>
<table border="0" cellspacing="0" cellpadding="2" width="100%">
<tr><td bgcolor="#525D76">
<font color="#ffffff" face="arial,helvetica,sanserif">
<a name="Velocimacros"><strong>Velocimacros</strong></a>
</font>
</td></tr>
<tr><td>
<blockquote>
<p>
El elemento de script <em>#macro</em> script permite definir un
segmento de plantilla VTL repetitivo. Los Velocimacros son muy
�tiles en una amplia gama se situaciones, tanto simples como
complejas. El siguiente Velocimacro, creado con el �nico prop�sito
de ahorrar tecleo y minimizar errores tipogr�ficos, provee una
introducci�n al concepto de Velocimacros
element allows template designers to.
</p>
<div align="left">
<table cellspacing="4" cellpadding="0" border="0">
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#ffffff"><pre>
#macro( d )
<tr><td></td></tr>
#end
</pre></td>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
</table>
</div>
<p>
El Velocimacro que se define en este ejemplo es <em>d</em>, y se
puede llamar de manera similar a cualquier otra directiva VTL:
</p>
<div align="left">
<table cellspacing="4" cellpadding="0" border="0">
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#ffffff"><pre>
#d()
</pre></td>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
</table>
</div>
<p>
Cuando esta plantilla sea solicitada, Velocity reemplazar� <em>#d()</em>
por una fila conteniendo un �nica celda vacia.
</p>
<p>
Un Velocimacro puiede tomar cualquier n�mero de argumentos -- no tener
ning�n argumento, como se mostr� en el primer ejemplo, es una opci�n --
pero cuando sea invocado el Velocimacro debe ser llamado con el mismo
n�mero de argumentos con el que fue definido. Muchos Velocimacros se
relacionan con el entorno mucho m�s con su entorno que el ejemplo
demostrado anteriormente. Aqu� hay un Velocimacro que recibe dos
argumentos, un color y un arreglo.
</p>
<div align="left">
<table cellspacing="4" cellpadding="0" border="0">
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#ffffff"><pre>
#macro( filastabla $color $algunalista )
#foreach( $algo in $algunalista )
<tr><td bgcolor=$color>$algo</td></tr>
#end
#end
</pre></td>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
</table>
</div>
<p>
El Velocimacro que se define en este ejemplo, <em>filastabla</em>, toma
dos argumentos. El primer argumento toma el lugar de <em>$color</em>, y
el segundo argumento el de <em>$algunalista</em>
</p>
<p>
Cualquier cosa que se pueda incluir dentro de una plantilla VTL puede
formar parte delcuerpo de un Velocimacro. El Velocimacro
<em>filastabla</em> es una sentencia <em>foreach</em>. Hay dos
sentencias <em>#end</em> dentro del Velocimacro; la primera pertenece al
<em>foreach</em> y a segunda termina la definici�n del Velocimacro.
</p>
<div align="left">
<table cellspacing="4" cellpadding="0" border="0">
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#ffffff"><pre>
#set( $grandeslagos = ["Superior","Michigan","Huron","Erie","Ontario"] )
#set( $color = "blue" )
<table>
#filastabla( $color $grandeslagos )
</table>
</pre></td>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
</table>
</div>
<p>
Note que <em>$grandeslagos</em> toma el lugar de
<em>$algunalista</em>. Cuando el Velocimacro es llamado en esta
situaci�n, la siguiente salida es generada:
</p>
<div align="left">
<table cellspacing="4" cellpadding="0" border="0">
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#ffffff"><pre>
<table>
<tr><td bgcolor="blue">Superior</td></tr>
<tr><td bgcolor="blue">Michigan</td></tr>
<tr><td bgcolor="blue">Huron</td></tr>
<tr><td bgcolor="blue">Erie</td></tr>
<tr><td bgcolor="blue">Ontario</td></tr>
</table>
</pre></td>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
</table>
</div>
<p>
Los Velocimacro pueden ser definidos <em>inline</em> dentro de una
plantilla. Esto quiere decir que la definici�n del macro no esta
disponible para otras plantillas dentro del mimso sitio Web. Definir un
Velocimacro de tal forma que sea compartido por todas las plantillas
tiene ventajas obvias: Reduce la necesidad de redefinir el macro en
varias plantillas, ahorrando trabajo y disminuyendo las posiblidades de
error, adem�s de asegurar que un �nico cambio en un archivo quedar�
disponible para todas las plantillas.
</p>
<p>
Si el Velocimacro <em>#filastabla($color $lista)</em> fuera definido en
una librer�a, se podr�a utilizar en cualquiera de la plantillas
normales; se podr�a utilizar muchas veces con prop�sitos distintos. En
la plantilla <code>vegetal.vm</code> dedicado a todas las plantas, el
Velocimacro <em>#filastabla</em> podr�a invocarse para listar las partes
de un vegetal t�pico:
</p>
<div align="left">
<table cellspacing="4" cellpadding="0" border="0">
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#ffffff"><pre>
#set( $partes = ["ra�z","tallo","hojas","flores","frutos"] )
#set( $colorCelda = "#CC00FF" )
<table>
#filastabla( $colorCelda $parts )
</table>
</pre></td>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
</table>
</div>
<p>
Cuando atendiera ls solicitud de <code>vegetal.vm</code>, Velocity
encontrar�a el macro <em>#filastabla</em> en la librer�a de plantillas
(definida en el archivo <code>velocity.properties</code>) y generar�a el
siguiente resultado:
</p>
<div align="left">
<table cellspacing="4" cellpadding="0" border="0">
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#ffffff"><pre>
<table>
<tr><td bgcolor="#CC00FF">ra�z</td></tr>
<tr><td bgcolor="#CC00FF">tallo</td></tr>
<tr><td bgcolor="#CC00FF">hojas</td></tr>
<tr><td bgcolor="#CC00FF">flores</td></tr>
<tr><td bgcolor="#CC00FF">frutos</td></tr>
</table>
</pre></td>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
</table>
</div>
<strong>Argumentos de un Velocimacro</strong>
<p>
Los Velocimacros pueden recibir como argumentos cualquiera de los
siguientes elementos de VTL:
</p>
<ul>
<li>
Referencia : cualquier coa que comience con '$'
</li>
<li>
Cadena de caracteres : algo como "$foo" u 'hola'
</li>
<li>
N�mero : 1, 2 etc
</li>
<li>
Rango de enteros : [ 1..2] � [$foo .. $bar]
</li>
<li>
ObjectArray : [ "a", "b", "c"]
</li>
<li>
El valor booleano "verdadero"
</li>
<li>
El valor booleano "falso"
</li>
</ul>
<p>
Cuando pase referencias como argumentos para los Velocimacros tenga
en cuenta que las referencias se pasan 'por nombre'. Esto quiere
decir que su valor es 'generado' cada vez que se usa dentro del
Velocimacros. Esta caracter�stica le permite pasar referencias con
las llamadas de m�todo y hacer que el m�todo se llame cada vez. Por
ejemplo, cuando llame el siguiente Velocimacro
</p>
<div align="left">
<table cellspacing="4" cellpadding="0" border="0">
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#ffffff"><pre>
#macro( llamame $a )
$a $a $a
#end
#llamame( $foo.bar() )
</pre></td>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
</table>
</div>
<p>
Esa llamada hace que el m�todo bar() de la referencia $foo sea
llamado 3 veces.
</p>
<p>
A primera vista, esta caracter�stica parece sorprendente, pero
cuando se tiene en cuenta la motivaci�n original de los Velocimacros
-- eliminar la duplicaci�n de "copiar y pegar" del VTL usado varias
veces -- tiene mucho sentido. Permite pasar al Velocimacro objetos
con estado, como un objeto que genera colores en una secuencia
repetitiva para colorear las filas de una tabla.
</p>
<p>
Si usted no desea utilizar esta caracter�stica siempre es posible
simplemente obtener el valor del m�todo como una nueva referencia y
pasar ese valor:
</p>
<div align="left">
<table cellspacing="4" cellpadding="0" border="0">
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#ffffff"><pre>
#set( $mivalor = $foo.bar() )
#llamame( $mivalor )
</pre></td>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
</table>
</div>
<strong>Propiedades de un Velocimacro</strong>
<p>
Varias l�neas en al archivo <code>velocity.properties</code> permiten
flexibilizar la implementaci�n de los Velocimacro. Tenga en cuenta
que estas propiedades tambi�n est�n documentadas en la <a href="developer-guide.html">Gu�a de Desarrolladores</a>.
</p>
<p>
<code>velocimacro.library</code> - Una lista, separada por comas de
todas la librerias de plantillas de Velocimacros. Por defecto,
Velocity busca una sola librer�a: <em>VM_global_library.vm</em>. El
directorio en el que se buscan las plantillas tambi�n se utiliza para
localizar las librer�as.
</p>
<p>
<code>velocimacro.permissions.allow.inline</code> - Esta propiedad,
que tiene como valores posibles verdadero y falso (true y false),
determina si los Velocimacros pueden ser definidos dentro de las
plantillas normales.
El valor por defecto, verdadero, le permite a los dise�adores
definir por si mismos macros en las plantillas.
</p>
<p>
<code>velocimacro.permissions.allow.inline.to.replace.global</code> -
Con valores posibles verdadero y falso (true y false), esta
propiedad le permite al usuario decidir si un Velocimacro definido
inline dentro de una plantilla puede reemplazar a la plantilla
global, que fue cargada al comienzo por medio de la propiedad
<code>velocimacro.library</code>. El valor por defecto, falso
(<code>false</code>), evita que los Velocimacros definidos en una
plantilla reemplacen a los que fueron cargados al inicio.
</p>
<p>
<code>velocimacro.permissions.allow.inline.local.scope</code> -
Con valores posibles verdadero y falso (true y false), valor por
defecto falso, esta propiedad dice si los Velocimacros definidos
inline son 'visibles' �nicamente para la plantilla que los define.
Usted puede usar esta caracter�stica para hacer algunos trucos de
VM - si un VM global llama a otro VM global, con ancance inline, una
plantilla puede definir una implementaci�n privada del segundo VM,
que ser� llamada por el primer VM cuando sea invocado en esa
plantilla. Ninguna de las otras templates es afectada.
</p>
<p>
<code>velocimacro.context.localscope</code> -
Con valores posibles verdadero y falso (true y false), valor por
defecto falso. Cuando es verdadera cualquier modificaci�n al
contexto por medio de un #set() dentro de un Velocimacro se
considera local a ese Velocimacro y no afecta permanentemente al
contexto.
</p>
<p>
<code>velocimacro.library.autoreload</code> - Esta propiedad
controla el cargado autom�tico de la libreria de Velocimacros. El
valor por defecto es <code>false</code>. Cuando es verdadero
(<code>true</code>) la librer�a fuente de un Velocimacro que ha sido
invocado ser� verificada para comprobar que no haya cambiado, y si
lo ha hecho ser� recargada. Esta caracter�stica le permite cambiar y
probar librer�as de macros sin necesidad de reiniciar la aplicaci�n
o el contenedor de servlets, de la misma manera que se hace con
plantillas normales.
Este modo solo funciona cuando el cach� esta <i>apagado</i>
en los cargadores de recursos( e.g. <code>file.resource.loader.cache
= false</code>).
Esta caracter�stica esta pensada para el proceso de desarrollo, no
el de producci�n.
This property
</p>
<strong>Cosas y Casos de Velocimacros</strong>
<p>
Actualmente los Velocimacros deben ser definidos antes de ser
utilizados por primera vez dentro de una plantilla. Esto significa
que sus declaraciones de #macro() deben aparecerantes de que usted
utilice los Velocimacros.
</p>
<p>
Esto es importante recordarlo cuando usted intenta hacerle #parse()
a una plantilla que contiene directivas #macro(). Como el #parse()
ocurre en tiempo de ejecuci�n, y el parser decide si un elemento que
parece una VM es realmente un VM cuando esta haciendo el #parse(),
entonces probablemente el #parse() de un conjunto de declaraciones
no funciona como se esperar�a. Para evitar este problema,
simplemente utilice la propiedad
<code>velocimacro.library</code>para cargar todos sus VM cuando se
inicie la aplicaci�n.
</p>
</blockquote>
</p>
</td></tr>
<tr><td><br/></td></tr>
</table>
<table border="0" cellspacing="0" cellpadding="2" width="100%">
<tr><td bgcolor="#525D76">
<font color="#ffffff" face="arial,helvetica,sanserif">
<a name="Escaping VTL Directives"><strong>Escaping VTL Directives</strong></a>
</font>
</td></tr>
<tr><td>
<blockquote>
<p>
Las directivas de VTL se pueden escapar con el palote invertido o
backslash ("\") de manera similar a como se escapan las referencias de
VTL v�lidas.
</p>
<div align="left">
<table cellspacing="4" cellpadding="0" border="0">
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#ffffff"><pre>
## #include( "a.txt" ) se muestra como <contenidos de a.txt>
#include( "a.txt" )
## \#include( "a.txt" ) se muestra como \#include( "a.txt" )
\#include( "a.txt" )
## \\#include ( "a.txt" ) se muestra como \<contenidos de a.txt>
\\#include ( "a.txt" )
</pre></td>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
</table>
</div>
<p>
Se debe tener especial cuidado cuando se escapan directivas de VTL que
contienen varios elementos de script en una misma directiva (como en las
sentencias if-else-end). A continuaci�n seencuentra un ejemplo de un
condicional t�pico de VTL:
</p>
<div align="left">
<table cellspacing="4" cellpadding="0" border="0">
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#ffffff"><pre>
#if( $jazz )
Vyacheslav Ganelin
#end
</pre></td>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
</table>
</div>
<p>
Si <em>$jazz</em> es cierto la salida es
</p>
<div align="left">
<table cellspacing="4" cellpadding="0" border="0">
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#ffffff"><pre>
Vyacheslav Ganelin
</pre></td>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
</table>
</div>
<p>
Si <em>$jazz</em> es fals, no hay salida. Escapar elementos de script
altera la salida. Considere el siguiente caso:
</p>
<div align="left">
<table cellspacing="4" cellpadding="0" border="0">
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#ffffff"><pre>
\#if( $jazz )
Vyacheslav Ganelin
\#end
</pre></td>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
</table>
</div>
<p>
Sin importar si <em>$jazz</em> es verdadero o falso, la salida ser�:
</p>
<div align="left">
<table cellspacing="4" cellpadding="0" border="0">
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#ffffff"><pre>
#if($ jazz )
Vyacheslav Ganelin
#end
</pre></td>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
</table>
</div>
<p>
De hecho, como todos los elementos de script est�n escapados,
<em>$jazz</em> nunca se eval�a por su valor booleano.
Suponga que los palotes invertidos preceden a elementos de script que
est�n legitimamente escapados:
</p>
<div align="left">
<table cellspacing="4" cellpadding="0" border="0">
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#ffffff"><pre>
\\#if( $jazz )
Vyacheslav Ganelin
\\#end
</pre></td>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
</table>
</div>
<p>
En este caso, si <em>$jazz</em> es verdadero, la salida es
</p>
<div align="left">
<table cellspacing="4" cellpadding="0" border="0">
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#ffffff"><pre>
\ Vyacheslav Ganelin
\
</pre></td>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
</table>
</div>
<p>
Para entender esto tenga en cuenta que <code>#if( arg )</code>, cuando
es terminado por un caracter de fin de l�nea (retorno) omitir� ese
caracter de la salida. Por lo tanto, el cuerpo del bloque
<code>#if()</code> va a continuaci�n del primer '\', que se gener� a
partir del '\\' que preced�a el <code>#if()</code> dentro de la
pantilla. El �ltimo \ est� en una l�nea distinta que el texto porqu� hay
un retorno despu�s de 'Ganelin', por lo que el \\ final, que precede el
<code>#end</code> hace parte del cuerpo del bloque.
</p>
<p>
Si <em>$jazz</em> es falso, no hay salida. Tenga en cuenta que las
cosas dejan de funcionar si los elementos de script no son escapados
de manera correcta.
</p>
<div align="left">
<table cellspacing="4" cellpadding="0" border="0">
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#ffffff"><pre>
\\\#if( $jazz )
Vyacheslave Ganelin
\\#end
</pre></td>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
</table>
</div>
<p>
Aqu� el <em>#if</em> esta escapado, pero hay un <em>#end</em> que
sobra; al haber demasiados cierres (end) sin sus correspondientes
aperturas (foreach � if) se generar� un error de procesamiento.
</p>
</blockquote>
</p>
</td></tr>
<tr><td><br/></td></tr>
</table>
<table border="0" cellspacing="0" cellpadding="2" width="100%">
<tr><td bgcolor="#525D76">
<font color="#ffffff" face="arial,helvetica,sanserif">
<a name="VTL: Formatting Issues"><strong>VTL: Formatting Issues</strong></a>
</font>
</td></tr>
<tr><td>
<blockquote>
<p>
A pesar de que el VTL mostrado en esta gu�a del usuario se muestra en la
mayor�a de los casos con cambios de l�nea y espacios en blanco, el VTL
que se muestra a continuaci�n
</p>
<div align="left">
<table cellspacing="4" cellpadding="0" border="0">
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#ffffff"><pre>
#set( $imperial = ["Munetaka","Koreyasu","Hisakira","Morikune"] )
#foreach( $shogun in $imperial )
$shogun
#end
</pre></td>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
</table>
</div>
<p>
es tan v�lido como el siguiente trozo de c�digo que Geir Magnusson Jr.
public� a la lista de correo de usuarios de Velocity para ilustrar un
punto sin ninguna relaci�n:
</p>
<div align="left">
<table cellspacing="4" cellpadding="0" border="0">
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#ffffff"><pre>
Enviame #set($foo = ["$10 y ","un pastel"])#foreach($a in $foo)$a #end
por favor.
</pre></td>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
</table>
</div>
<p>
El comportamiento de Velocity es el de ingnorar el espacio vac�o de
exceso. La directiva descrita anteriormente puede reescribirse como:
</p>
<div align="left">
<table cellspacing="4" cellpadding="0" border="0">
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#ffffff"><pre>
Enviame
#set( $foo = ["$10 y ","un pastel"] )
#foreach( $a in $foo )
$a
#end
por favor.
</pre></td>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
</table>
</div>
<p>
o como
</p>
<div align="left">
<table cellspacing="4" cellpadding="0" border="0">
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#ffffff"><pre>
Enviame
#set($foo = ["$10 y ","un pastel"])
#foreach ($a in $foo )$a
#end por favor.
</pre></td>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
</table>
</div>
<p>
En cada caso la salida ser� la misma
</p>
</blockquote>
</p>
</td></tr>
<tr><td><br/></td></tr>
</table>
<table border="0" cellspacing="0" cellpadding="2" width="100%">
<tr><td bgcolor="#525D76">
<font color="#ffffff" face="arial,helvetica,sanserif">
<a name="Other Features and Miscellany"><strong>Other Features and Miscellany</strong></a>
</font>
</td></tr>
<tr><td>
<blockquote>
<table border="0" cellspacing="0" cellpadding="2" width="100%">
<tr><td bgcolor="#828DA6">
<font color="#ffffff" face="arial,helvetica,sanserif">
<a name="Math"><strong>Math</strong></a>
</font>
</td></tr>
<tr><td>
<blockquote>
<p>
Velocity tiene varias funciones matem�ticas incluidas que pueden ser
utilizadas en plantillas con la directiva <em>set</em>. Las siguientes
ecuaciones son ejemplos de suma, resta, multiplicaci�n y divisi�n
respectivamente:
</p>
<div align="left">
<table cellspacing="4" cellpadding="0" border="0">
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#ffffff"><pre>
#set( $foo = $bar + 3 )
#set( $foo = $bar - 4 )
#set( $foo = $bar * 6 )
#set( $foo = $bar / 2 )
</pre></td>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
</table>
</div>
<p>
Cuando se realiza una divisi�n el resultado es un entero. El residuo se
puede obtener utilizando el operador m�dulo (<em>%</em>).
</p>
<div align="left">
<table cellspacing="4" cellpadding="0" border="0">
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#ffffff"><pre>
#set( $foo = $bar % 5 )
</pre></td>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
</table>
</div>
<p>
Solo los enteros (...-2, -1, 0, 1, 2...) son v�lidos cuando se realizan
operaciones matem�ticas en Velocity; cuando un no-entero se usa, se
escribe el dato al log y se retorna null como salida.
</p>
</blockquote>
</td></tr>
<tr><td><br/></td></tr>
</table>
<table border="0" cellspacing="0" cellpadding="2" width="100%">
<tr><td bgcolor="#828DA6">
<font color="#ffffff" face="arial,helvetica,sanserif">
<a name="Range Operator"><strong>Range Operator</strong></a>
</font>
</td></tr>
<tr><td>
<blockquote>
<p>
El operador de rango se puede usar en conjunci�n con las directivas
<em>#set</em> y <em>#foreach</em>. Es muy �til por su capacidad para
crear arreglos de objetos compuestos por enteros. La construcci�n del
operador rango es como sigue:
</p>
<div align="left">
<table cellspacing="4" cellpadding="0" border="0">
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#ffffff"><pre>
[n..m]
</pre></td>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
</table>
</div>
<p>
Tanto <em>n</em> como <em>m</em> debe ser o producir enteros. El hecho
de que <em>m</em> sea mayor o menor que <em>n</em> no importa; en ese
caso el rango cimplemente contar� hac�a abajo. A continuaci�n se
muestran varios ejemplos de uso del operador rango:
</p>
<div align="left">
<table cellspacing="4" cellpadding="0" border="0">
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#ffffff"><pre>
Primer ejemplo:
#foreach( $foo in [1..5] )
$foo
#end
Segundo ejemplo:
#foreach( $bar in [2..-2] )
$bar
#end
Tercer ejemplo:
#set( $arr = [0..1] )
#foreach( $i in $arr )
$i
#end
Cuarto ejemplo:
[1..3]
</pre></td>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
</table>
</div>
<p>
Produce lo siguiente:
</p>
<div align="left">
<table cellspacing="4" cellpadding="0" border="0">
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#ffffff"><pre>
Primer ejemplo:
1 2 3 4 5
Segundo ejemplo:
2 1 0 -1 -2
Tercer ejemplo:
0 1
Cuarto ejemplo:
[1..3]
</pre></td>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
</table>
</div>
<p>
enga en cuenta que el operador de rango solamente produce un arreglo
cuando se utiliza junto con las directivas <em>#set</em> y
<em>#foreach</em>, como se demuestra en el cuarto ejemplo.
</p>
<p>
Los dise�adores de p�ginas preocupados con hacer los tama�os de las
tablas iguales, pero con informaci�n que puede no se suficiente para
llenar la tabla, encontrar�n el operador de rango particularmente �til.
</p>
</blockquote>
</td></tr>
<tr><td><br/></td></tr>
</table>
<table border="0" cellspacing="0" cellpadding="2" width="100%">
<tr><td bgcolor="#828DA6">
<font color="#ffffff" face="arial,helvetica,sanserif">
<a name="Advanced Issues: Escaping and !"><strong>Advanced Issues: Escaping and !</strong></a>
</font>
</td></tr>
<tr><td>
<blockquote>
<p>
Cuando una referencia se hace silenciona con el caracter <em>!</em> y el
caracter <em>!</em> viene precedido por un caracter de escape
<em>\</em> la referencia se maneja de una manera diferente. Observe las
diferencias entre el escape sencillo y el caso especial en el que
<em>\</em> precede a <em>!</em>:
</p>
<div align="left">
<table cellspacing="4" cellpadding="0" border="0">
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#ffffff"><pre>
#set( $foo = "bar" )
$\!foo
$\!{foo}
$\\!foo
$\\\!foo
</pre></td>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
</table>
</div>
<p>
Se muestra como:
</p>
<div align="left">
<table cellspacing="4" cellpadding="0" border="0">
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#ffffff"><pre>
$!foo
$!{foo}
$\!foo
$\\!foo
</pre></td>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
</table>
</div>
<p>
A diferencia del escape normal, donde <em>\</em> precede a <em>$</em>:
</p>
<div align="left">
<table cellspacing="4" cellpadding="0" border="0">
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#ffffff"><pre>
\$foo
\$!foo
\$!{foo}
\\$!{foo}
</pre></td>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
</table>
</div>
<p>
Se muestra como:
</p>
<div align="left">
<table cellspacing="4" cellpadding="0" border="0">
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#ffffff"><pre>
\$foo
\$!foo
\$!{foo}
\bar
</pre></td>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
</table>
</div>
</blockquote>
</td></tr>
<tr><td><br/></td></tr>
</table>
<table border="0" cellspacing="0" cellpadding="2" width="100%">
<tr><td bgcolor="#828DA6">
<font color="#ffffff" face="arial,helvetica,sanserif">
<a name="Velocimacro Miscellany"><strong>Velocimacro Miscellany</strong></a>
</font>
</td></tr>
<tr><td>
<blockquote>
<p>
Esta secci�n contiene un conjunto de preguntas frecuentes (FAQ)
relacionadas con Velocimacros. Esta secci�n cambiar� con el tiempo, por
lo que es bueno revisar si hay informaci�n nueva de cuando en cuando.
</p>
<p>
Nota : A trav�s de esta secci�n 'Velocimacro' ser� abreviado como 'VM'.
</p>
<strong>�Puedo usar una directiva u otro VM como argumento para un VM?</strong>
<p>
Ejemplo : <code>#center( #bold("hola") )</code>
</p>
<p>
No. Una directiva no es un argumento v�lido para una directiva y, para
la mayor�a de los prop�sitos pr�cticos, un VM es una directiva.
</p>
<p>
<i>Sin embargo...</i>, hay cosas que usted puede hacer. Una soluci�n
sencilla es aprovechar el hecho de que la doble comilla (") muestra sus
contenidos, por lo que usted puede hacer algo como
</p>
<div align="left">
<table cellspacing="4" cellpadding="0" border="0">
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#ffffff"><pre>
#set($cosas = "#bold('hola')" )
#center( $cosas )
</pre></td>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
</table>
</div>
<p>
Puede tener un paso...
</p>
<div align="left">
<table cellspacing="4" cellpadding="0" border="0">
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#ffffff"><pre>
#center( "#bold( 'hola' )" )
</pre></td>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
</table>
</div>
<p>
Tenga en cuenta que en segundo ejemplo el argumentos es evaluado <i>
dentro</i> de la VM, no a nivel del llamador. En otras palabras, el
argumento para el VM es pasado completo y evaluado dentro del VM al que
se le pasa. Esto le permite hacer cosas como :
</p>
<div align="left">
<table cellspacing="4" cellpadding="0" border="0">
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#ffffff"><pre>
#macro( interno $foo )
interno : $foo
#end
#macro( externo $foo )
#set($bar = "externolala")
externo : $foo
#end
#set($bar = 'calltimelala')
#externo( "#interno($bar)" )
</pre></td>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
</table>
</div>
<p>
Donde la salida es
</p>
<div align="left">
<table cellspacing="4" cellpadding="0" border="0">
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#ffffff"><pre>
externo : interno : externolala
</pre></td>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
</table>
</div>
<p>
la evaluaci�n de "#interno($bar)" se lleva a cabo dentro de #externo(),
por lo que el valor $bar establecido dentro de #externo() es el que se
utiliza.
</p>
<p>
Estas es una caracter�stica intencional y celosamente protegina - los
argumentos se pasan por nombre a los VM para que usted le pueda
'entregar' a los VMs referencias con estado como
</p>
<div align="left">
<table cellspacing="4" cellpadding="0" border="0">
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#ffffff"><pre>
#macro( foo $color )
<tr bgcolor=$color><td>Hola</td></tr>
<tr bgcolor=$color><td>Todos</td></tr>
#end
#foo( $bar.colorFila() )
</pre></td>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
</table>
</div>
<p>
Y lograr que colorFila() se llame varias veces, en lugar de solo una.
Par evitar que eso ocurra invoque el m�todo fuera del VM y p�sele el
valor al VM.
</p>
<div align="left">
<table cellspacing="4" cellpadding="0" border="0">
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#ffffff"><pre>
#set($color = $bar.colorFila())
#foo( $color )
</pre></td>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
</table>
</div>
<strong>�Puedo registrar Velocimacros por medio de #parse() ? </strong>
<p>
Actualmente, los Velocimacros deben ser definidos antes de ser usados
por primera vez dentro de una plantilla. Esto significa que sus
declaraciones de #macro() deben venir antes de que usted use los
Velocimacros.
</p>
<p>
Esto es importante recordarlo cuando usted intenta hacerle #parse()
a una plantilla que contiene directivas #macro(). Como el #parse()
ocurre en tiempo de ejecuci�n, y el parser decide si un elemento que
parece una VM es realmente un VM cuando esta haciendo el #parse(),
entonces probablemente el #parse() de un conjunto de declaraciones
no funciona como se esperar�a. Para evitar este problema,
simplemente utilice la propiedad
<code>velocimacro.library</code>para cargar todos sus VM cuando se
inicie la aplicaci�n.
</p>
<strong>�Qu� es la auto recarga de Velocimacros?</strong>
<p>
Existe una propiedad, pensada para usarse en <i>desarrollo</i>, no
en producci�n :
</p>
<p>
<code>velocimacro.library.autoreload</code>
</p>
<p>
que tiene como valor por defecto falso. Cuando se hace verdadera
<em>junto con</em> <code><tipo>.resource.loader.cache = false</code>
(where <tipo> es el nombre del cargador de recursos que usted
esta utilizando, como 'file' para archivos) entonces el motor de
Velocity recargar� autom�ticamente los cambios en su librer�as en el
momento en que los haga para que usted no tenga que reinicar el motor
de servlets o la aplicaci�n, o hacer otros trucos para lograr que sus
Velocimacros se recarguen.
</p>
<p>
A continuaci�n se muestra un conjunto sencillo de propiedades de
configuraci�n.
</p>
<div align="left">
<table cellspacing="4" cellpadding="0" border="0">
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#ffffff"><pre>
file.resource.loader.path = templates
file.resource.loader.cache = false
velocimacro.library.autoreload = true
</pre></td>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
</table>
</div>
<p>No utilice esto en producci�n</p>
</blockquote>
</td></tr>
<tr><td><br/></td></tr>
</table>
<table border="0" cellspacing="0" cellpadding="2" width="100%">
<tr><td bgcolor="#828DA6">
<font color="#ffffff" face="arial,helvetica,sanserif">
<a name="String Concatenation"><strong>String Concatenation</strong></a>
</font>
</td></tr>
<tr><td>
<blockquote>
<p>
Una pregunta com�n que los desarrolladores formulan es <i>�C�mo
concateno cadenas de caracteres? �Existe alg�n an�logo al operador
'+' en Java?</i>
</p>
<p>
Para concatenar referencias en VTL usted solo tiene que 'ponerlos
juntos'. El contenido del contexto en donde usted desee juntar las
referencias es importante, por lo que ilustraremos con algunos
ejemplos.
</p>
<p>
En el c�digo regular de una plantilla (cuando usted lo mezcla con
contenido normal)
</p>
<div align="left">
<table cellspacing="4" cellpadding="0" border="0">
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#ffffff"><pre>
#set( $tam = "Big" )
#set( $nombre = "Ben" )
El reloj es $tam$nombre.
</pre></td>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
</table>
</div>
<p>
y la salida ser� 'El reloj es BigBen'. Para caso m�s interesantes,
como cuando ested desea concatenar las cadenas que pasar� a un
m�todo, o establecer el valor de una nueva referencia use
</p>
<div align="left">
<table cellspacing="4" cellpadding="0" border="0">
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#ffffff"><pre>
#set( $tam = "Big" )
#set( $nombre = "Ben" )
#set($reloj = "$tam$nombre" )
El reloj es $reloj.
</pre></td>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
</table>
</div>
<p>
Que resultar� en la mismo que el ejemplo anterior. Como un ejemplo
final, cuando usted desea mezclar cadenas 'est�ticas' con sus
referencias usted puede necesitar 'referencias formales':
</p>
<div align="left">
<table cellspacing="4" cellpadding="0" border="0">
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#ffffff"><pre>
#set( $tam = "Big" )
#set( $nombre = "Ben" )
#set($reloj = "${tam}Alto$nombre" )
El reloj es $reloj.
</pre></td>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
</table>
</div>
<p>
Ahora el resultado es 'El reloj es BigAltoBen'. La notaci�n formal
es necesaria para que el procesador de las plantillas sepa que usted
quiso usar la referencia '$tam', en lugar de '$tamAlto', que ser�a
lo que entender�a si los corchetes '{}' no estuvieran presentes.
</p>
</blockquote>
</td></tr>
<tr><td><br/></td></tr>
</table>
</blockquote>
</p>
</td></tr>
<tr><td><br/></td></tr>
</table>
<table border="0" cellspacing="0" cellpadding="2" width="100%">
<tr><td bgcolor="#525D76">
<font color="#ffffff" face="arial,helvetica,sanserif">
<a name="Feedback"><strong>Feedback</strong></a>
</font>
</td></tr>
<tr><td>
<blockquote>
<p>
Si encuentra alg�n error en este manual o tiene alg�n otro comentario o
retroalimentaci�n relacionada con la gu�a del usuario de Velocity, por
favor envie un correo a <a href="mailto:velocity-user@jakarta.apache.org">La lista de usuarios
de Velocity</a>.
Gracias!
</p>
</blockquote>
</p>
</td></tr>
<tr><td><br/></td></tr>
</table>
</td>
</tr>
<!-- FOOTER -->
<tr><td colspan="2">
<hr noshade="" size="1"/>
</td></tr>
<tr><td colspan="2">
<div align="center"><font color="#525D76" size="-1"><em>
Copyright © 1999-2002, Apache Software Foundation
</em></font></div>
</td></tr>
</table>
</body>
</html>
<!-- end the processing -->
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>