<?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>Gilliard Cordeiro &#187; Facelets</title>
	<atom:link href="http://blog.gilliard.eti.br/category/facelets/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.gilliard.eti.br</link>
	<description>tá nervoso? vai programar!</description>
	<lastBuildDate>Tue, 25 May 2010 20:00:10 +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>Exemplo com JSF 2.0</title>
		<link>http://blog.gilliard.eti.br/2009/02/exemplo-com-jsf-2/</link>
		<comments>http://blog.gilliard.eti.br/2009/02/exemplo-com-jsf-2/#comments</comments>
		<pubDate>Mon, 02 Feb 2009 20:44:56 +0000</pubDate>
		<dc:creator>Gilliard Cordeiro</dc:creator>
				<category><![CDATA[Facelets]]></category>
		<category><![CDATA[JSF]]></category>
		<category><![CDATA[JavaEE]]></category>
		<category><![CDATA[JavaServer Faces]]></category>

		<guid isPermaLink="false">http://blog.gilliard.eti.br/?p=113</guid>
		<description><![CDATA[Na última sexta-feira, dia 30/01/2009, realizamos a primeira reunião de 2009 do JUGMS. Foi bem legal, contamos com mais de 100 pessoas. Nosso bate papo teve, além de conversarmos sobre os planos do JUGMS, dois assuntos bem interessantes. O Saulo falou um pouco sobre Análise e Projeto OO em Java, e eu sobre as novidades [...]]]></description>
			<content:encoded><![CDATA[<p>Na última sexta-feira, dia 30/01/2009, realizamos a primeira reunião de 2009 do <a href="http://www.jugms.com.br/reuniao-2009-1/" target="_blank">JUGMS</a>. Foi bem legal, contamos com mais de 100 pessoas. Nosso bate papo teve, além de conversarmos sobre os planos do JUGMS, dois assuntos bem interessantes. O <a href="http://sauloarruda.eti.br/" target="_blank">Saulo</a> falou um pouco sobre Análise e Projeto OO em Java, e eu sobre as novidades do JavaEE 6, parando um tempinho a mais na parte de JSF 2.0.</p>
<p>O tempo foi curto, e não deu pra explorar muito o exemplo, mas estou disponibilizando agora a <a href="http://blog.gilliard.eti.br/arquivos/JavaEE_nos_trilhos.pdf">apresentação</a> e o <a href="http://blog.gilliard.eti.br/arquivos/apresentacao-jsf2.war">projeto de exemplo usando JSF 2</a>. O exemplo foi feito usando Java 6 e tomcat 6.</p>
<p>Alguns pontos que eu procurei mostrar no exemplo foram:</p>
<h2>API AJAX do JSF 2.0</h2>
<p>No código do exemplo podemos ver trechos de código como este:</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:commandButton</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;Salvar&quot;</span> <span style="color: #000066;">action</span>=<span style="color: #ff0000;">&quot;#{estadoBean.salvar}&quot;</span></span>
<span style="color: #009900;"><span style="color: #000066;">onclick</span>=<span style="color: #ff0000;">&quot;return facesAjaxRequest(this, event, {inputs: 'formEstado', render: 'formEstado:listaEstados'})&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
...</pre></div></div>

<p>onde eu criei essa função js chamada <i>facesAjaxRequest</i> que encapsula a simples chamada ajax do jsf 2 que seria assim:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">jsf.<span style="color: #660066;">ajax</span>.<span style="color: #660066;">request</span><span style="color: #009900;">&#40;</span>element<span style="color: #339933;">,</span> event<span style="color: #339933;">,</span> options<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Essa funçao recebe o elemento que está disparando a ação (normalmente this), o evento e um mapa de parâmetros. Nesse mapa existem duas entradas: execute e render. No render, especificamos, separados pos espaços em branco, os clientIds dos componentes que serão renderizados novamente, e no execute passamos os valores a serem enviados ao server nessa requisição ajax.</p>
<p>No exemplo usei a função facesAjaxRequest para montar dinamicamente a lista que vai no parâmetro execute, por isso este parâmetro não aparece no primeiro exemplo mostrado. Com essa função, podemos ainda passar o id de qualquer elemento html pelo atributo inputs do mapa que todos os inputs e selects que estiverem abaixo desse elemento será enviado para o server. Na tela de cadastro de cidades fiz uma espécie de ajaxRegion usando essa forma bem simples.</p>
<p>Isso tudo porque o JSF 2 não tem algo tão fácil de usar como os componentes da biblioteca ajax4jsf. A idéia dessa biblioteca de ajax de jsf 2 não é deixar tudo mastigadinho, e sim prover uma infraestrutura básica uso padronizado de js nos componentes, eliminando ou diminuindo assim as incompatibilidades entre as bibliotecas de componentes disponíveis.</p>
<p>Para quem chegou a usar as funções js do Facelets 1.2, que nem chegou a ser continuado, e que eu mostrei num artigo que escrevi pra MundoJava há muito tempo, o funcionamento é quase o mesmo, só mudando praticamente o nome das funções js e a forma como os dados eram enviados ao server.</p>
<h2>Facelets 2</h2>
<p>Como já foi dito por aí, agora o JSF já vem por default com o Facelets 2 habilitado, não sendo necessário colocar nenhuma configuração para utilizálo. Inclusive no exemplo disponível para download, nem existe o arquivo faces-config.xml, pois fiz tudo por anotações e o Facelets já vem pronto pra uso. Mas é claro que ele continua sendo utilizado para as regras de navegação.</p>
<h2>Criação de componentes com Facelets 2</h2>
<p>Com facelets 2, a criação de componentes será algo mais &#8220;formal&#8221; do que fazemos com facelets hoje em dia. Isso graças a presença de uma definição do componente como esse:</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;composite:interface</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;beanSimples&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;composite:attribute</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;bean&quot;</span> <span style="color: #000066;">required</span>=<span style="color: #ff0000;">&quot;true&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;composite:attribute</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;descricao&quot;</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;String&quot;</span> <span style="color: #000066;">required</span>=<span style="color: #ff0000;">&quot;true&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/composite:attribute<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/composite:interface<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;composite:implementation<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    Descrição: <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;h:inputText</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;descricao&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;#{compositeComponent.attrs.bean.descricao}&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/composite:implementation<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
...</pre></div></div>

<p>O componete possui a interface e a implementação. Na interface podemos colocar os parâmetros que serão recebidos, como no exemplo onde eu preciso passar um objeto que eu chamei de &#8220;bean&#8221; e esse bean tem que ter um atributo do tipo String chamado descrição.</p>
<p>É possível ainda passar atributos que representam ações, o que não é possível hoje em dia. Além disso não é necessário nenhum arquivo para configurar o nosso componente customizado, tudo é feito através de convenção. Basta colocar o componente em uma pasta dentro do resources do jsf que ele já fica publicado e acessível por uma uri default. Mas se quisermos colocar uma uri específica é só indicar através de um arquivo de configuração.</p>
<h2>SelectItems</h2>
<p>Finalmente podemos usar o componente f:selectItems sem ter que criar uma lista ou array de SelectItem. Agora podemos usar diretamente nossos objetos do modelo como podemos fazer usando outros componentes de selectItems como o do Seam.</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;#{cidadeBean.cidade.estado}&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;#{estadoBean.estados}&quot;</span> <span style="color: #000066;">var</span>=<span style="color: #ff0000;">&quot;estado&quot;</span> <span style="color: #000066;">itemLabel</span>=<span style="color: #ff0000;">&quot;#{estado.descricao}&quot;</span> <span style="color: #000066;">itemValue</span>=<span style="color: #ff0000;">&quot;#{estado}&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></pre></div></div>

<h2>Finalizando</h2>
<p>O exemplo disponível é bem simples, mas procurei mostrar nele o uso de coisas simples, como as mencionadas acima, e também proporcionar para quem ainda não teve a disposição de começar a testar que já tenha um ponto de partida. Olhando o código fonte podemos ver funcionando também as novas tags para escrever css e js, e explorar a parte de localização de recursos, que é inclusive o que torna a criação de componentes tão simples.</p>
<p>Espero que esse post e os materiais relacionados sejam de utilidade, e caso você encontre algum erro no material disponível me avise comentando aqui <img src='http://blog.gilliard.eti.br/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://blog.gilliard.eti.br/2009/02/exemplo-com-jsf-2/feed/</wfw:commentRss>
		<slash:comments>24</slash:comments>
		</item>
		<item>
		<title>JavaServer Faces 2.0 &#8211; Early Draft Review 2</title>
		<link>http://blog.gilliard.eti.br/2008/09/jsf-2-early-draft-review-2/</link>
		<comments>http://blog.gilliard.eti.br/2008/09/jsf-2-early-draft-review-2/#comments</comments>
		<pubDate>Thu, 25 Sep 2008 01:58:32 +0000</pubDate>
		<dc:creator>Gilliard Cordeiro</dc:creator>
				<category><![CDATA[Facelets]]></category>
		<category><![CDATA[JSF]]></category>
		<category><![CDATA[JavaEE]]></category>
		<category><![CDATA[JavaServer Faces]]></category>

		<guid isPermaLink="false">http://blog.gilliard.eti.br/?p=71</guid>
		<description><![CDATA[Saiu o segundo rascunho da especificação do JSF 2.0, no entanto ainda não há uma versão da implementação da EDR2 disponível para download como já saiu para a EDR1.
Primeiramente, vou me basear nas diferenças entre as reviews 1 e 2, mas isso não significa que o que vou falar aqui é inédito pois podemos ver [...]]]></description>
			<content:encoded><![CDATA[<p>Saiu o segundo rascunho da especificação do JSF 2.0, no entanto ainda não há uma versão da implementação da EDR2 disponível para download como já saiu para a EDR1.</p>
<p>Primeiramente, vou me basear nas diferenças entre as reviews 1 e 2, mas isso não significa que o que vou falar aqui é inédito pois podemos ver na net diversos post comentando <a href="http://blogs.sun.com/rlubke/entry/jsf_2_0_new_feature2">o que vem por aí</a>. E também ainda não li tudo, a idéia é compartilhar o que mais me chamou a atenção nesse primeiro contato.</p>
<h2>FacesContext</h2>
<p>Sem dúvida essa é uma das classes que mais manipulamos no JSF, e nela temos algumas funcionalidades novas interessantes:</p>
<ul>
<li><strong>getCurrentPhaseId</strong>() &#8211; Disponível desde a EDR1, devolve um <a href="http://java.sun.com/javaee/javaserverfaces/1.2/docs/api/javax/faces/event/PhaseId.html">PhaseId</a>. Pode ser bem útil para fazermos algumas coisas só depois de uma de</code>determinada fase.</li>
<li><strong>getExecutePhaseClientIds</strong>() - Devolve uma List&lt;String&gt;. Guarda uma lista com os client ids dos componentes que serão processados na requisição atual. Isso porque o JSF2 tem nativamente o suporte à ajax, e submissão parcial da página.</li>
<li><strong>getPartialResponseWriter</strong>() - Devolve o <a href="http://java.sun.com/javaee/javaserverfaces/1.2/docs/api/javax/faces/context/ResponseWriter.html">ResponseWriter</a> para os componentes de uma renderização parcial.</li>
<li><strong>getRenderPhaseClientIds</strong>() - Devolve uma List&lt;String&gt; contendo os client ids</code> dos componentes que serão renderizados em uma renderização parcial.</li>
<li><strong>isAjaxRequest</strong>() - devolve um boolean dizendo se a requisição é ajax (auto explicativa né <img src='http://blog.gilliard.eti.br/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  )</li>
<li><strong>isExecuteNone</strong>() - retorna true se for uma submissão parcial mas nenhum componente precisará ser processado. Seria como dar apenas um reRender usando o ajax4jsf mas sem mandar executar nada.</li>
<li><strong>isPostback</strong>() - método "atalho" para <a href="http://java.sun.com/javaee/javaserverfaces/1.2/docs/api/javax/faces/render/ResponseStateManager.html#isPostback(javax.faces.context.FacesContext)">ResponseStateManager.isPostback(FacesContext)</a>.</li>
<li><strong>isRenderAll</strong>() - Retorna true se for uma requisição ajax, isRenderNone() retornar falso, e getRenderPhaseClientIds() retornar uma lista vazia.</li>
<li><strong>isRenderNone</strong>() - Retorna true caso for para executar uma renderização parcial, mas a lista de componentes a renderizar for vazia. Imagine uma requisição ajax que só envia dados ao servidor.</li>
</ul>
<p>Para os métodos get dessa lista, também tem os respectivos set.</p>
<h2>Annotations</h2>
<p>Uma coisa que todo mundo esperava está disponível no EDR2, que é a possibilidade de anotar nossos managed beans com <strong>@ManagedBean</strong>, <strong>@FacesValidator</strong>, <strong>@FacesConverter</strong> e <strong>@FacesComponent</strong> entre outros.</p>
<p>Para quem já está habituado com o <a href="http://www.seamframework.org">Seam</a> vai se sentir bem a vontade, pois as anotações seguem o mesmo estilo.</p>
<p>Apesar de no começo parecer estranho esse prefixo "Faces" em todas essas anotações, fica útil para não confundir com as interfaces com o mesmo nome. Sem isso (no Seam é assim), como importamos a anotação e a interface com o mesmo nome, uma das duas tem que ficar com o nome totalmente especificado. Não que seja problema, mas com esse prefixo fica mais "limpinho".</p>
<p><strong>@ManagedBean</strong></p>
<ul>
<li><strong>name</strong> - nome do managed bean</li>
<li><del datetime="2009-10-19T18:35:30+00:00"><strong>scope</strong>- escopo. O que não pareceu tão legal é que a gente passa uma String ("request", "session" ou "application"), quando seria mais bacana uma Enum como o Seam faz. O valor default é "none".</del></li>
<li><strong>eager</strong> - se for true, o managed bean será startado junto com a aplicação, e o "escope" passado será ignorado, e o managed bean será do escopo application. Se for false, fica como é hoje (lazy). O default é false.</li>
</ul>
<p><strong>@RequestScoped, @SessionScoped, @ApplicationScoped, @NoneScoped, <a href="http://blog.gilliard.eti.br/2008/10/view-scope-no-jsf-2/">@ViewScoped</a>, <a href="http://blog.gilliard.eti.br/2009/05/conversation-scope-usando-customscoped-do-jsf-2/">@CustomScoped</a></strong></p>
<ul>
<li>Cada uma das anotações representando seus respectivos escopos</li>
</ul>
<p><strong>@FacesConverter</strong></p>
<ul>
<li><strong>value</strong> - string que representa o <em>converter-id</em> do conversor</li>
<li><strong>forClass</strong> - passamos o java.lang.Class da classe que queremos registrar o conversor na forma de <em>converter-for-class</em></li>
</ul>
<p><strong>@FacesValidator</strong></p>
<ul>
<li><strong>value</strong> - string que representa o <em>validator-id</em> do validador</li>
</ul>
<p><strong>@FacesComponent</strong></p>
<ul>
<li><strong>value</strong> - string que representa o <em>component-type</em> do UIComponente</li>
</ul>
<h2>Facelets 2</h2>
<p>O outro assunto que de cara me interessou foi a integração do JSF com o Facelets, pois já uso Facelets há um bom tempo e nem me imagino fazendo uma aplicação em JSF sem ele. Tanto que até escrevi uma <a href="http://www.mundojava.com.br/NovoSite/21destaque.shtml">matéria pra a MundoJava</a> sobre Facelets e as novidades do JSF 1.2. Na época eu comentei sobre a versão 1.2 do Facelets que nunca chegou a sair, talvez porque o pessoal passou a investir no JSFTemplating ou quem sabe viram que compensaria partir logo para um 2.0. Mas no Facelets 1.2 já podíamos ver o que provavelmente foi a base da API de Ajax para o JSF2.</p>
<p>No JSF2 temos o chamado PDL (Page Declaration Language), que é uma abstração para os mecanismos de definição de páginas disponíveis para o JSF, que até agora são JSP e Facelets. Porém se a gente der uma espiadinha no projeto JSFTemplating, podemos ver que existe a possibilidade de usarmos outras coisas, como Groovy por exemplo. Então é bem possível que vejamos coisas parecidas para o JSF2. Só para concluir a idéia, já é possivel usar Groovy em vez de xhtml para construir telas com Facelets, usando <a href="http://gracelets.sourceforge.net/">Gracelets</a>. É bem bacana e eu já fiz uns testes que depois vou postar aqui também. Mas vamos voltar ao assunto.</p>
<p>Na EDR2 é explicado como será mantida a compatibilidade retroativa com as aplicações que usam Facelets. Basicamente será procurando dentro das classes da nossa aplicação ou das dependencias dela se existe alguma dependencia de classes do pacote com.sun.facelets e/ou dos seus subpacotes. Se houver, o Facelets embarcado no JSF não vai rodar, e as coisas vão continuar como estão, onde quem roda é o facelets que está no jar da nossa aplicação. Agora se não houver dependencia com as classes do Facelets atual, o Facelets2 entra em ação.</p>
<h3>Composition Component com JSF/Facelets 2</h3>
<p>Primeiramente, seria interessante dar uma olhada no <a href="http://blogs.sun.com/rlubke/entry/jsf_2_0_new_feature5">suporte a recursos</a> do JSF2 para entendermos melhor como tudo vai funcionar. Vou seguir o exemplo da documentação para facilitar.</p>
<p>Um composition component vai ser definifo usando o suporte a resources do JSF2. Imagine que o source do nosso componente é o <strong>foo.xhtml</strong> que está dentro da pasta <strong>ezcomp</strong> que por sua vez fica dentro da pasta de resources do JSF. Para usarmos esse componente nao precisamos mais de um arquivo taglib.xml, bastara chamarmos assim:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
</pre></td><td class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #00bbdd;">&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot;</span>
<span style="color: #00bbdd;"> &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;&gt;</span>
 <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: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: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:ez</span>=<span style="color: #ff0000;">&quot;http://java.sun.com/jsf/composite/ezcomp&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;ez:foo</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
   ...
<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></td></tr></table></div>

<p>Como podemos ver nossos componentes ficam automaticamente visíveis usando o padrão <em>http://java.sun.com/jsf/composite/&lt;composite-library-name&gt;</em> onde <em>&lt;composite-library-name&gt;</em> é o nome da nossa pasta dentro do resources do JSF. E cada xhtml dentro dessa pasta pode ser acessado como um componente. Vimos aqui um bom exemplo de <a href="http://en.wikipedia.org/wiki/Convention_over_Configuration">CoC</a> no JSF2. Agora se quisermos usar um padrão diferente de nomenclatura para nossos componentes, basta usar o bom e velho arquivo de configuração de taglibs do facelets.</p>
<p>Agora ainda seguindo o exemplo disponível na versão snapshot (e provavelmente será a mesma do EDR2), vamos ver como fica o código de um componente definido em um arquivo chamado loginPanel.xhtml</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
</pre></td><td class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #00bbdd;">&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;&gt;</span>
<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: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: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:composite</span>=<span style="color: #ff0000;">&quot;http://java.sun.com/jsf/composite&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>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;title<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Not present in rendered output<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/title<span style="color: #000000; font-weight: bold;">&gt;</span></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>
<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;composite:interface</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;loginPanel&quot;</span></span>
<span style="color: #009900;">                     <span style="color: #000066;">displayName</span>=<span style="color: #ff0000;">&quot;Very Simple Login Panel&quot;</span></span>
<span style="color: #009900;">                     <span style="color: #000066;">preferred</span>=<span style="color: #ff0000;">&quot;true&quot;</span></span>
<span style="color: #009900;">                     <span style="color: #000066;">expert</span>=<span style="color: #ff0000;">&quot;false&quot;</span></span>
<span style="color: #009900;">                     <span style="color: #000066;">shortDescription</span>=<span style="color: #ff0000;">&quot;An illustration of the composite component feature&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;composite:attribute</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;model&quot;</span> <span style="color: #000066;">required</span>=<span style="color: #ff0000;">&quot;true&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;composite:attribute</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;loginAction&quot;</span> <span style="color: #000066;">required</span>=<span style="color: #ff0000;">&quot;true&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;composite:deferred-method<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;composite:method-signature<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                    java.lang.Object action()
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/composite:method-signature<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/composite:deferred-method<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
     <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/composite:attribute<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/composite:attribute<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
&nbsp;
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;composite:editableValueHolder</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;username&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;composite:actionSource</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;loginEvent&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;composite:actionSource</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;cancelEvent&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;composite:actionSource</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;allEvents&quot;</span> <span style="color: #000066;">targets</span>=<span style="color: #ff0000;">&quot;loginEvent,cancelEvent&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;composite:facet</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;header&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;/composite:interface<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;composite:implementation<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;table</span> <span style="color: #000066;">border</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;thead<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;tr<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;th<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
     <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;composite:insertFacet</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;header&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/th<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/tr<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/thead<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;tbody<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;tr<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;td<span style="color: #000000; font-weight: bold;">&gt;</span></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>
         <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;h:inputText</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;username&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>
      <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;h:commandButton</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;loginEvent&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;Login&quot;</span> <span style="color: #000066;">action</span>=<span style="color: #ff0000;">&quot;#{compositeComponent.attributes.model.loginAction}&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;/h:commandButton<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;h:commandButton</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;cancelEvent&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;Cancel&quot;</span> <span style="color: #000066;">action</span>=<span style="color: #ff0000;">&quot;cancel&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:commandButton<span style="color: #000000; font-weight: bold;">&gt;</span></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>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/td<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/tr<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;tr<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;td<span style="color: #000000; font-weight: bold;">&gt;</span></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 login panel footer<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;composite:insertChildren</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/td<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/tr<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/tbody<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/table<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/composite:implementation<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>
<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></td></tr></table></div>

<p>Coloquei o código todo, mas o mais importante é da linha 12 até a linha 41, que é onde definimos as características do nosso componente. Isso deve facilitar que ferramentas deem suporte aos nossos componentes, e também a quem for usar esses componentes, pois damos mais informações a respeito das propriedades que ele precisa. A documentação diz que em muitos casos será possível construir componentes sem prover essas informações, deixando mais parecido com o que é hoje, mas diz também que falta definir um limite de até onde pode ser feito um componente sem especificar esse "contrato de uso".</p>
<p>Uma coisa interessante que pode ser vista nesse exemplo é a exigencia de um método chamado loginAction com uma assinatura específica dentro do objeto que for passado no atributo model.</p>
<p>O código que usa esse componente pode ser visto a seguir</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
</pre></td><td class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #00bbdd;">&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;&gt;</span>
<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: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: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:ez</span>=<span style="color: #ff0000;">&quot;http://java.sun.com/jsf/composite/ezcomp&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:head<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;title<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>The Simplest EZComp Demo That Could Possibly Work<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/title<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/h:head<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;h:body<span style="color: #000000; font-weight: bold;">&gt;</span></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>Login Panel Component<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;ui:debug</span> <span style="color: #000066;">hotkey</span>=<span style="color: #ff0000;">&quot;p&quot;</span> <span style="color: #000066;">rendered</span>=<span style="color: #ff0000;">&quot;true&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:form<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;">id</span>=<span style="color: #ff0000;">&quot;compositeComponent&quot;</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;grayBox&quot;</span> <span style="color: #000066;">style</span>=<span style="color: #ff0000;">&quot;border: 1px solid #090;&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;ez:loginPanel</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;loginPanelInConsumingPage&quot;</span> <span style="color: #000066;">model</span>=<span style="color: #ff0000;">&quot;#{bean}&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;f:valueChangeListener</span> <span style="color: #000066;">for</span>=<span style="color: #ff0000;">&quot;username&quot;</span> <span style="color: #000066;">binding</span>=<span style="color: #ff0000;">&quot;#{bean.useridValueChangeListener}&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:actionListener</span> <span style="color: #000066;">for</span>=<span style="color: #ff0000;">&quot;loginEvent&quot;</span> <span style="color: #000066;">binding</span>=<span style="color: #ff0000;">&quot;#{bean.loginEventListener}&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:actionListener</span> <span style="color: #000066;">for</span>=<span style="color: #ff0000;">&quot;cancelEvent&quot;</span> <span style="color: #000066;">binding</span>=<span style="color: #ff0000;">&quot;#{bean.cancelEventListener}&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:actionListener</span> <span style="color: #000066;">for</span>=<span style="color: #ff0000;">&quot;allEvents&quot;</span> <span style="color: #000066;">binding</span>=<span style="color: #ff0000;">&quot;#{bean.allEventsListener}&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;f:facet</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;header&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:panelGroup</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;headerFacetInConsumingPage&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:outputText</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;this is the header facet in the consuming page&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:panelGroup<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/f:facet<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;h:outputText</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;childInConsumingPage&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;this is a child component in the consuming page&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/ez:loginPanel<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;p<span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #000000; font-weight: bold;">&lt;h:commandButton</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;reload&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span><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;/h:form<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/h:body<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<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></td></tr></table></div>

<p>Nesse exemplo pode reparar da linha 18 a 21 que usamos os <strong>composite:actionSource</strong> definidos no componente como ganchos para pendurar nossos listeners.</p>
<p>Só lembrando que esses exemplos são em cima da EDR2 do JSF2, então tudo que foi visto aqui pode não ser igual ao que vai estar na versão final.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.gilliard.eti.br/2008/09/jsf-2-early-draft-review-2/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>
