<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Desarrollo en Web &#187; Frameworks</title>
	<atom:link href="http://blogs.antartec.com/desarrolloweb/category/frameworks/feed/" rel="self" type="application/rss+xml" />
	<link>http://blogs.antartec.com/desarrolloweb</link>
	<description>Blog sobre desarrollo de aplicaciones web en Java, Python y JavaScript</description>
	<lastBuildDate>Thu, 06 Jan 2011 19:33:19 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>JQuery API browser</title>
		<link>http://blogs.antartec.com/desarrolloweb/2010/05/jquery-api-browser/</link>
		<comments>http://blogs.antartec.com/desarrolloweb/2010/05/jquery-api-browser/#comments</comments>
		<pubDate>Wed, 05 May 2010 20:41:58 +0000</pubDate>
		<dc:creator>Giancarlo Corzo</dc:creator>
				<category><![CDATA[Frameworks]]></category>
		<category><![CDATA[Programación]]></category>
		<category><![CDATA[documentación]]></category>
		<category><![CDATA[jquery]]></category>

		<guid isPermaLink="false">http://blogs.antartec.com/desarrolloweb/?p=333</guid>
		<description><![CDATA[
			
				
			
		
Uno de los aspectos más importantes para dominar y hacer uso de una tecnología es tener acceso a buena documentación. En el caso específico de la librería JQuery se cuenta con gran cantidad de información disponible en su sitio web, además de recursos de programadores con ejemplos prácticos de uso.
Sin embargo, la documentación oficial de [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fblogs.antartec.com%2Fdesarrolloweb%2F2010%2F05%2Fjquery-api-browser%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fblogs.antartec.com%2Fdesarrolloweb%2F2010%2F05%2Fjquery-api-browser%2F&amp;source=antartec&amp;style=normal&amp;service=bit.ly" height="61" width="50" /><br />
			</a>
		</div>
<p>Uno de los aspectos más importantes para dominar y hacer uso de una tecnología es tener acceso a buena documentación. En el caso específico de la librería JQuery se cuenta con gran cantidad de información disponible en su sitio web, además de recursos de programadores con ejemplos prácticos de uso.</p>
<p>Sin embargo, la <a href="http://api.jquery.com/">documentación oficial de la herramienta</a> es presentada en páginas independientes, por lo que navegar a través de ellas buscando información específica resulta complicado. Es por ello que quiero compartirles una utilidad que permite encontrar rápidamente mayores detalles de cualquier función de JQuery.</p>
<p><a href="http://blogs.antartec.com/desarrolloweb/files/2010/05/Pantallazo-jQuery-API-Browser-v1.3-Mozilla-Firefox.png"><img src="http://blogs.antartec.com/desarrolloweb/files/2010/05/Pantallazo-jQuery-API-Browser-v1.3-Mozilla-Firefox-300x169.png" alt="Pantallazo-jQuery API Browser v1.3" title="Pantallazo-jQuery API Browser v1.3" width="300" height="169" class="aligncenter size-medium wp-image-337" /></a></p>
<p>La herramienta, <a href="http://api.jquery.com/browser/">JQuery API browser</a> es accesible de dos maneras: la primera es mediante la aplicación web que utiliza una interfaz AJAX para saltar entre funciones de la librería y la segunda mediante una aplicación de escritorio basada en Adobe Air.</p>
<p>Espero la disfruten tanto como yo lo he hecho.</p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.antartec.com/desarrolloweb/2010/05/jquery-api-browser/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Usando JQuery Dialog con IFrame</title>
		<link>http://blogs.antartec.com/desarrolloweb/2010/05/usando-jquery-dialog-con-iframe/</link>
		<comments>http://blogs.antartec.com/desarrolloweb/2010/05/usando-jquery-dialog-con-iframe/#comments</comments>
		<pubDate>Mon, 03 May 2010 22:58:32 +0000</pubDate>
		<dc:creator>Giancarlo Corzo</dc:creator>
				<category><![CDATA[Frameworks]]></category>
		<category><![CDATA[Programación]]></category>
		<category><![CDATA[jdialog]]></category>
		<category><![CDATA[jquery]]></category>

		<guid isPermaLink="false">http://blogs.antartec.com/desarrolloweb/?p=314</guid>
		<description><![CDATA[
			
				
			
		
JQuery es una excelente librería JavaScript que simplifica la manipulación del DOM (Document Object Model) de una página HTML, el manejo de eventos, animaciones y AJAX. Así también, desde hace un tiempo atrás provee una librería de componentes UI que extiende los componentes iniciales de esta librería. 
El widget de tipo diálogo es un ventana [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fblogs.antartec.com%2Fdesarrolloweb%2F2010%2F05%2Fusando-jquery-dialog-con-iframe%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fblogs.antartec.com%2Fdesarrolloweb%2F2010%2F05%2Fusando-jquery-dialog-con-iframe%2F&amp;source=antartec&amp;style=normal&amp;service=bit.ly" height="61" width="50" /><br />
			</a>
		</div>
<p><a href="http://www.jquery.com">JQuery</a> es una excelente librería JavaScript que simplifica la manipulación del DOM (Document Object Model) de una página HTML, el manejo de eventos, animaciones y AJAX. Así también, desde hace un tiempo atrás provee una librería de <a href="http://jqueryui.com/home">componentes UI</a> que extiende los componentes iniciales de esta librería. </p>
<p>El widget de tipo diálogo es un ventana flotante que tiene un título y contenido (similar a un popup). Este widget resulta ser muy útil para mostrar alertas o formularios que el usuario debe llenar antes de poder con﻿tinuar.  Veamos como lograr lanzar un dialog apenas carga la página</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;script</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;text/javascript&quot;</span> <span style="color: #000066;">src</span>=<span style="color: #ff0000;">&quot;/assets/javascript/jquery-1.4.min.js&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span><span style="color: #000000; font-weight: bold;">&lt;/script<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;script</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;text/javascript&quot;</span> <span style="color: #000066;">src</span>=<span style="color: #ff0000;">&quot;/assets/javascript/jquery-ui-1.8.custom.min.js&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span><span style="color: #000000; font-weight: bold;">&lt;/script<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;script</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;text/javascript&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
&nbsp;
$(function() {
 $(&quot;#dialog&quot;).dialog();
});
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/script<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;div</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;dialog&quot;</span> <span style="color: #000066;">title</span>=<span style="color: #ff0000;">&quot;Basic dialog&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;p<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>This is the default dialog which is useful for displaying information. The dialog window can be moved, resized and closed with the 'x' icon.<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/p<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/div<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p><em>Ejemplo tomado de la página web de Jquery</em><br />
<br />Como puede apreciarse en el código anterior, esta es una solución muy sencilla para hacer un widget dialog; sin embargo, cuando se desarrolla un sistema de mayor complejidad lo ideal es separar las ventanas en múltiples archivos y los diálogos no son la excepción.  Una implementación bastante difundida en la web es utilizar un elemento iframe en vez de una etiqueta div para construir el contenido del diálogo. Veamos un ejemplo para que quede más clara la idea.</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;script</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;text/javascript&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
&nbsp;
$(function() {
        $('a.showPopup').click(function(e) {
            e.preventDefault();
            var $this = $(this);
            var horizontalPadding = 15;
            var verticalPadding = 15;
            $('<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;iframe</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;site&quot;</span> <span style="color: #000066;">src</span>=<span style="color: #ff0000;">&quot;' + this.href + '&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>').dialog({
                title: ($this.attr('title')) ? $this.attr('title') : 'Site',
                autoOpen: true,
                width: 600,
                height: 300,
                modal: true,
                resizable: false,
                autoResize: true,
                overlay: {
                    opacity: 0.5,
                    background: &quot;black&quot;
                }
            }).width(600 - horizontalPadding).height(300 - verticalPadding);
        });
});
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/script<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;a</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;showPopup&quot;</span> <span style="color: #000066;">href</span>=<span style="color: #ff0000;">&quot;http://www.google.com&quot;</span> <span style="color: #000066;">title</span>=<span style="color: #ff0000;">&quot;Google&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span></pre></div></div>

<p>Como puede apreciarse en el ejemplo anterior, se utiliza un pseudo iframe, al cual le asignamos la dirección con el contenido que queremos mostrar en el diálogo.  Algunas posibles mejoras a esta idea inicial sería crear una función que permita reutilizar el código en otros enlaces, pero eso se los dejo como tarea.</p>
<p>EDIT:<br />
Respondiendo aun pregunta realizada por un lector estoy agregando una manera de cerrar el diálogo desde el iframe mismo:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;script</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;text/javascript&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
var refDialog;
$(function() {
...
refDialog = $('<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;iframe</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;site&quot;</span> <span style="color: #000066;">src</span>=<span style="color: #ff0000;">&quot;' + this.href + '&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>').dialog(...);
...
});
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/script<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>Dentro del iFrame colocar un link de la siguiente manera:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;a</span> <span style="color: #000066;">href</span>=<span style="color: #ff0000;">&quot;javascript:void(0);&quot;</span> <span style="color: #000066;">onclick</span>=<span style="color: #ff0000;">&quot;window.parent.refDialog.dialog('close');&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>close<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/a<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://blogs.antartec.com/desarrolloweb/2010/05/usando-jquery-dialog-con-iframe/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Primeras Impresiones de Django</title>
		<link>http://blogs.antartec.com/desarrolloweb/2010/03/primeras-impresiones-de-django/</link>
		<comments>http://blogs.antartec.com/desarrolloweb/2010/03/primeras-impresiones-de-django/#comments</comments>
		<pubDate>Mon, 29 Mar 2010 19:20:50 +0000</pubDate>
		<dc:creator>Pablo Torres Navarrete</dc:creator>
				<category><![CDATA[Frameworks]]></category>
		<category><![CDATA[Programación]]></category>
		<category><![CDATA[django]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://blogs.antartec.com/desarrolloweb/?p=295</guid>
		<description><![CDATA[
			
				
			
		
Hace poco empezamos a probar Django, uno de los frameworks web más populares para el lenguaje Python. Nos gustaría compartir las características que nos han parecido impresionantes y algunas que no nos han gustado.
Lo más impresionante: el sitio de administración
El “admin site”, como le llaman los Djangonautas, es más que un simple scaffolding para el [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fblogs.antartec.com%2Fdesarrolloweb%2F2010%2F03%2Fprimeras-impresiones-de-django%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fblogs.antartec.com%2Fdesarrolloweb%2F2010%2F03%2Fprimeras-impresiones-de-django%2F&amp;source=antartec&amp;style=normal&amp;service=bit.ly" height="61" width="50" /><br />
			</a>
		</div>
<p>Hace poco empezamos a probar <a href="http://www.djangoproject.com/">Django</a>, uno de los frameworks web más populares para el lenguaje <a href="http://python.org/">Python</a>. Nos gustaría compartir las características que nos han parecido impresionantes y algunas que no nos han gustado.</p>
<p><strong>Lo más impresionante: el sitio de administración</strong></p>
<p>El “admin site”, como le llaman los Djangonautas, es más que un simple scaffolding para el back-end, puesto que construye una interfaz más avanzada.</p>
<p>Django puede deducir información de los modelos para generar automáticamente las páginas de administración de los objetos de negocio, desde donde se realizan todas las operaciones sobre base de datos: lectura, actualización, creación, eliminación, validación, relación con otros objetos, etc. Así, los usuarios administradores puedan agregar contenido al sitio y tenerla lista para mostrar a los clientes finales.</p>
<p><span id="more-295"></span>En unos pocos pasos, explicados en la <a href="http://docs.djangoproject.com/en/1.1/intro/tutorial02/">parte 2 del tutorial</a>, Django ofrece:</p>
<ul>
<li>El widget correcto a utilizar (combobox, textbox, textarea, etc) para cada campo del objeto de negocio en el formulario de creación y edición.</li>
<li>Atajos inteligentes para los campos: calendarios para las fechas, vínculos de &#8220;hoy&#8221; y &#8220;ahora&#8221; para fechas y horas.</li>
</ul>
<p style="text-align: center"><a href="http://blogs.antartec.com/desarrolloweb/files/2010/03/primeras_impresiones_de_Django-admin_formulario1.png"><img class="alignnone size-medium wp-image-303" title="primeras_impresiones_de_Django-admin_formulario" src="http://blogs.antartec.com/desarrolloweb/files/2010/03/primeras_impresiones_de_Django-admin_formulario1-275x300.png" alt="" width="275" height="300" /></a></p>
<p style="text-align: center"><em>Ejemplo de formulario, con validaciones (*)</em></p>
<ul>
<li>Listas desplegables para escoger objetos relacionados (a través de llaves foráneas), con un atajo especial para crear un nuevo objeto relacionado en una ventana pop-up en caso éste no exista todavía.</li>
<li>Validación de cada uno de los campos por tipo de dato y longitud.</li>
</ul>
<p style="text-align: center"><a href="http://blogs.antartec.com/desarrolloweb/files/2010/03/primeras_impresiones_de_Django-admin_busqueda.png"><img class="alignnone size-medium wp-image-304" title="primeras_impresiones_de_Django-admin_busqueda" src="http://blogs.antartec.com/desarrolloweb/files/2010/03/primeras_impresiones_de_Django-admin_busqueda-300x101.png" alt="" width="300" height="101" /></a></p>
<p style="text-align: center"><em>Ejemplo de filtros y campos de búsqueda (*)</em></p>
<ul>
<li>Filtros y criterios de búsqueda para cada objeto, con vínculos de &#8220;último mes&#8221; y &#8220;última semana&#8221; para buscar por fecha</li>
<li>Acciones en masa: seleccionar varios objetos y borrarlos a la vez, cambiarles de estado o cualquier acción definida por el programador</li>
<li>Historial de acciones por cada usuario</li>
</ul>
<p style="text-align: center"><a href="http://blogs.antartec.com/desarrolloweb/files/2010/03/primeras_impresiones_de_Django-admin_roles.png"><img class="alignnone size-medium wp-image-299" title="primeras_impresiones_de_Django-admin_roles" src="http://blogs.antartec.com/desarrolloweb/files/2010/03/primeras_impresiones_de_Django-admin_roles-300x153.png" alt="" width="300" height="153" /></a></p>
<p style="text-align: center"><em>Ejemplo de usuarios, perfiles y roles</em></p>
<ul>
<li>Administración de usuarios, incluyendo perfiles y roles</li>
</ul>
<p>Una lista bastante larga para un sitio generado automáticamente, ¿no es verdad?</p>
<p>Así, Django nos salva de la tediosa pero infaltable tarea de programar el back-end. Con unas pocas líneas de código, se obtienen páginas listas para mostrar en producción.</p>
<p><em>(*) Imágenes tomadas del tutorial oficial de Django.</em></p>
<p><strong>Lo más decepcionante: necesitamos migraciones, ¡urgente!</strong></p>
<p>En Django, un cambio en los modelos no implica un cambio en la base de datos; es decir, el comando &#8217;syncdb&#8217; sólo puede crear tablas, pero no alterar las antiguas.</p>
<p>Los modelos suelen evolucionar con el tiempo, porque cambian los requerimientos o simplemente notamos un error: falta o sobra un campo, o se necesita una tabla extra y una llave foránea. Django no ofrece ningún soporte para estos casos, así que uno se ve obligado a modificar el esquema escribiendo las sentencias SQL a mano. Esto es inconcebible por las siguientes razones:</p>
<ol>
<li>Algunos de los casos mencionados podrían implicar pérdida o inconsistencia de datos. Es responsabilidad del framework estar alerta de estos errores y proteger al desarrollador de ellos, especialmente si se trata de un tema tan sensible.</li>
<li>Cada motor de base de datos maneja su propia versión de SQL, así que una modificación manual no serviría universalmente.</li>
<li>Una de las tareas de un framework es esconder el lenguaje SQL (es por esto que existen los ORMs).</li>
<li>Django debería ser capaz de manejar al menos los casos más sencillos, como agregar una columna.</li>
</ol>
<p>En <a href="http://rubyonrails.org/">Ruby on Rails</a>, el framework web más popular para el lenguaje <a href="http://www.ruby-lang.org/en/">Ruby</a>, existe el concepto de &#8220;<a href="http://guides.rubyonrails.org/migrations.html">migración</a>&#8220;: es posible manipular el esquema de datos a través de código en Ruby, ya sea para crear tablas, agregar columnas o insertar datos. Esta facilidad ofrece muchas ventajas:</p>
<ol>
<li>Abstracción del lenguaje SQL; es decir, una migración es útil inclusive si se usan distintos motores de bases de datos (por ejemplo, uno ligero para desarrollo y uno más potente para producción, o si la aplicación se desplegó en más de un entorno, cada uno con sus requerimientos sobre bases de datos).</li>
<li>Disponibilidad universal, puesto que las migraciones son archivos que se almacenan en el directorio del proyecto, así que cualquier desarrollador puede acceder a ellas (a través del repositorio) y mantener sincronizada su copia local.</li>
<li>Uso automatizado, puesto que las migraciones son código fuente ejecutable. Esto no es posible si se usara un gestor gráfico para interactuar con la base de datos.</li>
<li>Historial de versiones de la base de datos, puesto que se crea una migración por cada transacción. Así, es posible deshacer o aplicar un conjunto de cambios sobre la base de datos, lo que equivale a mantener el esquema de datos bajo control de versiones (repositorio). Esto no es posible si se usara un gestor gráfico.</li>
</ol>
<p style="text-align: center"><a href="http://blogs.antartec.com/desarrolloweb/files/2010/03/primeras_impresiones_de_DJango-migracion.png"><img class="size-medium wp-image-296 aligncenter" title="primeras_impresiones_de_DJango-migracion" src="http://blogs.antartec.com/desarrolloweb/files/2010/03/primeras_impresiones_de_DJango-migracion-300x187.png" alt="" width="300" height="187" /></a></p>
<p style="text-align: center"><em>Migración para crear una tabla</em></p>
<p>Django necesita algo similar con urgencia. Por el momento, lo más recomendable es comenzar a utilizar el sitio de administración inmediatamente después de definir los modelos, para poder notar errores lo antes posible y no tener que lidiar con la evolución del esquema. Naturalmente, los desarrolladores de Django ya han comenzado a discutir opciones para salvar este error.</p>
<p><strong>Conclusión</strong></p>
<p>Django es un framework que ofrece muchas abstracciones de alto nivel que simplifican enormemente la tarea del desarrollo web. El ejemplo más claro es la generación automática del back-end, que ahorra muchas horas de labor tediosa.</p>
<p>La documentación es excelente. La curva de aprendizaje de Django es muy baja gracias a la cantidad de información disponible acerca de él, muy bien redactada y muy completa.</p>
<p>El manejo del esquema de la base de datos es un señor problema. A menos que uno sea un experto en SQL (cosa que la &#8220;mala&#8221; costumbre de los ORMs hace improbable), seguro se tendrán problemas al hacer cambios a las tablas, inclusive cambios sencillos.</p>
<p><strong>Fuentes</strong></p>
<ul>
<li><a href="http://docs.djangoproject.com/en/dev/intro/tutorial01/">Tutorial oficial de Django </a></li>
<li><a href="http://docs.djangoproject.com/en/1.1/">Documentación oficial de Django </a></li>
<li><a href="http://code.djangoproject.com/wiki/SchemaEvolution">&#8220;Schema Evolution&#8221;, de la wiki de Django </a></li>
<li><a href="http://guides.rubyonrails.org/migrations.html">&#8220;Migrations&#8221;, de la documentación de Ruby on Rails</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://blogs.antartec.com/desarrolloweb/2010/03/primeras-impresiones-de-django/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Frameworks para iPhone</title>
		<link>http://blogs.antartec.com/desarrolloweb/2009/08/frameworks-para-iphone/</link>
		<comments>http://blogs.antartec.com/desarrolloweb/2009/08/frameworks-para-iphone/#comments</comments>
		<pubDate>Tue, 04 Aug 2009 14:41:04 +0000</pubDate>
		<dc:creator>Giancarlo Corzo</dc:creator>
				<category><![CDATA[Frameworks]]></category>
		<category><![CDATA[iphone]]></category>
		<category><![CDATA[jsf]]></category>
		<category><![CDATA[Seam]]></category>
		<category><![CDATA[ui]]></category>

		<guid isPermaLink="false">http://blogs.antartec.com/desarrolloweb/?p=223</guid>
		<description><![CDATA[
			
				
			
		
Hace algunas semanas en Antartec se nos encargó desarrollar una aplicación web piloto, ésto no tendría mucha novedad y/o relevancia como para escribir un post sobre ello, sin embargo el objetivo planteado lo hizo particularmente interesante.
El reto en esta aplicación fue desarrollar una web que se comporte como una aplicación nativa de iPhone y que le [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fblogs.antartec.com%2Fdesarrolloweb%2F2009%2F08%2Fframeworks-para-iphone%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fblogs.antartec.com%2Fdesarrolloweb%2F2009%2F08%2Fframeworks-para-iphone%2F&amp;source=antartec&amp;style=normal&amp;service=bit.ly" height="61" width="50" /><br />
			</a>
		</div>
<p>Hace algunas semanas en <a href="http://www.antartec.com">Antartec</a> se nos encargó desarrollar una aplicación web piloto, ésto no tendría mucha novedad y/o relevancia como para escribir un post sobre ello, sin embargo el objetivo planteado lo hizo particularmente interesante.</p>
<p>El reto en esta aplicación fue desarrollar una web que se comporte como una aplicación nativa de iPhone y que le permita a los usuarios ingresar información en tiempo real al sistema sin encontrarse frente a un computador.</p>
<p>Nuestros esfuerzos se concentraron en expandir nuestro actual framework basado en JSF y SEAM para que soporte el formato iPhone; nuestras investigaciones preliminares dieron frutos y encontramos varios frameworks para simular la apariencia de interfaces nativas en iPhone tales como <a href="http://code.google.com/p/iui">iUI</a> y <a href="http://code.google.com/p/iphone-universal/">UiUI (Universal)</a>.<br />
<span id="more-223"></span><br />
<a href="http://code.google.com/p/iui">iUI</a> desarrollado por Joe Hewitt es un framework bastante maduro que agiliza la construcción de aplicaciones al manejar las vistas, eventos, peticiones y estilos; sin embargo tiene algunas cosas que no son de mi agrado, como por ejemplo:</p>
<ul>
<li>Su funcionamiento está dado por el intercambio de vistas o pseudo páginas que se encuentran definidas en un solo documento HTML y mediante manipulación DOM se muestran o se ocultan, para el caso particular de cargar una vista dinámica ésta tiene que ser obtenida por AJAX y reemplazada en la vista apropiada (Ésto no tiene nada de malo pero no se ajusta 100% al ciclo de vida natural de JSF).</li>
<li>La simulación de las transiciones entre vistas que se utilizan en las aplicaciones nativas de iPhone se muestran con saltos bastante antinaturales, ésto se debe a que utiliza los efectos de CSS3 para realizar las transiciones. Es una lástima que en el Safari para  iPhone estas transiciones se vean bastante mal debido probablemente a la velocidad del procesador de video del equipo.</li>
<li>Para programar para iUI tienes que aprender la manera en que define vistas, cabeceras, botones etc. Para un proyecto corto, en donde no hay mucho tiempo para aprender, ésto se vuelve un impedimento mas que un beneficio (mi opinión es que mantener un esquema de programación conocido facilita la adopción de la tecnología).</li>
</ul>
<p><a href="http://code.google.com/p/iphone-universal/">iPhone Universal UI</a> fue otro framework que evaluamos. Desarrollado por Diego Lafuente, se basa en una serie de CSS que simulan la apariencia de las aplicaciones nativas.</p>
<p>Al respetar las convenciones web <a href="http://code.google.com/p/iphone-universal/">UiUI</a> se perfilaba como uno de los mejores prospectos para nuestro proyecto dado que podía ser adaptado fácilmente al desarrollo de aplicaciones JSF. Sin embargo, a mi modo de ver tiene una gran desventaja para que sea aceptado por las empresas, tiene una licencia GNU Affero General Public License (GNU AGPL 3) en vez de LGPL que no permite utilizarlo para proyectos con fines comerciales.</p>
<p>Dadas estas circunstancias, decidimos crear nuestro propio framework visual para iPhone que utilice todo el poder de los componentes JSF y el templating de Facelets. En una próxima entrega hablaremos más en profundidad sobre los pormenores del framework.</p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.antartec.com/desarrolloweb/2009/08/frameworks-para-iphone/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Uso de RichFaces tabPanel con JavaScript</title>
		<link>http://blogs.antartec.com/desarrolloweb/2009/04/uso-de-richfaces-tabpanel-con-javascript/</link>
		<comments>http://blogs.antartec.com/desarrolloweb/2009/04/uso-de-richfaces-tabpanel-con-javascript/#comments</comments>
		<pubDate>Tue, 07 Apr 2009 22:52:38 +0000</pubDate>
		<dc:creator>Otto Theo</dc:creator>
				<category><![CDATA[Frameworks]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[RichFaces]]></category>

		<guid isPermaLink="false">http://blogs.antartec.com/desarrolloweb/?p=132</guid>
		<description><![CDATA[
			
				
			
		
En esta ocasión trataré sobre el uso del componente tabPanel de RichFaces usándolo con funciones JavaScript para dos casos en particular:

Hacer el cambio de tabs.
Verificar si un tab está activo.

El tabPanel presenta 3 maneras para realizar el cambio de un tab a otro mediante el atributo switchType:

client (se carga la información de todos los tabs).
ajax [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fblogs.antartec.com%2Fdesarrolloweb%2F2009%2F04%2Fuso-de-richfaces-tabpanel-con-javascript%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fblogs.antartec.com%2Fdesarrolloweb%2F2009%2F04%2Fuso-de-richfaces-tabpanel-con-javascript%2F&amp;source=antartec&amp;style=normal&amp;service=bit.ly" height="61" width="50" /><br />
			</a>
		</div>
<p>En esta ocasión trataré sobre el uso del componente tabPanel de RichFaces usándolo con funciones JavaScript para dos casos en particular:</p>
<ul>
<li>Hacer el cambio de tabs.</li>
<li>Verificar si un tab está activo.</li>
</ul>
<p>El tabPanel presenta 3 maneras para realizar el cambio de un tab a otro mediante el atributo switchType:</p>
<ul>
<li><strong><em>client</em></strong> (se carga la información de todos los tabs).</li>
<li><strong><em>ajax</em></strong> (se carga la información mediante ajax, cada vez que se entra al tab).</li>
<li><strong><em>server</em></strong> (se carga la información cada vez que se entra al tab, actualizando toda la página).</li>
</ul>
<p><span id="more-132"></span><br />
Antes de comenzar, como nota importante, he probado esta forma de usar el tabPanel con las versiones <em><span style="text-decoration: underline">3.2.1</span></em> y la <em><span style="text-decoration: underline">3.3.0.GA</span><span style="font-style: normal"> de RichFaces.</span></em></p>
<p>Para todos los ejemplos utilizaré el código siguiente:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #ddbb00;">&amp;lt;</span>h:form id=&quot;miFormulario&quot; <span style="color: #ddbb00;">&amp;gt;</span>
&nbsp;
  <span style="color: #ddbb00;">&amp;lt;</span>!-- para los casos ajax y server switchType tendrá los valores 'ajax' y 'server' respectivamente --<span style="color: #ddbb00;">&amp;gt;</span>
  <span style="color: #ddbb00;">&amp;lt;</span>rich:tabPanel id=&quot;testTabPanel&quot; switchType=&quot;client&quot; <span style="color: #ddbb00;">&amp;gt;</span>
&nbsp;
    <span style="color: #ddbb00;">&amp;lt;</span>rich:tab id=&quot;tabUno&quot; label=&quot;Tab Uno&quot; <span style="color: #ddbb00;">&amp;gt;</span>
      <span style="color: #ddbb00;">&amp;lt;</span>!-- contenido del tab uno --<span style="color: #ddbb00;">&amp;gt;</span>
    <span style="color: #ddbb00;">&amp;lt;</span>/rich:tab<span style="color: #ddbb00;">&amp;gt;</span>
&nbsp;
    <span style="color: #ddbb00;">&amp;lt;</span>rich:tab id=&quot;tabDos&quot; label=&quot;Tab Dos&quot; <span style="color: #ddbb00;">&amp;gt;</span>
      <span style="color: #ddbb00;">&amp;lt;</span>!-- contenido del tab dos --<span style="color: #ddbb00;">&amp;gt;</span>
    <span style="color: #ddbb00;">&amp;lt;</span>/rich:tab<span style="color: #ddbb00;">&amp;gt;</span>
&nbsp;
  <span style="color: #ddbb00;">&amp;lt;</span>/rich:tabPanel<span style="color: #ddbb00;">&amp;gt;</span>
&nbsp;
<span style="color: #ddbb00;">&amp;lt;</span>/h:form<span style="color: #ddbb00;">&amp;gt;</span></pre></div></div>

<p><strong>1. </strong><span style="text-decoration: underline"><strong>Cambio de tabs</strong></span><strong>:</strong></p>
<p>Para realizar el cambio de tabs, se obtendrá mediante JavaScript el elemento cuyo id tenga la foma &lt;id del tab&gt;_shifted, así:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> irAlTabUno<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #006600; font-style: italic;">// se obtiene el elemento:</span>
  <span style="color: #003366; font-weight: bold;">var</span> tabUno <span style="color: #339933;">=</span> document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'miFormulario:tabUno_shifted'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #006600; font-style: italic;">// esta es la línea que realizará el cambio de tab</span>
  <span style="color: #006600; font-style: italic;">// si el tab se encuentra activo entonces no hará nada:</span>
  tabUno.<span style="color: #660066;">onclick</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">function</span> irAlTabDos<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'miFormulario:tabDos_shifted'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">onclick</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>El &#8216;truco&#8217; es obtener mediante JavaScript el elemento correcto (al cual hacerle onclick), lo que hace RichFaces es crear un HTML &lt;table&gt; dentro de la celda que contiene la pestaña con el mismo id que le dimos al tab pero concatenándole &#8216;_shifted&#8217;.</p>
<p>Existe una manera en particular para hacer el cambio pero <span style="text-decoration: underline">sólo</span> si se encuentra en modo <span style="text-decoration: underline">&#8216;client&#8217;</span>, la cual es usando una de las funciones del archivo tabPanel.js de RichFaces:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> irAlTabUno<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  RichFaces.<span style="color: #660066;">switchTab</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'miFormulario:testTabPanel'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'miFormulario:tabUno'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'Tab Uno'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">function</span> irAlTabDos<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  RichFaces.<span style="color: #660066;">switchTab</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'miFormulario:testTabPanel'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'miFormulario:tabDos'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'Tab Dos'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>O usando <a href="http://blogs.antartec.com/desarrolloweb/2009/03/richelement-una-forma-de-obtener-componentes-jsf-sin-preocuparse-por-los-id/" target="_blank">rich:clientId()</a></p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> irAlTabUno<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  RichFaces.<span style="color: #660066;">switchTab</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#{rich:clientId('</span>testTabPanel<span style="color: #3366CC;">')}'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'#{rich:clientId('</span>tabUno<span style="color: #3366CC;">')}'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'Tab Uno'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">function</span> irAlTabDos<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  RichFaces.<span style="color: #660066;">switchTab</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#{rich:clientId('</span>testTabPanel<span style="color: #3366CC;">')}'</span> <span style="color: #339933;">,</span><span style="color: #3366CC;">'#{rich:clientId('</span>tabDos<span style="color: #3366CC;">')}'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'Tab Dos'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Donde la función <span style="color: #0000ff">RichFaces.switchTab()</span> recibe 3 parámetros: el id del tabPanel, el id del tab al cual queremos ir, y el label del mismo tab destino.</p>
<p><strong>2. </strong><span style="text-decoration: underline"><strong>Verificar si un tab está activo</strong></span><strong>:</strong></p>
<p>Aquí también usaremos una de las funciones del archivo tabPanel.js de RichFaces:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> estaActivoTabUno<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #000066; font-weight: bold;">return</span> RichFaces.<span style="color: #660066;">isTabActive</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'miFormulario:tabUno_lbl'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">function</span> estaActivoTabDos<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #000066; font-weight: bold;">return</span> RichFaces.<span style="color: #660066;">isTabActive</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'miFormulario:tabDos_lbl'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Igual que en el caso anterior de cambio de tabs, el &#8216;truco&#8217; es usar el HTML &lt;td&gt; que crea RichFaces con el mismo id que le dimos al tab pero concatenándole &#8216;_lbl&#8217;. Entonces llamamos a la función <span style="color: #0000ff">RichFaces.isTabActive()</span> que recibe como parámetro este id.</p>
<p><strong>Conclusión</strong><strong>:</strong></p>
<p>Normalmente cambiar de tab es tan sencillo como hacer clic en el tab al cual queremos cambiar, y conocer el tab activo se realiza mediante el atributo &#8217;selectedTab&#8217; del rich:tabPanel (con un backing bean de por medio). Por eso esta manera de hacer ambas cosas mediante JavaScript es para casos muy particulares como por ejemplo, verificar que no se realice el cambio de tabs sin antes haber validado/guardado la información de cada tab independiente (cada tab posee un formulario), previa pregunta de confirmación al usuario con un javascript:confirm(&#8216;&#8230;&#8217;).</p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.antartec.com/desarrolloweb/2009/04/uso-de-richfaces-tabpanel-con-javascript/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>rich:element una forma de obtener componentes jsf sin preocuparse por los id</title>
		<link>http://blogs.antartec.com/desarrolloweb/2009/03/richelement-una-forma-de-obtener-componentes-jsf-sin-preocuparse-por-los-id/</link>
		<comments>http://blogs.antartec.com/desarrolloweb/2009/03/richelement-una-forma-de-obtener-componentes-jsf-sin-preocuparse-por-los-id/#comments</comments>
		<pubDate>Wed, 04 Mar 2009 17:17:48 +0000</pubDate>
		<dc:creator>Giancarlo Corzo</dc:creator>
				<category><![CDATA[Frameworks]]></category>
		<category><![CDATA[rich faces jsf element]]></category>

		<guid isPermaLink="false">http://blogs.antartec.com/desarrolloweb/?p=121</guid>
		<description><![CDATA[
			
				
			
		
Cuando trabajamos con JSF tenemos que tener cuidado con los ids que asignamos a cada componente, dado que estos deben ser únicos.
JSF y otras librerías, para prevenir problemas en este sentido, siguen las siguientes reglas:

Cuando no se asigna un id de manera explícita a un elemento se le genera un client id único.
 A todos [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fblogs.antartec.com%2Fdesarrolloweb%2F2009%2F03%2Frichelement-una-forma-de-obtener-componentes-jsf-sin-preocuparse-por-los-id%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fblogs.antartec.com%2Fdesarrolloweb%2F2009%2F03%2Frichelement-una-forma-de-obtener-componentes-jsf-sin-preocuparse-por-los-id%2F&amp;source=antartec&amp;style=normal&amp;service=bit.ly" height="61" width="50" /><br />
			</a>
		</div>
<p>Cuando trabajamos con JSF tenemos que tener cuidado con los ids que asignamos a cada componente, dado que estos deben ser únicos.</p>
<p>JSF y otras librerías, para prevenir problemas en este sentido, siguen las siguientes reglas:</p>
<ol>
<li>Cuando no se asigna un id de manera explícita a un elemento se le genera un client id único.</li>
<li> A todos los client ids (autogenerados o fijos) le antepone los client ids de los componentes padres, por ejemplo un inputText que se encuentre dentro de un form tendría un client id de la siguiente forma: nombreForm:nombreInputText.</li>
<li>Componentes como a4j:repeat van incluso más alla,  generando client ids  con esta estructura nombreForm:nombreRepeat:indice:componente.</li>
</ol>
<p>Antes de la última versión de rich faces (<a href="http://www.jboss.org/jbossrichfaces/downloads/" target="_blank">http://www.jboss.org/jbossrichfaces/downloads/</a>) teníamos el problema de tener que estar pendientes de los client id, por ejemplo para obtener un elemento teníamos que escribir algo como esto:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span>“formName<span style="color: #339933;">:</span>elementName”<span style="color: #009900;">&#41;</span></pre></div></div>

<p>Sin embargo rich proporciona ahora 4 métodos muy interesantes para obtener referencias a los componentes desde javascript:</p>
<ul>
<li>rich:clientId(&#8216;id&#8217;) retorna el client id compuesto del componente JSF</li>
<li>rich:element(&#8216;id&#8217;) es una contracción de document.getElementById(#{rich:clientId(&#8216;id&#8217;)})</li>
<li>rich:component(&#8216;id&#8217;) es una contracción de #{rich:clientId(&#8216;id&#8217;)}.component</li>
<li>rich:findComponent(&#8216;id&#8217;) devuelve una instancia de UIComponent tomando el id como parámetro.</li>
</ul>
<p>Veamos un ejemplo:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span>script<span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;</span>
<span style="color: #003366; font-weight: bold;">function</span> getLinkAndDoClick<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
#<span style="color: #009900;">&#123;</span>rich<span style="color: #339933;">:</span>element<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'linkid'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#125;</span> .<span style="color: #660066;">onclick</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;/</span>script<span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span>h<span style="color: #339933;">:</span>form<span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;</span>
<span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span>a4j<span style="color: #339933;">:</span>commandLink id<span style="color: #339933;">=</span>”linkid” value<span style="color: #339933;">=</span>”Haz click aqui” action<span style="color: #339933;">=</span>”#<span style="color: #009900;">&#123;</span>somebean.<span style="color: #660066;">someAction</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#125;</span>”<span style="color: #339933;">/&amp;</span>gt<span style="color: #339933;">;</span>
<span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;/</span>h<span style="color: #339933;">:</span>form<span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;</span></pre></div></div>

<p>De esta manera se puede obtener referencias a los componentes JSF sin tener que estar preocupándose cómo sus client id son generados.</p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.antartec.com/desarrolloweb/2009/03/richelement-una-forma-de-obtener-componentes-jsf-sin-preocuparse-por-los-id/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Performance: Uso de @Create</title>
		<link>http://blogs.antartec.com/desarrolloweb/2009/02/seam_uso_de_create/</link>
		<comments>http://blogs.antartec.com/desarrolloweb/2009/02/seam_uso_de_create/#comments</comments>
		<pubDate>Fri, 13 Feb 2009 22:11:47 +0000</pubDate>
		<dc:creator>Giancarlo Corzo</dc:creator>
				<category><![CDATA[Arquitectura]]></category>
		<category><![CDATA[Frameworks]]></category>
		<category><![CDATA[Seam]]></category>

		<guid isPermaLink="false">http://blogs.antartec.com/desarrolloweb/?p=107</guid>
		<description><![CDATA[
			
				
			
		
En este post me gustaría hacer una pequeña contribución al post “Performance: ¿Por qué usar @Factory en vez de getters?” de Seam City sobre el uso de @Factory para la obtención de listas.

En el post se menciona que los valores obtenidos por EL no se guardan en cache y ésto es un problema sobre todo [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fblogs.antartec.com%2Fdesarrolloweb%2F2009%2F02%2Fseam_uso_de_create%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fblogs.antartec.com%2Fdesarrolloweb%2F2009%2F02%2Fseam_uso_de_create%2F&amp;source=antartec&amp;style=normal&amp;service=bit.ly" height="61" width="50" /><br />
			</a>
		</div>
<p>En este post me gustaría hacer una pequeña contribución al post <a href="http://seamcity.madeinxpain.com/archives/performance-%C2%BFpor-que-usar-factory-en-vez-de-getters" target="_blank">“Performance: ¿Por qué usar @Factory en vez de getters?”</a> de Seam City sobre el uso de @Factory para la obtención de listas.<br />
<span id="more-107"></span><br />
En el post se menciona que los valores obtenidos por EL no se guardan en cache y ésto es un problema sobre todo cuando se acceden a listas que son cargadas desde la base de datos.</p>
<p>Para resolver el problema el post plantea 2 opciones:</p>
<p>Por patrón de carga lazy loading</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">@<span style="color: #003399;">Name</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;userManager&quot;</span><span style="color: #009900;">&#41;</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> UserManager <span style="color: #009900;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">List</span> list<span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">List</span> getUserList<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">list</span> <span style="color: #339933;">==</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">list</span> <span style="color: #339933;">=</span> createUserList<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #000000; font-weight: bold;">return</span> list<span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Y una mejor manera utilizando las anotaciones @Out y @Factory</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> UserManager <span style="color: #009900;">&#123;</span>
&nbsp;
  @Factory<span style="color: #009900;">&#40;</span>value <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;userList&quot;</span>, scope <span style="color: #339933;">=</span> ScopeType.<span style="color: #006633;">PAGE</span><span style="color: #009900;">&#41;</span>
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">List</span> getUserList<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
     <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">list</span> <span style="color: #339933;">==</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
       <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">list</span> <span style="color: #339933;">=</span> createUserList<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
     <span style="color: #009900;">&#125;</span>
     <span style="color: #000000; font-weight: bold;">return</span> list<span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Sin embargo existe una tercera solución que es bastante más clara y sobre todo sigue la convención con respecto a la creación de objetos y es utilizar la anotación @Create</p>
<p>El código es el siguiente:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">&nbsp;
@<span style="color: #003399;">Name</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;userManager&quot;</span><span style="color: #009900;">&#41;</span>
@Scope<span style="color: #009900;">&#40;</span>ScopeType.<span style="color: #006633;">PAGE</span><span style="color: #009900;">&#41;</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> UserManager <span style="color: #000000; font-weight: bold;">implements</span> <span style="color: #003399;">Serializable</span> <span style="color: #009900;">&#123;</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">private</span> List<span style="color: #339933;">&lt;</span>User<span style="color: #339933;">&gt;</span> list<span style="color: #339933;">;</span>
&nbsp;
  @Create
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> loadInitData<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
     <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">list</span> <span style="color: #339933;">=</span> createList<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">public</span> List<span style="color: #339933;">&lt;</span>User<span style="color: #339933;">&gt;</span> getList<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">return</span> list<span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
   <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setList<span style="color: #009900;">&#40;</span>List<span style="color: #339933;">&lt;</span>User<span style="color: #339933;">&gt;</span> list<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
     <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">list</span> <span style="color: #339933;">=</span> list<span style="color: #339933;">;</span>
   <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>La anotación @Create nos permite declarar que un método se ejecute al momento que un componente es creado. Momento apropiado para cargar toda la información que sólo debe ser obtenida una vez.</p>
<p>La anotación @Scope(ScopeType.PAGE) nos permite establecer un contexto para el componente de seam, en este caso que el componente exista mientras la página esta activa. Se pueden utilizar otros contextos como por ejemplo Conversation o Session, sin embargo no es recomendable usar el contexto session a menos que sea estrictamente necesario pues sin una adecuada adminstración la memoria requerida por aplicación puede dispararse.</p>
<p><strong>A modo de conclusión</strong></p>
<p>Es una buena práctica centralizar la información de carga estática en un solo método y combinado con el scope Page mejor, pues el uso de memoria en el servidor es mínimo.</p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.antartec.com/desarrolloweb/2009/02/seam_uso_de_create/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Carga dinámica de combos usando JSF y richfaces</title>
		<link>http://blogs.antartec.com/desarrolloweb/2009/01/carga-dinamica-de-combos-usando-jsf-y-richfaces/</link>
		<comments>http://blogs.antartec.com/desarrolloweb/2009/01/carga-dinamica-de-combos-usando-jsf-y-richfaces/#comments</comments>
		<pubDate>Wed, 28 Jan 2009 22:36:59 +0000</pubDate>
		<dc:creator>Giancarlo Corzo</dc:creator>
				<category><![CDATA[Frameworks]]></category>
		<category><![CDATA[AJAX]]></category>
		<category><![CDATA[jsf]]></category>
		<category><![CDATA[RichFaces]]></category>

		<guid isPermaLink="false">http://blogs.antartec.com/desarrolloweb/?p=93</guid>
		<description><![CDATA[
			
				
			
		
La carga dinámica de un combo basado en la selección de un combo previo es un problema relativamente clásico y que ha sido abordado de distintas maneras a lo largo del tiempo.
En este post queremos mostrarles como es que nosotros abordamos el tema usando componentes JSF y de Richfaces para resolver el problema.

Para este ejemplo [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fblogs.antartec.com%2Fdesarrolloweb%2F2009%2F01%2Fcarga-dinamica-de-combos-usando-jsf-y-richfaces%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fblogs.antartec.com%2Fdesarrolloweb%2F2009%2F01%2Fcarga-dinamica-de-combos-usando-jsf-y-richfaces%2F&amp;source=antartec&amp;style=normal&amp;service=bit.ly" height="61" width="50" /><br />
			</a>
		</div>
<p>La carga dinámica de un combo basado en la selección de un combo previo es un problema relativamente clásico y que ha sido abordado de distintas maneras a lo largo del tiempo.</p>
<p>En este post queremos mostrarles como es que nosotros abordamos el tema usando componentes JSF y de Richfaces para resolver el problema.</p>
<p><span id="more-93"></span><br />
Para este ejemplo usaremos 2 entidades (Ciudad y Distrito) donde una ciudad tiene múltiples distritos asociados y para el caso práctico asumiremos que ambas solo tienen un id y un nombre.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">@<span style="color: #003399;">Entity</span>
@Table<span style="color: #009900;">&#40;</span>name <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;CIUDAD&quot;</span><span style="color: #009900;">&#41;</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Ciudad <span style="color: #000000; font-weight: bold;">implements</span> <span style="color: #003399;">Serializable</span> <span style="color: #009900;">&#123;</span>
&nbsp;
    @Id
    @GeneratedValue<span style="color: #009900;">&#40;</span>strategy <span style="color: #339933;">=</span> GenerationType.<span style="color: #006633;">AUTO</span><span style="color: #009900;">&#41;</span>
    @Column<span style="color: #009900;">&#40;</span>name <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;ID_CIUDAD&quot;</span>, nullable <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">Integer</span> idCiudad<span style="color: #339933;">;</span>
&nbsp;
    @Length<span style="color: #009900;">&#40;</span>max<span style="color: #339933;">=</span><span style="color: #cc66cc;">45</span><span style="color: #009900;">&#41;</span>
    @Column<span style="color: #009900;">&#40;</span>name <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;NOMBRE&quot;</span>,length<span style="color: #339933;">=</span><span style="color: #cc66cc;">45</span><span style="color: #009900;">&#41;</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> nombre<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
@<span style="color: #003399;">Entity</span>
@Table<span style="color: #009900;">&#40;</span>name <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;DISTRITO&quot;</span><span style="color: #009900;">&#41;</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Distrito <span style="color: #000000; font-weight: bold;">implements</span> <span style="color: #003399;">Serializable</span> <span style="color: #009900;">&#123;</span>
&nbsp;
    @Id
    @GeneratedValue<span style="color: #009900;">&#40;</span>strategy <span style="color: #339933;">=</span> GenerationType.<span style="color: #006633;">AUTO</span><span style="color: #009900;">&#41;</span>
    @Column<span style="color: #009900;">&#40;</span>name <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;ID_CIUDAD&quot;</span>, nullable <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">Integer</span> idDistrito<span style="color: #339933;">;</span>
&nbsp;
    @Length<span style="color: #009900;">&#40;</span>max<span style="color: #339933;">=</span><span style="color: #cc66cc;">45</span><span style="color: #009900;">&#41;</span>
    @Column<span style="color: #009900;">&#40;</span>name <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;NOMBRE&quot;</span>,length<span style="color: #339933;">=</span><span style="color: #cc66cc;">45</span><span style="color: #009900;">&#41;</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> nombre<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Además tendremos un managed bean de JSF llamado testBean que nos servirá para almacenar la información temporal de la página.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">@<span style="color: #003399;">Name</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;testBean&quot;</span><span style="color: #009900;">&#41;</span>
@Scope<span style="color: #009900;">&#40;</span>ScopeType.<span style="color: #006633;">CONVERSATION</span><span style="color: #009900;">&#41;</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> TestBean <span style="color: #000000; font-weight: bold;">implements</span> <span style="color: #003399;">Serializable</span> <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">Integer</span> idCiudad <span style="color: #339933;">=</span> <span style="color: #339933;">-</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//Omitimos sus gets y sets</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">Integer</span> idDistrito <span style="color: #339933;">=</span> <span style="color: #339933;">-</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span><span style="color: #666666; font-style: italic;">//Omitimos sus gets y sets</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span>  Map<span style="color: #339933;">&lt;</span>String,Integer<span style="color: #339933;">&gt;</span> getCiudades<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #003399;">String</span> query <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;select new map(nombre as nombre, idCiudad as idCiudad) &quot;</span> <span style="color: #339933;">+</span>
                <span style="color: #0000ff;">&quot;from Ciudad order by nombre&quot;</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">return</span> uiUtils.<span style="color: #006633;">getComboBox</span><span style="color: #009900;">&#40;</span>query, <span style="color: #0000ff;">&quot;nombre&quot;</span>, <span style="color: #0000ff;">&quot;idCiudad&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span>  Map<span style="color: #339933;">&lt;</span>String,Integer<span style="color: #339933;">&gt;</span> getDistritos<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #003399;">String</span> query <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;select new map(d.nombre as nombre, d.idDistrito as idDistrito) &quot;</span> <span style="color: #339933;">+</span>
                <span style="color: #0000ff;">&quot;from Distrito d where d.ciudad.idCiudad = &quot;</span> <span style="color: #339933;">+</span> idCiudad <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot; order by nombre&quot;</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">return</span> uiUtils.<span style="color: #006633;">getComboBox</span><span style="color: #009900;">&#40;</span>query, <span style="color: #0000ff;">&quot;nombre&quot;</span>, <span style="color: #0000ff;">&quot;idDistrito&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Solo para simplificar el asunto el método getComboBox hace una consulta a la Base de datos y genera una estructura Map&lt;String,Integer&gt;</p>
<p>El signature del método es:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span>  Map<span style="color: #339933;">&lt;</span>String,Integer<span style="color: #339933;">&gt;</span> getComboBox<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> query, <span style="color: #003399;">String</span> value, <span style="color: #003399;">String</span> key<span style="color: #009900;">&#41;</span></pre></div></div>

<p>UPDATE:<br />
Me preguntaron que cosa hace el uiUtils, el uiUtils es un seam bean stateless que tiene un método llamado getComboBox el cual devuelve un Map de labels, ids, la función hace un query a la bd que retorna un map con los dos valores. </p>
<p>Otra alternativa a usar un Map es utlilizar una lista de SelectItem, el objeto tiene el siguiente constructor en su modalidad más sencilla:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">new</span> SelectItem<span style="color: #009900;">&#40;</span><span style="color: #003399;">Object</span> valor, <span style="color: #003399;">String</span> label<span style="color: #009900;">&#41;</span></pre></div></div>

<p>Por lo tanto simplemente es iterar sobre el resultado del query y crear los objetos y retornar la lista.<br />
El código que corresponde a la parte de JSF se los presento a continuación:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;h:selectOneMenu</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;#{testBean.idCiudad}&quot;</span> <span style="color: #000066;">style</span>=<span style="color: #ff0000;">&quot;width:200px;&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;f:selectItem</span> <span style="color: #000066;">itemLabel</span>=<span style="color: #ff0000;">&quot;#{messages['comun.selectOneMenu.seleccione']}&quot;</span> <span style="color: #000066;">itemValue</span>=<span style="color: #ff0000;">&quot;-1&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;f:selectItems</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;#{testBean.cuidades}&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;a4j:support</span> <span style="color: #000066;">event</span>=<span style="color: #ff0000;">&quot;onchange&quot;</span> <span style="color: #000066;">reRender</span>=<span style="color: #ff0000;">&quot;distritosPanel&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/h:selectOneMenu<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;a4j:outputPanel</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;distritosPanel&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ui:fragment</span> <span style="color: #000066;">rendered</span>=<span style="color: #ff0000;">&quot;#{testBean.idCiudad ne -1}&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;h:selectOneMenu</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;#{testBean.idDistrito}&quot;</span> <span style="color: #000066;">style</span>=<span style="color: #ff0000;">&quot;width:200px;&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
       <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;f:selectItem</span> <span style="color: #000066;">itemLabel</span>=<span style="color: #ff0000;">&quot;#{messages['comun.selectOneMenu.seleccione']}&quot;</span> <span style="color: #000066;">itemValue</span>=<span style="color: #ff0000;">&quot;-1&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
       <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;f:selectItems</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;#{testBean.distritos}&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/h:selectOneMenu<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/ui:fragment<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/a4j:outputPanel<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>Como pueden ver es muy sencillo, cada combo tiene dos propiedades importantes, la primera es la que almacenará el resultado de la selección en este caso idCiudad y idDistrito, la segunda es la lista de opciones del combo el cual se obtiene de una propiedad List&lt;SelectItem&gt;, esta lista es generada en el managed bean haciendo consultas a la base de datos.</p>
<p>Los componentes JSF por default no tienen soporte AJAX, lo que significa que tendrían que hacer un submit cada vez que quisieran recargar una sección de la página, es por esto que utilizamos el tag a4j:support que nos permite darle una naturaleza AJAX al componente JSF.</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;a4j:support</span> <span style="color: #000066;">event</span>=<span style="color: #ff0000;">&quot;onchange&quot;</span>  <span style="color: #000066;">reRender</span>=<span style="color: #ff0000;">&quot;distritosPanel&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span></pre></div></div>

<p>Como pueden ver al tag a4j:support tiene 2 propiedades, la primera es el evento que dispara la acción, este podría ser onclick, onmouseover, onmouseout, en este caso utilizamos onchange.La segunda propiedad es el parámetro reRender que le dice al componente las secciones de código que deben ser refrescadas una vez que el request AJAX haya terminado.</p>
<p>De esta manera podemos conseguir cargar dinámicamente un combo JSF mediante AJAX.</p>
<p><strong>Más información</strong></p>
<ul>
<li><a href="http://livedemo.exadel.com/richfaces-demo/richfaces/actionparam.jsf?c=actionparam&amp;tab=usage" target="_blank">Rich faces Demo</a></li>
<li><a href="http://java.sun.com/javaee/javaserverfaces/1.2/docs/tlddocs/index.html" target="_blank">Tag lib de JSF 1.2</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://blogs.antartec.com/desarrolloweb/2009/01/carga-dinamica-de-combos-usando-jsf-y-richfaces/feed/</wfw:commentRss>
		<slash:comments>22</slash:comments>
		</item>
		<item>
		<title>Pop up windows en las aplicaciones web</title>
		<link>http://blogs.antartec.com/desarrolloweb/2009/01/pop-up-windows-en-las-aplicaciones-web/</link>
		<comments>http://blogs.antartec.com/desarrolloweb/2009/01/pop-up-windows-en-las-aplicaciones-web/#comments</comments>
		<pubDate>Tue, 13 Jan 2009 19:59:23 +0000</pubDate>
		<dc:creator>Giancarlo Corzo</dc:creator>
				<category><![CDATA[Arquitectura]]></category>
		<category><![CDATA[Frameworks]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[popup]]></category>
		<category><![CDATA[window]]></category>

		<guid isPermaLink="false">http://blogs.antartec.com/desarrolloweb/?p=73</guid>
		<description><![CDATA[
			
				
			
		
Introducción
Las ventanas Pop up siempre han sido un problema en el desarrollo de aplicaciones web, las que proporciona el browser son poco prácticas al ser mini ventanas que se abren de manera separada a la aplicación, en un browser independiente y que no comparten información de manera natural. (Solamente mediante javascript).
Además recientemente éstas han sido [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fblogs.antartec.com%2Fdesarrolloweb%2F2009%2F01%2Fpop-up-windows-en-las-aplicaciones-web%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fblogs.antartec.com%2Fdesarrolloweb%2F2009%2F01%2Fpop-up-windows-en-las-aplicaciones-web%2F&amp;source=antartec&amp;style=normal&amp;service=bit.ly" height="61" width="50" /><br />
			</a>
		</div>
<p><strong>Introducción</strong></p>
<p>Las ventanas Pop up siempre han sido un problema en el desarrollo de aplicaciones web, las que proporciona el browser son poco prácticas al ser mini ventanas que se abren de manera separada a la aplicación, en un browser independiente y que no comparten información de manera natural. (Solamente mediante javascript).</p>
<p>Además recientemente éstas han sido utilizadas como una manera de spam publicitario al activarse al momento de ingresar a la página web, lo que hace que la navegación sea realmente molesta. Dada esta situación los browser decidieron desarrollar sistemas que bloqueen los Pop ups de toda aplicación sin importar si estos eran relevantes o no.</p>
<p>Es por esto que multiples frameworks de javascript como yui, ext, richfaces (aunque no es de javascript tambien provee Pop up windows) han desarrollado Pop up windows basados en un div flotante y que son bastante útiles.</p>
<p><span id="more-73"></span><br />
<strong>¿Qué hace que un Pop up window sea realmente útil?</strong></p>
<p>Un Pop up window utilizado dentro de una aplicación es útil en la medida en que pueda cumplir los mismos requerimientos que tendría un Dialog hecho en Java o C#.</p>
<p>Por lo tanto las características que deben tener son:</p>
<ul>
<li>Deben poder ser invocados desde cualquier lugar (en este caso desde cualquier página web).</li>
<li>Ser autocontenibles (que no se necesite registrar información extra para que funcionen).</li>
<li>En caso que necesiten retornar parámetros, estos debe poder ser obtenidos en la página que lo llamo.</li>
<li>Una extensión del punto anterior seria que los Pop up window puedan intercambiar información entre ellos.</li>
<li>Capacidad de recibir parámetros.</li>
</ul>
<p><strong>Nuestra solución</strong></p>
<p>Hemos planteado nuestra solución de la siguiente manera:</p>
<p>Para cumplir con el primer y tercer objetivo tenemos un objeto javascript que es omnipresente a todas las páginas y se encarga de: crear, mostrar y cerrar los Pop up y además maneja los parámetros de retorno.</p>
<p>Para cumplir con el segundo objetivo el contenido del modal panel esta en otra página web y ésta es mostrada a través de un iframe dentro del modal.</p>
<p>Para cumplir con el quinto objetivo simplemente se los pasamos como parámetros de url a la página dentro del iframe.</p>
<p>Un ejemplo de cómo instanciamos un objeto:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> editarObjeto<span style="color: #009900;">&#40;</span>id<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  ManejadorVentanas.<span style="color: #660066;">mostrar</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
   id<span style="color: #339933;">:</span> <span style="color: #3366CC;">'idPanel'</span><span style="color: #339933;">,</span>
   titulo<span style="color: #339933;">:</span> <span style="color: #3366CC;">'Editar objeto'</span><span style="color: #339933;">,</span>
   src<span style="color: #339933;">:</span> <span style="color: #3366CC;">'/contenido/editarObjeto.xhtml?id='</span> <span style="color: #339933;">+</span> id<span style="color: #339933;">,</span>
   ancho<span style="color: #339933;">:</span> <span style="color: #CC0000;">500</span><span style="color: #339933;">,</span>
   alto<span style="color: #339933;">:</span> <span style="color: #CC0000;">350</span><span style="color: #339933;">,</span>
   callback<span style="color: #339933;">:</span> refrescarLista
 <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Como puede verse la invocación es muy sencilla y solo se requiere tener la página en donde se desarrollará el contenido.</p>
<p>La función de callback permite obtener los parámetros de retorno, de esta manera:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> refrescarLista <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
   <span style="color: #003366; font-weight: bold;">var</span> rpta <span style="color: #339933;">=</span> ManejadorVentanas.<span style="color: #660066;">obtenerParametros</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'idPanel'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#91;</span><span style="color: #3366CC;">'rptaModal'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
   <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>rpta<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #003366; font-weight: bold;">var</span> valorRetornado <span style="color: #339933;">=</span> ManejadorVentanas.<span style="color: #660066;">obtenerParametros</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'idPanel'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#91;</span><span style="color: #3366CC;">'valor1'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
      <span style="color: #006600; font-style: italic;">// hacer algo mas.</span>
   <span style="color: #009900;">&#125;</span>
 <span style="color: #009900;">&#125;</span></pre></div></div>

<p><strong>A manera de conclusión</strong></p>
<p>No importa con que librería de javascript estén trabajando (YUI, JQuery, ExtJS, Dojo, etc) estos principios básicos deben poderse cumplir para poder sacar el máximo provecho de las Pop up windows dentro de una aplicación web.</p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.antartec.com/desarrolloweb/2009/01/pop-up-windows-en-las-aplicaciones-web/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Facelets y JSF &#8211; Uso de Templates</title>
		<link>http://blogs.antartec.com/desarrolloweb/2008/12/facelets-y-jsf-uso-de-templates/</link>
		<comments>http://blogs.antartec.com/desarrolloweb/2008/12/facelets-y-jsf-uso-de-templates/#comments</comments>
		<pubDate>Wed, 17 Dec 2008 13:17:04 +0000</pubDate>
		<dc:creator>Otto Theo</dc:creator>
				<category><![CDATA[Frameworks]]></category>
		<category><![CDATA[facelets]]></category>
		<category><![CDATA[jsf]]></category>
		<category><![CDATA[jsp]]></category>
		<category><![CDATA[templates]]></category>

		<guid isPermaLink="false">http://blogs.antartec.com/desarrolloweb/?p=19</guid>
		<description><![CDATA[
			
				
			
		
Este artículo tratará sobre el framework JavaServer Facelets comenzando con una pequeña introducción y luego una descripción básica del uso de templating en una aplicación JSF (JavaServer Faces).
Introducción
JavaServer Facelets es un framework para plantillas (templates) centrado en la tecnología JSF (JavaServer Faces), por lo cual se integran de manera muy fácil. Este framework incluye muchas [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fblogs.antartec.com%2Fdesarrolloweb%2F2008%2F12%2Ffacelets-y-jsf-uso-de-templates%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fblogs.antartec.com%2Fdesarrolloweb%2F2008%2F12%2Ffacelets-y-jsf-uso-de-templates%2F&amp;source=antartec&amp;style=normal&amp;service=bit.ly" height="61" width="50" /><br />
			</a>
		</div>
<p>Este artículo tratará sobre el framework <a title="JavaServer Facelets" href="https://facelets.dev.java.net/" target="_blank">JavaServer Facelets</a> comenzando con una pequeña introducción y luego una descripción básica del uso de templating en una aplicación JSF (JavaServer Faces).</p>
<p><strong>Introducción</strong></p>
<p><a title="JavaServer Facelets" href="https://facelets.dev.java.net/" target="_blank">JavaServer Facelets</a> es un framework para plantillas (templates) centrado en la tecnología JSF (JavaServer Faces), por lo cual se integran de manera muy fácil. Este framework incluye muchas características siendo las más importantes:</p>
<p><span id="more-19"></span></p>
<ul>
<li>Tiempo de desarrollo cero de los tags para UIComponents.</li>
<li>Facilidad en la creación del templating para los componentes y páginas.</li>
<li>Habilidad de separar los UIComponents en diferentes archivos.</li>
<li>Un buen sistema de reporte de errores.</li>
<li>Soporte completo a EL (Expression Language).</li>
<li>Validación de EL en tiempo de construcción.</li>
<li>No es necesaria configuración XML.</li>
<li>Trabaja con cualquier RenderKit.</li>
</ul>
<p>Desafortunadamente JSP (JavaServer Pages) y JSF no se complementan naturalmente, cuando se usan juntos ambos escriben output al response, pero lo hacen de una manera diferente: JSP crea output ni bien encuentra código JSP (es decir procesa los elementos de la página de arriba a abajo), mientras que JSF dicta su propio re-rendering (ya que su ciclo de vida está dividido en fases marcadas). Facelets llena este vacío entre JSP y JSF, siendo una tecnología centrada en crear árboles de componentes y estar relacionado con el complejo ciclo de vida JSF.</p>
<p><strong>¿Por qué Facelets?</strong></p>
<ul>
<li>No depende de un contenedor Web.</li>
<li>Integrar JSP con JSF trae problemas, además, no se puede usar JSTL (JavaServer Pages Standard Tag Library) con JSF, cosa que Facelets sí provee.</li>
<li>Facelets provee un proceso de compilación más rápido que JSP.</li>
<li>Provee templating, lo cual implica reutilización de código, simplificación de desarrollo y facilidad en el mantenimiento de grandes aplicaciones.</li>
<li>Permite crear componentes ligeros sin necesidad de crear los tags de los UIComponents (es más fácil comparado a crear un componente JSF puro).</li>
<li>Soporta Unified Expression Language, incluyendo soporte para funciones EL y validación de EL en tiempo de compilación.</li>
</ul>
<p><strong>Templating</strong></p>
<p>Existen tres maneras de modularizar las páginas y componentes: <em>includes</em>, <em>archivos tag </em>y <em>decorators</em>. Pero primero algo básico de templating:</p>
<p><span style="text-decoration: underline">La página que contendrá al template</span>:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;html</span> <span style="color: #000066;">xmlns</span>=<span style="color: #ff0000;">&quot;http://www.w3.org/1999/xhtml&quot;</span></span>
<span style="color: #009900;">  <span style="color: #000066;">xmlns:ui</span>=<span style="color: #ff0000;">&quot;http://java.sun.com/jsf/facelets&quot;</span></span>
<span style="color: #009900;">  <span style="color: #000066;">xmlns:h</span>=<span style="color: #ff0000;">&quot;http://java.sun.com/jsf/html&quot;</span></span>
<span style="color: #009900;">  <span style="color: #000066;">xmlns:f</span>=<span style="color: #ff0000;">&quot;http://java.sun.com/jsf/core&quot;</span></span>
<span style="color: #009900;">  <span style="color: #000066;">xmlns:c</span>=<span style="color: #ff0000;">&quot;http://java.sun.com/jstl/core&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
&nbsp;
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;head<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ui:insert</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;head&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/head<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;body<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;div</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;body&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ui:insert</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;body&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
        Contenido por defecto
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/ui:insert<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/div<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/body<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/html<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p><span style="text-decoration: underline">El template en sí</span>:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ui:composition</span> <span style="color: #000066;">xmlns</span>=<span style="color: #ff0000;">&quot;http://www.w3.org/1999/xhtml&quot;</span></span>
<span style="color: #009900;">  <span style="color: #000066;">xmlns:ui</span>=<span style="color: #ff0000;">&quot;http://java.sun.com/jsf/facelets&quot;</span></span>
<span style="color: #009900;">  <span style="color: #000066;">xmlns:f</span>=<span style="color: #ff0000;">&quot;http://java.sun.com/jsf/core&quot;</span></span>
<span style="color: #009900;">  <span style="color: #000066;">xmlns:h</span>=<span style="color: #ff0000;">&quot;http://java.sun.com/jsf/html&quot;</span></span>
<span style="color: #009900;">  <span style="color: #000066;">xmlns:c</span>=<span style="color: #ff0000;">&quot;http://java.sun.com/jstl/core&quot;</span></span>
<span style="color: #009900;">  <span style="color: #000066;">template</span>=<span style="color: #ff0000;">&quot;/template.xhtml&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
  <span style="color: #808080; font-style: italic;">&lt;!-- nótese el uso del atributo 'template' --&gt;</span>
&nbsp;
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ui:define</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;head&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #808080; font-style: italic;">&lt;!-- contenido de la cabecera --&gt;</span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/ui:define<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ui:define</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;body&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #808080; font-style: italic;">&lt;!-- contenido del cuerpo --&gt;</span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/ui:define<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/ui:composition<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>Como puede verse donde uno quiere que se inserte código se usa el tag <strong>&lt;ui:insert name=&#8221;nombre&#8221;/&gt;</strong> donde nombre corresponde al identificador de la sección.</p>
<p><strong>Tres maneras de modularizar con Facelets</strong></p>
<p>Esta es la porción de código que se abstraerá para los ejemplos siguientes:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ui:composition<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  Bienvenido, #{usuario.nombre}
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/ui:composition<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<ul>
<li><strong>Templating mediante &#8216;includes&#8217;</strong></li>
</ul>
<p>Este es el método más familiar para modularizar componentes (se le pueden pasar parámetros al &#8216;ui:include&#8217;).</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;span</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;loginDisplay&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ui:include</span> <span style="color: #000066;">src</span>=<span style="color: #ff0000;">&quot;/contenido/bienvenido.xhtml&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;</span></span>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ui:param</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;usuario&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;#{usuarioActual}&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/ui:include<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/span<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<ul>
<li><strong>Templating mediante un &#8216;tag file&#8217;</strong></li>
</ul>
<p>Para esta manera de templating, al tag se le da un namespace, por ejemplo:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ui:composition</span> <span style="color: #000066;">xmlns</span>=<span style="color: #ff0000;">&quot;http://www.w3.org/1999/xhtml&quot;</span></span>
<span style="color: #009900;">  <span style="color: #000066;">xmlns:ui</span>=<span style="color: #ff0000;">&quot;http://java.sun.com/jsf/facelets&quot;</span></span>
<span style="color: #009900;">  <span style="color: #000066;">xmlns:f</span>=<span style="color: #ff0000;">&quot;http://java.sun.com/jsf/core&quot;</span></span>
<span style="color: #009900;">  <span style="color: #000066;">xmlns:h</span>=<span style="color: #ff0000;">&quot;http://java.sun.com/jsf/html&quot;</span></span>
<span style="color: #009900;">  <span style="color: #000066;">xmlns:c</span>=<span style="color: #ff0000;">&quot;http://java.sun.com/jstl/core&quot;</span></span>
<span style="color: #009900;">  <span style="color: #000066;">xmlns:my</span>=<span style="color: #ff0000;">&quot;http://www.mycompany.com/jsf&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
...
  <span style="color: #808080; font-style: italic;">&lt;!-- uso del tag --&gt;</span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;my:bienvenido</span> <span style="color: #000066;">usuario</span>=<span style="color: #ff0000;">&quot;#{usuarioActual}&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
...
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/ui:composition<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>¿Cómo especificamos el tag?: en un archivo xml, que es una libreria de tags facelets. Este archivo es cargado automáticamente por Facelets, para ello debe tener la extensión <strong>*.taglib.xml </strong>y estar ubicado en el directorio especial META-INF.</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;facelet-taglib<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;namespace<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>http://www.mycompany.com/jsf<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/namespace<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;tag<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;tag-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>bienvenido<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/tag-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;source<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>contenido/bienvenido.xhtml<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/source<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/tag<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
...
  <span style="color: #808080; font-style: italic;">&lt;!-- otros tags --&gt;</span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/facelet-taglib<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<ul>
<li><strong>Templating mediante &#8216;decorators&#8217;</strong></li>
</ul>
<p>Los decorators se pueden usar de la misma manera que los compositions, pero éstos pueden ser insertados en la página (inline).</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;">El texto anterior se mostrará.
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ui:decorate</span> <span style="color: #000066;">template</span>=<span style="color: #ff0000;">&quot;/contenido/bienvenido.xhtml&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ui:param</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;usuario&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;#{usuarioActual}&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/ui:decorate<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
El texto posterior se mostrará.</pre></div></div>

<p>Un uso práctico del decorator es cuando no tiene mucho sentido abstraer el componente en un archivo aparte, pero sí usar las ventajas del templating.</p>
<p><strong>A manera de conclusión</strong></p>
<p>El uso de templating trae consigo las ventajas de tener un código ordenado (sobre todo en aplicaciones grandes), fácil de desarrollar y reusar. Uno puede crear componentes o templates que abarcan desde simplemente mostrar texto hasta crear componentes que muestren un checkbox, un input o un dropdown dependiendo de la data del backing bean.</p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.antartec.com/desarrolloweb/2008/12/facelets-y-jsf-uso-de-templates/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
	</channel>
</rss>

