<?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>Blog de desenvolvimento da Milfont Consulting, Client e Server-side &#187; JSON</title>
	<atom:link href="http://www.milfont.org/tech/category/web-development/json/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.milfont.org/tech</link>
	<description>Blog da Comunidade Milfont Consulting, uma empresa especializada em desenvolvimento Web, principalmente Javascript, node.js e muito Javascript.</description>
	<lastBuildDate>Thu, 26 Jan 2012 11:30:28 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>Extjs e DWR</title>
		<link>http://www.milfont.org/tech/2009/07/02/extjs-e-dwr/</link>
		<comments>http://www.milfont.org/tech/2009/07/02/extjs-e-dwr/#comments</comments>
		<pubDate>Thu, 02 Jul 2009 19:11:42 +0000</pubDate>
		<dc:creator>cmilfont</dc:creator>
				<category><![CDATA[Ajax]]></category>
		<category><![CDATA[DWR]]></category>
		<category><![CDATA[Ext]]></category>
		<category><![CDATA[Frameworks]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[JEE]]></category>
		<category><![CDATA[JSON]]></category>
		<category><![CDATA[Model 3]]></category>
		<category><![CDATA[RIA]]></category>
		<category><![CDATA[web2.0]]></category>
		<category><![CDATA[ExtJS]]></category>
		<category><![CDATA[MVC]]></category>

		<guid isPermaLink="false">http://www.milfont.org/tech/?p=705</guid>
		<description><![CDATA[Nesse artigo eu pretendo trabalhar dois conceitos principais de uso do Extjs, extensão/customização de componentes e acesso a dados server-side com base em experiência recente em um projeto que desenvolvemos. Esse projeto em questão é um ERP que tinha a necessidade de manter a usabilidade similar a sua versão antiga, feita em Delphi, para o [...]]]></description>
			<content:encoded><![CDATA[<p>Nesse artigo eu pretendo trabalhar dois conceitos principais de uso do <a href="http://www.milfont.org/tech/tag/extjs/">Extjs</a>, extensão/customização de componentes e acesso a dados server-side com base em experiência recente em um projeto que desenvolvemos. Esse projeto em questão é um ERP que tinha a necessidade de manter a usabilidade similar a sua versão antiga, feita em Delphi, para o desktop.</p>
<p>Para suprir essa necessidade de usabilidade tivemos que adotar alguns conceitos, como ser totalmente stateless e modificar a arquitetura MVC2 para o <a href="http://www.milfont.org/tech/2008/09/08/mvc-model-3-e-camadas/">MVC3</a>. No server-side trabalhamos com um domain model baseado em Hibernate, Spring e Facades e Services com DWR. Nada de frameworks MVC2, não nos preocupamos com renderização e sim com a API. No lado cliente usamos Extjs com algumas modificações que fiz para integrar de forma suave com o DWR.</p>
<p>Primeiro precisamos entender como o Extjs trabalha com herança. Basicamente há um método no objeto Ext que faz esse trabalho de extensão dos componentes, funciona da seguinte maneira:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">//Formato:</span>
<span style="color: #003366; font-weight: bold;">var</span> NovoComponente <span style="color: #339933;">=</span> Ext.<span style="color: #660066;">extend</span><span style="color: #009900;">&#40;</span>velhoComponente<span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span> 
          <span style="color: #009966; font-style: italic;">/* metodos e propriedades que serão reescritas */</span> 
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">//Exemplo:</span>
<span style="color: #003366; font-weight: bold;">var</span> MilfontGridPanel <span style="color: #339933;">=</span> Ext.<span style="color: #660066;">extend</span><span style="color: #009900;">&#40;</span>Ext.<span style="color: #660066;">grid</span>.<span style="color: #660066;">GridPanel</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #006600; font-style: italic;">//novo construtor</span>
        constructor<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>config<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #006600; font-style: italic;">// Seu preprocessamento vai aqui</span>
        	MilfontGridPanel.<span style="color: #660066;">superclass</span>.<span style="color: #660066;">constructor</span>.<span style="color: #660066;">apply</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #339933;">,</span> arguments<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #006600; font-style: italic;">// Seu pos-processamento vai aqui</span>
        <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
&nbsp;
        NovoMethod<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><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;">// algum novo método que você queira criar para o novo componente</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Para esse projeto, criei um Ext.data.DataProxy (<a href="http://www.milfont.org/tech/2009/06/29/introducao-ao-ext/">como visto no artigo passado</a>) especialista para o DWR, criativamente denominado DWRProxy. A idéia é modificar o comportamento de buscar os dados para usar um <a href="http://www.milfont.org/tech/tag/dwr/">Creator do DWR</a>.</p>
<p>Definimos primeiro o objeto e suas propriedades necessárias:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">Ext.<span style="color: #660066;">ux</span>.<span style="color: #660066;">data</span>.<span style="color: #660066;">DWRProxy</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>dwr_facade<span style="color: #339933;">,</span> dwr_filter<span style="color: #339933;">,</span> dwr_errorHandler<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
&nbsp;
    Ext.<span style="color: #660066;">ux</span>.<span style="color: #660066;">data</span>.<span style="color: #660066;">DWRProxy</span>.<span style="color: #660066;">superclass</span>.<span style="color: #660066;">constructor</span>.<span style="color: #660066;">call</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #009966; font-style: italic;">/* Propriedade que receberá a classe Java configurada como Creator */</span>
    <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">data</span> <span style="color: #339933;">=</span> dwr_facade<span style="color: #339933;">;</span>
    <span style="color: #006600; font-style: italic;">/*
	 * Propriedade que receberá uma classe java configurada como converter
	 * que servirá como filtro de busca
	 */</span>
&nbsp;
	<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">dwr_filter</span> <span style="color: #339933;">=</span> dwr_filter<span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #006600; font-style: italic;">/**
	 *
	 * Propriedade para fazer paginação, indica que deve cachear a consulta de
	 * total de elementos o controlador [fachada] deve implementar a logica de
	 * negocios adequada, quando for false consulta o total, quando for true
	 * consulta apenas a listagem e repete o total
	 */</span>
&nbsp;
	<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">dwr_total_cache</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">dwr_errorHandler</span> <span style="color: #339933;">=</span> dwr_errorHandler<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Após isso extendemos do Ext.data.DataProxy :</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">Ext.<span style="color: #660066;">extend</span><span style="color: #009900;">&#40;</span>Ext.<span style="color: #660066;">ux</span>.<span style="color: #660066;">data</span>.<span style="color: #660066;">DWRProxy</span><span style="color: #339933;">,</span> Ext.<span style="color: #660066;">data</span>.<span style="color: #660066;">DataProxy</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #006600; font-style: italic;">/**
     * Método Load do Ext.data.DataProxy overrided
     */</span>
&nbsp;
    load <span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>params<span style="color: #339933;">,</span> reader<span style="color: #339933;">,</span> callback<span style="color: #339933;">,</span> scope<span style="color: #339933;">,</span> arg<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #006600; font-style: italic;">/**
	 * Escopo &quot;this&quot; mapeado para a variável &quot;s&quot; porque dentro do callback do
	 * DWR o escopo &quot;this&quot; não pertence ao objeto Ext.ux.data.DWRProxy.
	 */</span>
&nbsp;
	<span style="color: #003366; font-weight: bold;">var</span> s <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">this</span><span style="color: #339933;">;</span>
&nbsp;
        params <span style="color: #339933;">=</span> params <span style="color: #339933;">||</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>params.<span style="color: #660066;">cache</span> <span style="color: #339933;">!=</span> undefined<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">dwr_total_cache</span> <span style="color: #339933;">=</span> params.<span style="color: #660066;">cache</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>params.<span style="color: #660066;">filter</span> <span style="color: #339933;">!=</span> undefined<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">dwr_filter</span> <span style="color: #339933;">=</span> params.<span style="color: #660066;">filter</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #003366; font-weight: bold;">var</span> result<span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000066; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">data</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">dwr_filter</span><span style="color: #339933;">,</span> params.<span style="color: #660066;">start</span><span style="color: #339933;">,</span> params.<span style="color: #660066;">limit</span><span style="color: #339933;">,</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">dwr_total_cache</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span>
			callback<span style="color: #339933;">:</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>response<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                                <span style="color: #006600; font-style: italic;">//aqui passamos o retorno do DWR </span>
                               <span style="color: #006600; font-style: italic;">// que chamei de response,  para o extjs</span>
				result <span style="color: #339933;">=</span> reader.<span style="color: #660066;">readRecords</span><span style="color: #009900;">&#40;</span>response<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				callback.<span style="color: #660066;">call</span><span style="color: #009900;">&#40;</span>scope<span style="color: #339933;">,</span> result<span style="color: #339933;">,</span> arg<span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
			errorHandler<span style="color: #339933;">:</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>a<span style="color: #339933;">,</span> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				scope.<span style="color: #660066;">fireEvent</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;loadexception&quot;</span><span style="color: #339933;">,</span> s<span style="color: #339933;">,</span> arg<span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">null</span><span style="color: #339933;">,</span> e<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				s.<span style="color: #660066;">dwr_errorHandler</span><span style="color: #009900;">&#40;</span>a<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
			timeout<span style="color: #339933;">:</span><span style="color: #CC0000;">100000</span>
		<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">dwr_total_cache</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">catch</span><span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">fireEvent</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;loadexception&quot;</span><span style="color: #339933;">,</span> <span style="color: #000066; font-weight: bold;">this</span><span style="color: #339933;">,</span> arg<span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">null</span><span style="color: #339933;">,</span> e<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            callback.<span style="color: #660066;">call</span><span style="color: #009900;">&#40;</span>scope<span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">null</span><span style="color: #339933;">,</span> arg<span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #000066; font-weight: bold;">return</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>A fachada DWR é uma classe comum, segue um exemplo de uso com Hibernate:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">//classe para satisfazer o transporte para o Extjs</span>
<span style="color: #003366; font-weight: bold;">public</span> final <span style="color: #003366; font-weight: bold;">class</span> DataTransferObject <span style="color: #009900;">&#123;</span>
    <span style="color: #003366; font-weight: bold;">private</span> int total<span style="color: #339933;">;</span>
    <span style="color: #003366; font-weight: bold;">private</span> List<span style="color: #339933;">&lt;?</span> <span style="color: #003366; font-weight: bold;">extends</span> Object<span style="color: #339933;">&gt;</span> results<span style="color: #339933;">;</span>
    <span style="color: #006600; font-style: italic;">//sets e gets</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">public</span> <span style="color: #003366; font-weight: bold;">class</span> AjaxFacade <span style="color: #009900;">&#123;</span>
    <span style="color: #006600; font-style: italic;">//injeta um repositorio, whatever</span>
    <span style="color: #003366; font-weight: bold;">private</span> Repository repository <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">null</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #003366; font-weight: bold;">public</span> DataTransferObject find<span style="color: #009900;">&#40;</span>Object filter<span style="color: #339933;">,</span> int start<span style="color: #339933;">,</span> int limit<span style="color: #339933;">,</span> boolean cache<span style="color: #339933;">,</span> HttpSession session<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        DataTransferObject dto <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> DataTransferObject<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #006600; font-style: italic;">//verifica se o Proxy está passando true </span>
        <span style="color: #006600; font-style: italic;">// indicando que está paginando</span>
        <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>cache<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            Integer total <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>Integer<span style="color: #009900;">&#41;</span> session.<span style="color: #660066;">getAttribute</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;totalObject&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            dto.<span style="color: #660066;">setTotal</span><span style="color: #009900;">&#40;</span>total<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
       <span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
            session.<span style="color: #660066;">removeAttribute</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;totalObject&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            Integer total <span style="color: #339933;">=</span> repository.<span style="color: #660066;">count</span><span style="color: #009900;">&#40;</span>filter<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            dto.<span style="color: #660066;">setTotal</span><span style="color: #009900;">&#40;</span>total<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            session.<span style="color: #660066;">setAttribute</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;totalObject&quot;</span><span style="color: #339933;">,</span> total<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        List<span style="color: #339933;">&lt;</span>Object<span style="color: #339933;">&gt;</span> retorno <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>List<span style="color: #339933;">&lt;</span>Object<span style="color: #339933;">&gt;</span><span style="color: #009900;">&#41;</span> repository.<span style="color: #660066;">find</span><span style="color: #009900;">&#40;</span>filter<span style="color: #339933;">,</span> start<span style="color: #339933;">,</span> limit<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        dto.<span style="color: #660066;">setResults</span><span style="color: #009900;">&#40;</span>retorno<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000066; font-weight: bold;">return</span> dto<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span></pre></div></div>

<p>Para o Grid visto no artigo passado, basta instanciar assim no javscript:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> store <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Ext.<span style="color: #660066;">data</span>.<span style="color: #660066;">Store</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
    proxy<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">new</span> Ext.<span style="color: #660066;">ux</span>.<span style="color: #660066;">data</span>.<span style="color: #660066;">DWRProxy</span><span style="color: #009900;">&#40;</span>
        AjaxFacade.<span style="color: #660066;">find</span><span style="color: #339933;">,</span> 
        <span style="color: #009900;">&#123;</span>$dwrClassName<span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;Project&quot;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> 
        errorHandler
    <span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
    reader<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">new</span> Ext.<span style="color: #660066;">data</span>.<span style="color: #660066;">JsonReader</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
            root<span style="color: #339933;">:</span> <span style="color: #3366CC;">'results'</span><span style="color: #339933;">,</span>totalProperty<span style="color: #339933;">:</span> <span style="color: #3366CC;">'total'</span><span style="color: #339933;">,</span>id<span style="color: #339933;">:</span> <span style="color: #3366CC;">'id'</span>
        <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> 
        <span style="color: #009900;">&#91;</span><span style="color: #3366CC;">'id'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'name'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'manager.name'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'manager.address.country'</span><span style="color: #009900;">&#93;</span>
    <span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Para entender o<em> {$dwrClassName:&#8221;Project&#8221;}</em> <a href="http://www.milfont.org/tech/2008/12/24/dwr-3-release-candidate-1/">visite esse post</a>.</p>
<p>Dessa forma o DWR se torna um proxy para todos os componentes do Extjs.</p>
<p>Código fonte da modificação do javascript eu <a href="http://github.com/cmilfont/MilfontExtjs/tree/master">coloquei aqui no github</a> e uma <a href="https://github.com/cmilfont/example-dwr-extjs/tree">aplicação demo aqui</a>. No próximo vou integrar o DWR com o Rails, aguardem que sai logo&#8230; ou não.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.milfont.org/tech/2009/07/02/extjs-e-dwr/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Introdução ao Ext</title>
		<link>http://www.milfont.org/tech/2009/06/29/introducao-ao-ext/</link>
		<comments>http://www.milfont.org/tech/2009/06/29/introducao-ao-ext/#comments</comments>
		<pubDate>Mon, 29 Jun 2009 13:38:32 +0000</pubDate>
		<dc:creator>cmilfont</dc:creator>
				<category><![CDATA[(X)HTML]]></category>
		<category><![CDATA[Ajax]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[Ext]]></category>
		<category><![CDATA[Frameworks]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[JSON]]></category>
		<category><![CDATA[RIA]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[web2.0]]></category>
		<category><![CDATA[XMLHttpRequest]]></category>
		<category><![CDATA[ECMAScript]]></category>
		<category><![CDATA[ExtJS]]></category>
		<category><![CDATA[Orientação a Objetos]]></category>
		<category><![CDATA[widget]]></category>
		<category><![CDATA[YUI]]></category>

		<guid isPermaLink="false">http://www.milfont.org/tech/?p=24</guid>
		<description><![CDATA[Eu trabalho com Extjs desde que ele era uma extensão para o YUI, ainda hoje há aplicação no ar usando essa antiga tecnologia [por problema causado por algum idiota, você provavelmente será redirecionado para outro site do governo, dá uma olhada no canto esquerdo superior e clique em "IR PARA A SEPLAG"]. Para ver o [...]]]></description>
			<content:encoded><![CDATA[<p>Eu trabalho com <a href="http://www.extjs.com/products/extjs/">Extjs</a> desde que ele era uma extensão para o <a href="http://developer.yahoo.com/yui/">YUI</a>, ainda hoje <a href="http://www.seplag.ce.gov.br/seplag/categoria2/diario-oficial">há aplicação no ar</a> usando essa antiga tecnologia [por problema <a href="http://www.milfont.org/tech/2009/03/25/como-simular-trabalho-no-estado/">causado por algum idiota</a>, você provavelmente será redirecionado para outro site do governo, dá uma olhada no canto esquerdo superior e clique em "<strong>IR PARA A SEPLAG</strong>"]. Para ver o Extjs no tempo que ele se chamava ext-yui, vá no link de pesquisa avançada, preencha o input descrição em &#8220;dados da matéria&#8221; com &#8220;secretaria de cultura&#8221; por exemplo e clique no botão pesquisar.</p>
<p>Esse tutorial tem o objetivo de preparar o conhecimento para outros posts que estou escrevendo e achei necessário uma introdução apenas nos conceitos do Extjs para não confundir com as tecnologias que uso em conjunto como <a href="http://www.milfont.org/tech/tag/dwr/">DWR</a> ou no modelo <a href="http://www.milfont.org/tech/tag/rest/">REST</a> com o <a href="http://www.milfont.org/tech/tag/rails/">RubyOnRails</a>.</p>
<p>O Extjs é um <a href="http://www.milfont.org/tech/2007/10/11/frameworks-ajax/">framework javascript de propósito geral</a>, ou seja, tem um conjunto de funcionalidades que tratam <a href="http://www.milfont.org/tech/tag/ajax/">Ajax</a>, um conjunto de Widgets bem elaborados [componentes visuais como Grid e TabPanel], manipulação de DOM [Document Object Model] e BOM [Browser Object Model], tratamento de eventos, animações como Fade In e Fade Out, parser de <a href="http://www.milfont.org/tech/2007/11/04/o-que-e-json/">JSON</a>, entre outras coisas. Seus componentes são construídos com técnicas modernas de<a href="http://www.milfont.org/tech/2008/01/05/heranca-no-javascript/"> orientação</a> a <a href="http://www.milfont.org/tech/2007/10/01/overloading-e-overriding-no-javascript/">objetos</a> no javascript e manipulação de <a href="http://www.milfont.org/tech/2007/10/08/script-tag/">Scripttag</a> para recursos remotos que não suportam Ajax.</p>
<h2>Preparação</h2>
<p>Após <a href="http://www.extjs.com/products/extjs/download.php">baixar e descompactar</a> o framework [estou trabalhando na versão 2.x que é estável nessa data], recomendo que deixa a disposição das pastas conforme se encontra e coloque no seu projeto de forma que seja acessível via web, já vem com documentação e exemplos que você deve e vai usar durante o desenvolvimento. Temos a <a href="http://www.extjs.com/products/extjs/build/">opção de montar o Extjs</a> [marcando a opção "<em>Make build available via CacheFly</em>" ] no <a href="http://cachefly.com/">CacheFly</a> como um servidor <a href="http://en.wikipedia.org/wiki/Content_Delivery_Network">CDN</a> para <a href="http://www.milfont.org/tech/2007/10/10/otimizando-wordpress-com-yslow/">otimizar o tráfego</a> de sua aplicação principalmente se ela será disponibilizada na internet e não apenas na intranet.</p>
<p>É necessário importar o CSS global, o adapter e o Javascript global conforme mostrado abaixo:</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;link rel=&quot;stylesheet&quot; type=&quot;text/css&quot; href=&quot;/javascripts/ext-2.2.1/resources/css/ext-all.css&quot; /&gt;
&lt;script src=&quot;/javascripts/ext-2.2.1/adapter/ext/ext-base.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;
&lt;script src=&quot;/javascripts/ext-2.2.1/ext-all.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;</pre></div></div>

<p>Pode usar outros temas para o Extjs, estarão na pasta &#8220;<em>resources/css</em>&#8220;, assim como podemos internacionalizar os componentes com arquivos que se encontram em &#8220;<em>build/locale</em>&#8220;. Exemplo com o tema &#8220;Gray&#8221; e <a href="http://en.wikipedia.org/wiki/Internationalization_and_localization">i18n</a> em português do Brasil:</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;link rel=&quot;stylesheet&quot; type=&quot;text/css&quot; href=&quot;/javascripts/ext-2.2.1/resources/css/ext-all.css&quot; /&gt;
&lt;link rel=&quot;stylesheet&quot; type=&quot;text/css&quot; href=&quot;/javascripts/ext-2.2.1/resources/css/xtheme-gray.css&quot;&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;/javascripts/ext-2.2.1/adapter/ext/ext-base.js&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;/javascripts/ext-2.2.1/ext-all.js&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;/javascripts/ext-2.2.1/build/locale/ext-lang-pt_BR-min.js&quot;&gt;&lt;/script&gt;</pre></div></div>

<p>Internacionalização é algo pensado no Extjs de forma a facilitar a criação de arquivos de linguagem aproveitando a estrutura da linguagem [dinâmica e fracamente tipada], todas as propriedades de mensagens e textos são públicas para facilitar a reescrita como mostrado abaixo na i18n do componente de DataPicker:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>Ext.<span style="color: #660066;">DatePicker</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
   Ext.<span style="color: #660066;">apply</span><span style="color: #009900;">&#40;</span>Ext.<span style="color: #660066;">DatePicker</span>.<span style="color: #660066;">prototype</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span>
      todayText         <span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;Hoje&quot;</span><span style="color: #339933;">,</span>
      minText           <span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;Esta data &amp;eacute; anterior a menor data&quot;</span><span style="color: #339933;">,</span>
      maxText           <span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;Esta data &amp;eacute; posterior a maior data&quot;</span><span style="color: #339933;">,</span>
      disabledDaysText  <span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;&quot;</span><span style="color: #339933;">,</span>
      disabledDatesText <span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;&quot;</span><span style="color: #339933;">,</span>
      monthNames        <span style="color: #339933;">:</span> Date.<span style="color: #660066;">monthNames</span><span style="color: #339933;">,</span>
      dayNames          <span style="color: #339933;">:</span> Date.<span style="color: #660066;">dayNames</span><span style="color: #339933;">,</span>
      nextText          <span style="color: #339933;">:</span> <span style="color: #3366CC;">'Pr&amp;oacute;ximo M&amp;ecirc;s (Control+Direita)'</span><span style="color: #339933;">,</span>
      prevText          <span style="color: #339933;">:</span> <span style="color: #3366CC;">'M&amp;ecirc;s Anterior (Control+Esquerda)'</span><span style="color: #339933;">,</span>
      monthYearText     <span style="color: #339933;">:</span> <span style="color: #3366CC;">'Escolha um M&amp;ecirc;s (Control+Cima/Baixo para mover entre os anos)'</span><span style="color: #339933;">,</span>
      todayTip          <span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;{0} (Espa&amp;ccedil;o)&quot;</span><span style="color: #339933;">,</span>
      format            <span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;d/m/Y&quot;</span><span style="color: #339933;">,</span>
      okText            <span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;&amp;#160;OK&amp;#160;&quot;</span><span style="color: #339933;">,</span>
      cancelText        <span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;Cancelar&quot;</span><span style="color: #339933;">,</span>
      startDay          <span style="color: #339933;">:</span> <span style="color: #CC0000;">0</span>
   <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>Se você usar o CacheFly gerado pela página do Extjs, ele incluir o adapter e o global em um mesmo arquivo, vai ser algo como:</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;link rel=&quot;stylesheet&quot; type=&quot;text/css&quot; href=&quot;http://extjs.cachefly.net/ext-2.2.1/resources/css/ext-all.css&quot;&gt;
&lt;link rel=&quot;stylesheet&quot; type=&quot;text/css&quot; href=&quot;http://extjs.cachefly.net/ext-2.2.1/resources/css/xtheme-gray.css&quot;&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;http://extjs.cachefly.net/builds/ext-cdn-771.js&quot;&gt;&lt;/script&gt;</pre></div></div>

<h2>Adapter</h2>
<p>Quando o Extjs passou a ser um framework independente do YUI, passou a adotar outros frameworks como base para funções básicas de manipulação de DOM e Ajax, hoje suporta trabalhar em conjunto com YUI, JQuery, Prototype e totalmente independente. Se o projeto já tem Jquery ou outro framework que trabalha com o Extjs, a utilização dos dois é muito fácil e indicada, principalmente para usar os widgets que são provavelmente os mais poderosos hoje em dia em um framework opensource.</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">//Exemplos de adapters permitidos
&lt;script type=&quot;text/javascript&quot; src=&quot;/javascripts/ext-2.2.1/adapter/ext/ext-base.js&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;/javascripts/ext-2.2.1/adapter/jquery/ext-jquery-adapter.js&quot;&gt;&lt;/script&gt;</pre></div></div>

<h2>Widgets</h2>
<p>O principal apelo do Extjs que conquista os desenvolvedores é o layout bem trabalhado dos componentes visuais que são de fácil parametrização. Basicamente todos os componentes funcionam da mesma forma, você o instancia passando um <a href="http://www.milfont.org/tech/2007/11/04/o-que-e-json/">objeto literal</a> de configuração com mostrado abaixo:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">//Exemplo do grid</span>
<span style="color: #003366; font-weight: bold;">var</span> grid  <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Ext.<span style="color: #660066;">grid</span>.<span style="color: #660066;">GridPanel</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
autoShow<span style="color: #339933;">:</span><span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">,</span> width<span style="color: #339933;">:</span><span style="color: #CC0000;">750</span><span style="color: #339933;">,</span>height<span style="color: #339933;">:</span><span style="color: #CC0000;">250</span> <span style="color: #006600; font-style: italic;">//mais parametros </span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #006600; font-style: italic;">//Exemplo de uma Window</span>
<span style="color: #003366; font-weight: bold;">var</span> window <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Ext.<span style="color: #660066;">Window</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
autoShow<span style="color: #339933;">:</span><span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">,</span> width<span style="color: #339933;">:</span><span style="color: #CC0000;">750</span><span style="color: #339933;">,</span>height<span style="color: #339933;">:</span><span style="color: #CC0000;">250</span> <span style="color: #006600; font-style: italic;">//mais parametros </span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #006600; font-style: italic;">//Exemplo de um Painel</span>
<span style="color: #003366; font-weight: bold;">var</span> panel <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Ext.<span style="color: #660066;">Panel</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
autoShow<span style="color: #339933;">:</span><span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">,</span> width<span style="color: #339933;">:</span><span style="color: #CC0000;">750</span><span style="color: #339933;">,</span>height<span style="color: #339933;">:</span><span style="color: #CC0000;">250</span> <span style="color: #006600; font-style: italic;">//mais parametros </span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Vamos usar o GRID para exemplificar como trabalhamos com o Extjs, o mesmo comportamente se repete em todos os componentes.<br />
A <a href="http://www.extjs.com/deploy/dev/docs/">documentação do Extjs</a> é muito bem feita e praticamente vai ser a única coisa que você vai precisar depois de entender como os componentes são formados, afinal não vale a pena decorar todas as propriedades de todos os componentes, concentre-se apenas em entender os conceitos.</p>
<p>A GRID é o Widget mais famoso desse framework e é formado basicamente por um objeto &#8220;<strong>Ext.data.Store</strong>&#8221; [que é a fonte de dados da GRID] e um objeto &#8220;<strong>Ext.grid.ColumnModel</strong>&#8221; [que é a definição das colunas], como mostrado abaixo:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> grid  <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Ext.<span style="color: #660066;">grid</span>.<span style="color: #660066;">GridPanel</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
    autoShow<span style="color: #339933;">:</span><span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">,</span> width<span style="color: #339933;">:</span><span style="color: #CC0000;">750</span><span style="color: #339933;">,</span>height<span style="color: #339933;">:</span><span style="color: #CC0000;">250</span><span style="color: #339933;">,</span> <span style="color: #006600; font-style: italic;">//parametros de configuração de layout</span>
    cm<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">new</span> Ext.<span style="color: #660066;">grid</span>.<span style="color: #660066;">ColumnModel</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span><span style="color: #006600; font-style: italic;">/*configuração*/</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
    store<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">new</span> Ext.<span style="color: #660066;">data</span>.<span style="color: #660066;">Store</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #006600; font-style: italic;">//Ou especialização de um Store</span>
    sm<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">new</span> Ext.<span style="color: #660066;">grid</span>.<span style="color: #660066;">RowSelectionModel</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>singleSelect<span style="color: #339933;">:</span><span style="color: #003366; font-weight: bold;">true</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #006600; font-style: italic;">//ou outra especialização de um AbstractSelectionModel</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>O objeto ColumnModel é a definição de colunas do Grid, possui propriedades para definição de layout como largura e altura, título da coluna como vai ser exibida e formatação do texto:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> colModel <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Ext.<span style="color: #660066;">grid</span>.<span style="color: #660066;">ColumnModel</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#91;</span>
    <span style="color: #009900;">&#123;</span> header<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;Ticker&quot;</span><span style="color: #339933;">,</span> width<span style="color: #339933;">:</span> <span style="color: #CC0000;">60</span><span style="color: #339933;">,</span> sortable<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
    <span style="color: #009900;">&#123;</span> header<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;Company Name&quot;</span><span style="color: #339933;">,</span> width<span style="color: #339933;">:</span> <span style="color: #CC0000;">150</span><span style="color: #339933;">,</span> sortable<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
    <span style="color: #009900;">&#123;</span> header<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;Market Cap.&quot;</span><span style="color: #339933;">,</span> width<span style="color: #339933;">:</span> <span style="color: #CC0000;">100</span><span style="color: #339933;">,</span> sortable<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
    <span style="color: #009900;">&#123;</span> header<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;$ Sales&quot;</span><span style="color: #339933;">,</span> width<span style="color: #339933;">:</span> <span style="color: #CC0000;">100</span><span style="color: #339933;">,</span> sortable<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">,</span> renderer<span style="color: #339933;">:</span> money<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
    <span style="color: #009900;">&#123;</span> header<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;Employees&quot;</span><span style="color: #339933;">,</span> width<span style="color: #339933;">:</span> <span style="color: #CC0000;">100</span><span style="color: #339933;">,</span> sortable<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">,</span> resizable<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #009900;">&#125;</span>
 <span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>A propriedade cm [ColumnModel] pode ser também substituída pela propriedade &#8220;columns&#8221; que funciona como um &#8220;alias&#8221;, dessa forma o Grid cria automaticamente um objeto ColumnModel:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> grid <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Ext.<span style="color: #660066;">grid</span>.<span style="color: #660066;">GridPanel</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
    columns<span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span>
        <span style="color: #009900;">&#123;</span>id<span style="color: #339933;">:</span><span style="color: #3366CC;">'id'</span><span style="color: #339933;">,</span> header<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;id&quot;</span><span style="color: #339933;">,</span> width<span style="color: #339933;">:</span> <span style="color: #CC0000;">200</span><span style="color: #339933;">,</span> sortable<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">,</span> dataIndex<span style="color: #339933;">:</span> <span style="color: #3366CC;">'id'</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
        <span style="color: #009900;">&#123;</span>header<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;Nome&quot;</span><span style="color: #339933;">,</span> width<span style="color: #339933;">:</span> <span style="color: #CC0000;">120</span><span style="color: #339933;">,</span> sortable<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">,</span> dataIndex<span style="color: #339933;">:</span> <span style="color: #3366CC;">'name'</span><span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#93;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Caso haja necessidade de formatar o conteúdo da célula, você pode usar uma função como &#8220;renderer&#8221; para tratar esse conteúdo:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> grid <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Ext.<span style="color: #660066;">grid</span>.<span style="color: #660066;">GridPanel</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
    columns<span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span>
        <span style="color: #009900;">&#123;</span>id<span style="color: #339933;">:</span><span style="color: #3366CC;">'id'</span><span style="color: #339933;">,</span> header<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;id&quot;</span><span style="color: #339933;">,</span> width<span style="color: #339933;">:</span> <span style="color: #CC0000;">200</span><span style="color: #339933;">,</span> sortable<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">,</span> dataIndex<span style="color: #339933;">:</span> <span style="color: #3366CC;">'id'</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
        <span style="color: #009900;">&#123;</span>header<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;Nome&quot;</span><span style="color: #339933;">,</span> width<span style="color: #339933;">:</span> <span style="color: #CC0000;">120</span><span style="color: #339933;">,</span> sortable<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">,</span> dataIndex<span style="color: #339933;">:</span> <span style="color: #3366CC;">'name'</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
        <span style="color: #009900;">&#123;</span>header<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;Criado em&quot;</span><span style="color: #339933;">,</span> width<span style="color: #339933;">:</span> <span style="color: #CC0000;">135</span><span style="color: #339933;">,</span> sortable<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">,</span> renderer<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>value<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                    <span style="color: #000066; font-weight: bold;">return</span> Date.<span style="color: #660066;">parseDate</span><span style="color: #009900;">&#40;</span>value<span style="color: #339933;">,</span> <span style="color: #3366CC;">'Y-m-d<span style="color: #000099; font-weight: bold;">\\</span>TH:i:s<span style="color: #000099; font-weight: bold;">\\</span>Z'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">format</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'d/m/Y H:i:s'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                    <span style="color: #006600; font-style: italic;">//2009-06-14T12:51:07Z</span>
        <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> dataIndex<span style="color: #339933;">:</span> <span style="color: #3366CC;">'created_at'</span><span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#93;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>A propriedade &#8220;<strong>store</strong>&#8221; da GRID é uma especialização do componente &#8220;<strong>Ext.data.Store</strong>&#8221; que é formado basicamente por um &#8220;<strong>proxy</strong>&#8221; e um &#8220;<strong>reader</strong>&#8220;:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> store <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Ext.<span style="color: #660066;">data</span>.<span style="color: #660066;">Store</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
    proxy<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">new</span> Ext.<span style="color: #660066;">data</span>.<span style="color: #660066;">DataProxy</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #006600; font-style: italic;">//ou uma especialização</span>
    reader<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">new</span> Ext.<span style="color: #660066;">data</span>.<span style="color: #660066;">DataReader</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #006600; font-style: italic;">//ou uma especialização</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>O &#8220;<strong>proxy</strong>&#8221; é o componente que obterá os dados e o &#8220;<strong>reader</strong>&#8221; o componente que fará a leitura desses dados para um formato comum a todos os componentes do Extjs na forma de um objeto denominado &#8220;<strong>Ext.data.Record</strong>&#8220;. O objeto &#8220;Record&#8221; representa um registro de dados e é usado seja para GRID, para um Form ou qualquer componente que trabalhe com dados editáveis.</p>
<p>Dessa forma podemos usar uma combinação de Proxy e Reader como HttpProxy e JsonReader:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> store <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Ext.<span style="color: #660066;">data</span>.<span style="color: #660066;">Store</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
    proxy<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">new</span> Ext.<span style="color: #660066;">data</span>.<span style="color: #660066;">HttpProxy</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
        url<span style="color: #339933;">:</span> <span style="color: #3366CC;">'projects.json'</span>
    <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
    reader<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">new</span> Ext.<span style="color: #660066;">data</span>.<span style="color: #660066;">JsonReader</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
        totalProperty<span style="color: #339933;">:</span><span style="color: #3366CC;">'total'</span><span style="color: #339933;">,</span>
        root<span style="color: #339933;">:</span><span style="color: #3366CC;">'results'</span><span style="color: #339933;">,</span>id<span style="color: #339933;">:</span><span style="color: #3366CC;">'id'</span>
    <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> Ext.<span style="color: #660066;">data</span>.<span style="color: #660066;">Record</span>.<span style="color: #660066;">create</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#91;</span>
        <span style="color: #009900;">&#123;</span><span style="color: #000066;">name</span><span style="color: #339933;">:</span><span style="color: #3366CC;">'id'</span><span style="color: #339933;">,</span> mapping<span style="color: #339933;">:</span><span style="color: #3366CC;">'id'</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
        <span style="color: #009900;">&#123;</span><span style="color: #000066;">name</span><span style="color: #339933;">:</span><span style="color: #3366CC;">'name'</span><span style="color: #339933;">,</span> mapping<span style="color: #339933;">:</span><span style="color: #3366CC;">'name'</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
        <span style="color: #009900;">&#123;</span><span style="color: #000066;">name</span><span style="color: #339933;">:</span><span style="color: #3366CC;">'created_at'</span><span style="color: #339933;">,</span> mapping<span style="color: #339933;">:</span><span style="color: #3366CC;">'created_at'</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
        <span style="color: #009900;">&#123;</span><span style="color: #000066;">name</span><span style="color: #339933;">:</span><span style="color: #3366CC;">'updated_at'</span><span style="color: #339933;">,</span> mapping<span style="color: #339933;">:</span><span style="color: #3366CC;">'updated_at'</span><span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Devido o costume do uso do HttpProxy, o componente Store possui uma propriedade chamada &#8220;url&#8221; que estando presente cria um HttpProxy automaticamente como mostrado abaixo:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> store <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Ext.<span style="color: #660066;">data</span>.<span style="color: #660066;">Store</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
    url<span style="color: #339933;">:</span> <span style="color: #3366CC;">'projects.json'</span><span style="color: #339933;">,</span>
    reader<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">new</span> Ext.<span style="color: #660066;">data</span>.<span style="color: #660066;">JsonReader</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
        totalProperty<span style="color: #339933;">:</span><span style="color: #3366CC;">'total'</span><span style="color: #339933;">,</span>
        root<span style="color: #339933;">:</span><span style="color: #3366CC;">'results'</span><span style="color: #339933;">,</span>id<span style="color: #339933;">:</span><span style="color: #3366CC;">'id'</span>
    <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> Ext.<span style="color: #660066;">data</span>.<span style="color: #660066;">Record</span>.<span style="color: #660066;">create</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#91;</span>
        <span style="color: #009900;">&#123;</span><span style="color: #000066;">name</span><span style="color: #339933;">:</span><span style="color: #3366CC;">'id'</span><span style="color: #339933;">,</span> mapping<span style="color: #339933;">:</span><span style="color: #3366CC;">'id'</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
        <span style="color: #009900;">&#123;</span><span style="color: #000066;">name</span><span style="color: #339933;">:</span><span style="color: #3366CC;">'name'</span><span style="color: #339933;">,</span> mapping<span style="color: #339933;">:</span><span style="color: #3366CC;">'name'</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
        <span style="color: #009900;">&#123;</span><span style="color: #000066;">name</span><span style="color: #339933;">:</span><span style="color: #3366CC;">'created_at'</span><span style="color: #339933;">,</span> mapping<span style="color: #339933;">:</span><span style="color: #3366CC;">'created_at'</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
        <span style="color: #009900;">&#123;</span><span style="color: #000066;">name</span><span style="color: #339933;">:</span><span style="color: #3366CC;">'updated_at'</span><span style="color: #339933;">,</span> mapping<span style="color: #339933;">:</span><span style="color: #3366CC;">'updated_at'</span><span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>O objeto &#8220;<strong>Reader</strong>&#8221; é o único que foge um pouco a regra de instanciação por receber dois parâmetros, um similar aos outros com um objeto literal de configuração e outro com o mapeamento dos dados. O objeto de configuração tem duas propriedades de que representam o total e a lista de dados. O objeto de mapeamento usa um método &#8220;estático&#8221; do objeto Record para criar um link entre a propriedade do json [com a propriedade "mapping"] e o índice interno do Record [pela propriedade "name"].</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"> <span style="color: #003366; font-weight: bold;">new</span> Ext.<span style="color: #660066;">data</span>.<span style="color: #660066;">JsonReader</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
        totalProperty<span style="color: #339933;">:</span><span style="color: #3366CC;">'total'</span><span style="color: #339933;">,</span>
        root<span style="color: #339933;">:</span><span style="color: #3366CC;">'results'</span><span style="color: #339933;">,</span>id<span style="color: #339933;">:</span><span style="color: #3366CC;">'id'</span>
    <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> Ext.<span style="color: #660066;">data</span>.<span style="color: #660066;">Record</span>.<span style="color: #660066;">create</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#91;</span>
        <span style="color: #009900;">&#123;</span><span style="color: #000066;">name</span><span style="color: #339933;">:</span><span style="color: #3366CC;">'id'</span><span style="color: #339933;">,</span> mapping<span style="color: #339933;">:</span><span style="color: #3366CC;">'id'</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
        <span style="color: #009900;">&#123;</span><span style="color: #000066;">name</span><span style="color: #339933;">:</span><span style="color: #3366CC;">'name'</span><span style="color: #339933;">,</span> mapping<span style="color: #339933;">:</span><span style="color: #3366CC;">'name'</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
        <span style="color: #009900;">&#123;</span><span style="color: #000066;">name</span><span style="color: #339933;">:</span><span style="color: #3366CC;">'created_at'</span><span style="color: #339933;">,</span> mapping<span style="color: #339933;">:</span><span style="color: #3366CC;">'created_at'</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
        <span style="color: #009900;">&#123;</span><span style="color: #000066;">name</span><span style="color: #339933;">:</span><span style="color: #3366CC;">'updated_at'</span><span style="color: #339933;">,</span> mapping<span style="color: #339933;">:</span><span style="color: #3366CC;">'updated_at'</span><span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span></pre></div></div>

<p>Dessa forma você tem um link entre o ColumnName pela propriedade dataIndex e o Store por meio do Reader, como abaixo:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">Ext.<span style="color: #660066;">data</span>.<span style="color: #660066;">Record</span>.<span style="color: #660066;">create</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#91;</span>
         <span style="color: #009900;">&#123;</span><span style="color: #000066;">name</span><span style="color: #339933;">:</span><span style="color: #3366CC;">'nome_linkado'</span><span style="color: #339933;">,</span> mapping<span style="color: #339933;">:</span><span style="color: #3366CC;">'name'</span><span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span>
<span style="color: #006600; font-style: italic;">//</span>
 columns<span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span>
        <span style="color: #009900;">&#123;</span>header<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;Nome&quot;</span><span style="color: #339933;">,</span> width<span style="color: #339933;">:</span> <span style="color: #CC0000;">120</span><span style="color: #339933;">,</span> sortable<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">,</span> dataIndex<span style="color: #339933;">:</span> <span style="color: #3366CC;">'nome_linkado'</span><span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#93;</span></pre></div></div>

<p>Para melhorar a navegação da GRID, você pode também acrescentar um componente de Toolbar no header ou no footer:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> grid  <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Ext.<span style="color: #660066;">grid</span>.<span style="color: #660066;">GridPanel</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
    autoShow<span style="color: #339933;">:</span><span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">,</span> width<span style="color: #339933;">:</span><span style="color: #CC0000;">750</span><span style="color: #339933;">,</span>height<span style="color: #339933;">:</span><span style="color: #CC0000;">250</span><span style="color: #339933;">,</span> <span style="color: #006600; font-style: italic;">//parametros de configuração de layout</span>
    cm<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">new</span> Ext.<span style="color: #660066;">grid</span>.<span style="color: #660066;">ColumnModel</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span><span style="color: #006600; font-style: italic;">/*configuração*/</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
    store<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">new</span> Ext.<span style="color: #660066;">data</span>.<span style="color: #660066;">Store</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #006600; font-style: italic;">//Ou especialização de um Store</span>
    sm<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">new</span> Ext.<span style="color: #660066;">grid</span>.<span style="color: #660066;">RowSelectionModel</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>singleSelect<span style="color: #339933;">:</span><span style="color: #003366; font-weight: bold;">true</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
    bbar<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">new</span> Ext.<span style="color: #660066;">Toolbar</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #006600; font-style: italic;">//Bottom Toolbar</span>
    tbar<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">new</span> Ext.<span style="color: #660066;">Toolbar</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #006600; font-style: italic;">//Top Toolbar</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>A Toolbar mais usada é sua especialização com paginação, a Ext.PagingToolbar que necessita ser linkada com o Store:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">new</span> Ext.<span style="color: #660066;">PagingToolbar</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
    pageSize<span style="color: #339933;">:</span><span style="color: #CC0000;">10</span><span style="color: #339933;">,</span> <span style="color: #006600; font-style: italic;">//propriedade opcional, default é 20</span>
    store<span style="color: #339933;">:</span> store
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span></pre></div></div>

<p>A PagingToolbar é I18n, mas se as mensagens não agradarem você pode mudá-las [eu sempre faço]:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">new</span> Ext.<span style="color: #660066;">PagingToolbar</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
    pageSize<span style="color: #339933;">:</span><span style="color: #CC0000;">10</span><span style="color: #339933;">,</span>store<span style="color: #339933;">:</span> store<span style="color: #339933;">,</span>
    displayInfo<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">,</span>	
    displayMsg<span style="color: #339933;">:</span> <span style="color: #3366CC;">'Exibindo o resultado: {0} a {1} de {2} registros'</span><span style="color: #339933;">,</span>
    emptyMsg<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;Sem resultados a exibir&quot;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span></pre></div></div>

<p>Uma coisa bacana nesse componente é que você pode agrupar botões [já que é uma Toolbar] e até padronizar o layout:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">new</span> Ext.<span style="color: #660066;">PagingToolbar</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
    pageSize<span style="color: #339933;">:</span><span style="color: #CC0000;">10</span><span style="color: #339933;">,</span>store<span style="color: #339933;">:</span> store<span style="color: #339933;">,</span>
    displayInfo<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">,</span>	
    displayMsg<span style="color: #339933;">:</span> <span style="color: #3366CC;">'Exibindo o resultado: {0} a {1} de {2} registros'</span><span style="color: #339933;">,</span>
    emptyMsg<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;Sem resultados a exibir&quot;</span><span style="color: #339933;">,</span>
    items<span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span><span style="color: #3366CC;">'-'</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span>
        pressed<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">,</span>enableToggle<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">,</span>text<span style="color: #339933;">:</span> <span style="color: #3366CC;">'Alterar'</span><span style="color: #339933;">,</span>
        toggleHandler<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span>
        pressed<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">,</span>enableToggle<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">,</span>text<span style="color: #339933;">:</span> <span style="color: #3366CC;">'Excluir'</span><span style="color: #339933;">,</span>
        toggleHandler<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#93;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span></pre></div></div>

<p>Código da GRID inteira:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">&nbsp;
<span style="color: #003366; font-weight: bold;">var</span> store <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Ext.<span style="color: #660066;">data</span>.<span style="color: #660066;">Store</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
    proxy<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">new</span> Ext.<span style="color: #660066;">data</span>.<span style="color: #660066;">HttpProxy</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
        url<span style="color: #339933;">:</span> <span style="color: #3366CC;">'projects.json'</span>
    <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
    reader<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">new</span> Ext.<span style="color: #660066;">data</span>.<span style="color: #660066;">JsonReader</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
        totalProperty<span style="color: #339933;">:</span><span style="color: #3366CC;">'total'</span><span style="color: #339933;">,</span>
        root<span style="color: #339933;">:</span><span style="color: #3366CC;">'results'</span><span style="color: #339933;">,</span>id<span style="color: #339933;">:</span><span style="color: #3366CC;">'id'</span>
    <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> Ext.<span style="color: #660066;">data</span>.<span style="color: #660066;">Record</span>.<span style="color: #660066;">create</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#91;</span>
        <span style="color: #009900;">&#123;</span><span style="color: #000066;">name</span><span style="color: #339933;">:</span><span style="color: #3366CC;">'id'</span><span style="color: #339933;">,</span> mapping<span style="color: #339933;">:</span><span style="color: #3366CC;">'id'</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
        <span style="color: #009900;">&#123;</span><span style="color: #000066;">name</span><span style="color: #339933;">:</span><span style="color: #3366CC;">'name'</span><span style="color: #339933;">,</span> mapping<span style="color: #339933;">:</span><span style="color: #3366CC;">'name'</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
        <span style="color: #009900;">&#123;</span><span style="color: #000066;">name</span><span style="color: #339933;">:</span><span style="color: #3366CC;">'created_at'</span><span style="color: #339933;">,</span> mapping<span style="color: #339933;">:</span><span style="color: #3366CC;">'created_at'</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
        <span style="color: #009900;">&#123;</span><span style="color: #000066;">name</span><span style="color: #339933;">:</span><span style="color: #3366CC;">'updated_at'</span><span style="color: #339933;">,</span> mapping<span style="color: #339933;">:</span><span style="color: #3366CC;">'updated_at'</span><span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">var</span> colModel <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Ext.<span style="color: #660066;">grid</span>.<span style="color: #660066;">ColumnModel</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#91;</span>
    <span style="color: #009900;">&#123;</span>id<span style="color: #339933;">:</span><span style="color: #3366CC;">'id'</span><span style="color: #339933;">,</span> header<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;id&quot;</span><span style="color: #339933;">,</span> width<span style="color: #339933;">:</span> <span style="color: #CC0000;">200</span><span style="color: #339933;">,</span> sortable<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">,</span> dataIndex<span style="color: #339933;">:</span> <span style="color: #3366CC;">'id'</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
    <span style="color: #009900;">&#123;</span>header<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;Nome&quot;</span><span style="color: #339933;">,</span> width<span style="color: #339933;">:</span> <span style="color: #CC0000;">120</span><span style="color: #339933;">,</span> sortable<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">,</span> dataIndex<span style="color: #339933;">:</span> <span style="color: #3366CC;">'name'</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
    <span style="color: #009900;">&#123;</span>header<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;Criado em&quot;</span><span style="color: #339933;">,</span> width<span style="color: #339933;">:</span> <span style="color: #CC0000;">135</span><span style="color: #339933;">,</span> sortable<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">,</span> 
        renderer<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>value<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
          <span style="color: #000066; font-weight: bold;">return</span> Date.<span style="color: #660066;">parseDate</span><span style="color: #009900;">&#40;</span>value<span style="color: #339933;">,</span> <span style="color: #3366CC;">'Y-m-d<span style="color: #000099; font-weight: bold;">\\</span>TH:i:s<span style="color: #000099; font-weight: bold;">\\</span>Z'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">format</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'d/m/Y H:i:s'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> dataIndex<span style="color: #339933;">:</span> <span style="color: #3366CC;">'created_at'</span><span style="color: #009900;">&#125;</span>
 <span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">var</span> pagingToolbar <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Ext.<span style="color: #660066;">PagingToolbar</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
    pageSize<span style="color: #339933;">:</span><span style="color: #CC0000;">10</span><span style="color: #339933;">,</span>store<span style="color: #339933;">:</span> store<span style="color: #339933;">,</span>
    displayInfo<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">,</span>	
    displayMsg<span style="color: #339933;">:</span> <span style="color: #3366CC;">'Exibindo o resultado: {0} a {1} de {2} registros'</span><span style="color: #339933;">,</span>
    emptyMsg<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;Sem resultados a exibir&quot;</span><span style="color: #339933;">,</span>
    items<span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span><span style="color: #3366CC;">'-'</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span>
        pressed<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">,</span>enableToggle<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">,</span>text<span style="color: #339933;">:</span> <span style="color: #3366CC;">'Alterar'</span><span style="color: #339933;">,</span>
        toggleHandler<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span>
        pressed<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">,</span>enableToggle<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">,</span>text<span style="color: #339933;">:</span> <span style="color: #3366CC;">'Excluir'</span><span style="color: #339933;">,</span>
        toggleHandler<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#93;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">var</span> grid  <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Ext.<span style="color: #660066;">grid</span>.<span style="color: #660066;">GridPanel</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
    autoShow<span style="color: #339933;">:</span><span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">,</span> width<span style="color: #339933;">:</span><span style="color: #CC0000;">750</span><span style="color: #339933;">,</span>height<span style="color: #339933;">:</span><span style="color: #CC0000;">250</span><span style="color: #339933;">,</span>
    cm<span style="color: #339933;">:</span> colModel<span style="color: #339933;">,</span>
    store<span style="color: #339933;">:</span> store<span style="color: #339933;">,</span>
    sm<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">new</span> Ext.<span style="color: #660066;">grid</span>.<span style="color: #660066;">RowSelectionModel</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>singleSelect<span style="color: #339933;">:</span><span style="color: #003366; font-weight: bold;">true</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
    bbar<span style="color: #339933;">:</span> pagingToolbar
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Como eu falei, todos os componentes possuem o mesmo comportamento, notaram que dá para aproveitar esse código semelhante e reaproveitar em todos os CRUDs?<br />
Vou falando de um por um de acordo com os posts que forem saindo, aguardem que o próximo sai logo&#8230; ou não.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.milfont.org/tech/2009/06/29/introducao-ao-ext/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>Introdução ao DWR</title>
		<link>http://www.milfont.org/tech/2009/03/20/introducao-ao-dwr/</link>
		<comments>http://www.milfont.org/tech/2009/03/20/introducao-ao-dwr/#comments</comments>
		<pubDate>Fri, 20 Mar 2009 10:24:04 +0000</pubDate>
		<dc:creator>cmilfont</dc:creator>
				<category><![CDATA[Ajax]]></category>
		<category><![CDATA[DWR]]></category>
		<category><![CDATA[Frameworks]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[JSON]]></category>

		<guid isPermaLink="false">http://www.milfont.org/tech/?p=23</guid>
		<description><![CDATA[Material básico que eu usava nos cursos em 2007 para configuração do DWR em uma aplicação web em java, principalmente a partir da página 10. O DWR tem uma vantagem, desde 2005 &#8211; em suas primeiras versões &#8211; que praticamente é a mesma configuração, com mudanças poucos significativas. Esse material continua válido em sua plenitude. [...]]]></description>
			<content:encoded><![CDATA[<p>Material básico que eu usava nos cursos em 2007 para configuração do DWR em uma aplicação web em java, principalmente a partir da página 10.</p>
<p>O DWR tem uma vantagem, desde 2005 &#8211; em suas primeiras versões &#8211; que praticamente é a mesma configuração, com mudanças poucos significativas. Esse material continua válido em sua plenitude.</p>
<div id="__ss_1172050" style="width: 425px; text-align: left;"><a style="font:14px Helvetica,Arial,Sans-serif;display:block;margin:12px 0 3px 0;text-decoration:underline;" title="Tw Dwr 2007 Ap01" href="http://www.slideshare.net/cmilfont/tw-dwr-2007-ap01?type=powerpoint">Tw Dwr 2007 Ap01</a><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="425" height="355" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="allowFullScreen" value="true" /><param name="allowScriptAccess" value="always" /><param name="src" value="http://static.slideshare.net/swf/ssplayer2.swf?doc=twdwr2007ap01-090319212458-phpapp01&amp;stripped_title=tw-dwr-2007-ap01" /><embed type="application/x-shockwave-flash" width="425" height="355" src="http://static.slideshare.net/swf/ssplayer2.swf?doc=twdwr2007ap01-090319212458-phpapp01&amp;stripped_title=tw-dwr-2007-ap01" allowscriptaccess="always" allowfullscreen="true"></embed></object></p>
<div style="font-size: 11px; font-family: tahoma,arial; height: 26px; padding-top: 2px;">View more <a style="text-decoration:underline;" href="http://www.slideshare.net/">presentations</a> from <a style="text-decoration:underline;" href="http://www.slideshare.net/cmilfont">Christiano Milfont</a>.</div>
</div>
<p><img src="http://www.milfont.org/tech/wp-content/upload/dwrworks.png" alt="" /></p>
]]></content:encoded>
			<wfw:commentRss>http://www.milfont.org/tech/2009/03/20/introducao-ao-dwr/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>DWR 3 Release Candidate 1</title>
		<link>http://www.milfont.org/tech/2008/12/24/dwr-3-release-candidate-1/</link>
		<comments>http://www.milfont.org/tech/2008/12/24/dwr-3-release-candidate-1/#comments</comments>
		<pubDate>Wed, 24 Dec 2008 15:33:43 +0000</pubDate>
		<dc:creator>cmilfont</dc:creator>
				<category><![CDATA[Ajax]]></category>
		<category><![CDATA[DWR]]></category>
		<category><![CDATA[Frameworks]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[JSON]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[Joe Walker]]></category>

		<guid isPermaLink="false">http://www.milfont.org/tech/?p=481</guid>
		<description><![CDATA[Joe Walker anunciou que saiu a RC1 do DWR3 com pequeno atraso com novidades interessantes como suporte a Varargs, Method Overloading, entre outras coisas. Mas destaco algo que deveria ter há tempos e sentíamos falta para construções repetitivas como CRUD (principalmente) que é o que chamou de &#8220;Lightweight typed parameters&#8220;. Até a versão 2 temos [...]]]></description>
			<content:encoded><![CDATA[<p>Joe Walker <a href="http://directwebremoting.org/blog/joe/2008/12/16/dwr_version_3_0_release_candidate_1.html">anunciou</a> que saiu a <a href="http://directwebremoting.org/dwr/download">RC1</a> do <a href="http://directwebremoting.org/dwr">DWR3</a> com <a href="http://www.milfont.org/tech/2008/03/11/dwr-3-em-junho/">pequeno atraso</a> com novidades interessantes como suporte a Varargs, Method Overloading, entre outras coisas. Mas destaco algo que deveria ter há tempos e sentíamos falta para construções repetitivas como CRUD (principalmente) que é o que chamou de &#8220;<strong>Lightweight typed parameters</strong>&#8220;.</p>
<p>Até a versão 2 temos que construir métodos no <a href="http://directwebremoting.org/dwr/server/dwrxml/creators">Creator</a> com implementação nos argumentos devido ao DWR não ter como fazer o binding entre o Javascript e o Java sem saber quem é o objeto. Algo assim:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> AjaxFacade <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> User teste<span style="color: #009900;">&#40;</span>User param<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		param.<span style="color: #006633;">setDescription</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Teste funcionou&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">return</span> param<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>No javascript:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">AjaxFacade.<span style="color: #660066;">teste</span><span style="color: #009900;">&#40;</span>
	<span style="color: #009900;">&#123;</span>
		id<span style="color: #339933;">:</span><span style="color: #CC0000;">42</span> <span style="color: #006600; font-style: italic;">//JSON que representa o objeto User</span>
	<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> 
	<span style="color: #009900;">&#123;</span>
		callback<span style="color: #339933;">:</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>retorno<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span>retorno.<span style="color: #660066;">toSource</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
		errorHandler<span style="color: #339933;">:</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>error<span style="color: #339933;">,</span> message<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span>message<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> 
		timeout<span style="color: #339933;">:</span><span style="color: #CC0000;">5000</span>
	<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Agora foi adicionado a propriedade <strong><em>$dwrClassName</em></strong> no <a href="http://directwebremoting.org/dwr/server/dwrxml/converters">Converter</a> onde você pode trabalhar com a interface ao invés da implementação. Vejamos com o Object como argumento no mesmo método:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> AjaxFacade <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">Object</span> teste<span style="color: #009900;">&#40;</span><span style="color: #003399;">Object</span> param<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #666666; font-style: italic;">//puramente ilustrativo não peça fundamentação lógica :)</span>
		<span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>param <span style="color: #000000; font-weight: bold;">instanceof</span> User<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> 
			<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>User<span style="color: #009900;">&#41;</span> param<span style="color: #009900;">&#41;</span>.<span style="color: #006633;">setDescription</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Teste funcionou&quot;</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> param<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>No javascript:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">AjaxFacade.<span style="color: #660066;">teste</span><span style="color: #009900;">&#40;</span>
	<span style="color: #009900;">&#123;</span>
		id<span style="color: #339933;">:</span><span style="color: #CC0000;">42</span> <span style="color: #006600; font-style: italic;">//JSON que representa o objeto User,</span>
		$dwrClassName<span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;User&quot;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> 
	<span style="color: #009900;">&#123;</span>
		callback<span style="color: #339933;">:</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>retorno<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span>retorno.<span style="color: #660066;">toSource</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
		errorHandler<span style="color: #339933;">:</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>error<span style="color: #339933;">,</span> message<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span>message<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> 
		timeout<span style="color: #339933;">:</span><span style="color: #CC0000;">5000</span>
	<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Agora aquelas centenas de classes que fazem a mesma coisa [CRUDzão velho de guerra] podem ser resumidas em uma única Facade que faz suas validações e aciona um Repository ou sua estrutura de persistência.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> AjaxFacade <span style="color: #009900;">&#123;</span>
	@Autowired <span style="color: #003399;">Repository</span> repository<span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">Object</span> persistir<span style="color: #009900;">&#40;</span><span style="color: #003399;">Object</span> param<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>param <span style="color: #339933;">==</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> ...
		<span style="color: #006633;">repository</span>.<span style="color: #006633;">persist</span><span style="color: #009900;">&#40;</span>param<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">return</span> param<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Agora não tem como não termos um Feliz Natal!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.milfont.org/tech/2008/12/24/dwr-3-release-candidate-1/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Minificação de Javascript com Ant Task</title>
		<link>http://www.milfont.org/tech/2008/12/16/minificacao-de-javascript-com-ant-task/</link>
		<comments>http://www.milfont.org/tech/2008/12/16/minificacao-de-javascript-com-ant-task/#comments</comments>
		<pubDate>Tue, 16 Dec 2008 20:06:34 +0000</pubDate>
		<dc:creator>cmilfont</dc:creator>
				<category><![CDATA[Ajax]]></category>
		<category><![CDATA[Engenharia de Software]]></category>
		<category><![CDATA[Frameworks]]></category>
		<category><![CDATA[High Performance]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[JSON]]></category>
		<category><![CDATA[Melhores práticas]]></category>
		<category><![CDATA[Otimização]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[YUI]]></category>
		<category><![CDATA[ant]]></category>
		<category><![CDATA[ant task]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[minificação]]></category>
		<category><![CDATA[minified]]></category>

		<guid isPermaLink="false">http://www.milfont.org/tech/?p=459</guid>
		<description><![CDATA[Em um post passado eu falei da importância de unir e minificar arquivos js em determinados casos e discuti &#8220;quando&#8221; fazer isso, vou mostrar &#8220;como&#8221; minificar usando o YUI Compressor com tasks do Apache Ant montados por Viktor Lieskovsky do Javaflight. Esse pequeno tutorial-guia faz parte do material dos meus cursos de Javascript e Ajax [...]]]></description>
			<content:encoded><![CDATA[<p>Em um <a href="http://www.milfont.org/tech/2008/02/10/javascript-inline-e-external/">post passado</a> eu falei da importância de unir e minificar arquivos js em determinados casos e discuti &#8220;quando&#8221; fazer isso, vou mostrar &#8220;como&#8221; minificar usando o <a href="http://developer.yahoo.com/yui/compressor/">YUI Compressor</a> com tasks do <a href="http://ant.apache.org/">Apache Ant</a> <a href="http://code.google.com/p/javaflight-code/">montados por Viktor Lieskovsky</a> do <a href="http://javaflight.blogspot.com/">Javaflight</a>.</p>
<p>Esse pequeno tutorial-guia faz parte do material dos meus cursos de Javascript e Ajax e serve para deixar um histórico acessível aos alunos e fácil para leitores que por ventura precisem.</p>
<p>Preparei um ambiente de execução com todas as dependências no <a href="http://www.milfont.org/tech/projetos/">projeto</a> <a href="http://code.google.com/p/remendux/">Remendux</a> onde vocês podem fazer <a href="http://code.google.com/p/remendux/source/checkout">checkout</a> e rodar o build ant localmente como um projeto do eclipse &#8211; estou usando o plugin para o <a href="http://subclipse.tigris.org/">SVN Subclipse</a>.</p>
<p>Montei um script ant padrão bem simples de ser entendido por iniciantes:</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;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;UTF-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;project</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;jsmin&quot;</span> <span style="color: #000066;">default</span>=<span style="color: #ff0000;">&quot;main&quot;</span> <span style="color: #000066;">basedir</span>=<span style="color: #ff0000;">&quot;.&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
	<span style="color: #808080; font-style: italic;">&lt;!-- Propriedades para definir nomes de pastas que usaremos --&gt;</span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;js&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;js&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;build&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;build&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;lib&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;lib&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;output&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;output&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	<span style="color: #808080; font-style: italic;">&lt;!-- Propriedades para definir nomes os arquivos necessários --&gt;</span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;yui-compressor.jar&quot;</span></span>
<span style="color: #009900;">		<span style="color: #000066;">location</span>=<span style="color: #ff0000;">&quot;${lib}/yuicompressor-2.4.2.jar&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;yui-compressor-ant-task.jar&quot;</span> </span>
<span style="color: #009900;">		<span style="color: #000066;">location</span>=<span style="color: #ff0000;">&quot;${lib}/yui-compressor-ant-task-0.3.jar&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	<span style="color: #808080; font-style: italic;">&lt;!-- Incluir as libs necessárias no classpath --&gt;</span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;path</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;task.classpath&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;pathelement</span> <span style="color: #000066;">location</span>=<span style="color: #ff0000;">&quot;${yui-compressor.jar}&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;pathelement</span> <span style="color: #000066;">location</span>=<span style="color: #ff0000;">&quot;${yui-compressor-ant-task.jar}&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/path<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #808080; font-style: italic;">&lt;!-- Definição da task para o Ant reconhecer --&gt;</span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;taskdef</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;yui-compressor&quot;</span> </span>
<span style="color: #009900;"><span style="color: #000066;">classname</span>=<span style="color: #ff0000;">&quot;net.noha.tools.ant.yuicompressor.tasks.YuiCompressorTask&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;classpath</span> <span style="color: #000066;">refid</span>=<span style="color: #ff0000;">&quot;task.classpath&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/taskdef<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;target</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;clean&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;delete</span> <span style="color: #000066;">dir</span>=<span style="color: #ff0000;">&quot;build&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;delete</span> <span style="color: #000066;">dir</span>=<span style="color: #ff0000;">&quot;output&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mkdir</span> <span style="color: #000066;">dir</span>=<span style="color: #ff0000;">&quot;build&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mkdir</span> <span style="color: #000066;">dir</span>=<span style="color: #ff0000;">&quot;output&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/target<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;target</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;main&quot;</span> <span style="color: #000066;">depends</span>=<span style="color: #ff0000;">&quot;clean&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
		<span style="color: #808080; font-style: italic;">&lt;!-- Tag do Ant para concatenar arquivos </span>
<span style="color: #808080; font-style: italic;">		[ http://ant.apache.org/manual/CoreTasks/concat.html] </span>
<span style="color: #808080; font-style: italic;">		os arquivos são unidos na sequência de definição </span>
<span style="color: #808080; font-style: italic;">		no fileset</span>
<span style="color: #808080; font-style: italic;">		--&gt;</span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;concat</span> <span style="color: #000066;">destfile</span>=<span style="color: #ff0000;">&quot;${output}/remendux.js&quot;</span> <span style="color: #000066;">force</span>=<span style="color: #ff0000;">&quot;no&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;fileset</span> <span style="color: #000066;">file</span>=<span style="color: #ff0000;">&quot;${js}/util.js&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;fileset</span> <span style="color: #000066;">file</span>=<span style="color: #ff0000;">&quot;${js}/remendux.js&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/concat<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #808080; font-style: italic;">&lt;!-- Task do yui-compressor --&gt;</span>
		 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;yui-compressor</span> <span style="color: #000066;">warn</span>=<span style="color: #ff0000;">&quot;false&quot;</span>  <span style="color: #000066;">munge</span>=<span style="color: #ff0000;">&quot;true&quot;</span>  </span>
<span style="color: #009900;">				<span style="color: #000066;">preserveallsemicolons</span>=<span style="color: #ff0000;">&quot;false&quot;</span> </span>
<span style="color: #009900;">				<span style="color: #000066;">fromdir</span>=<span style="color: #ff0000;">&quot;${output}&quot;</span> <span style="color: #000066;">todir</span>=<span style="color: #ff0000;">&quot;${build}&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/yui-compressor<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/target<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/project<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>Após a importação, para executar o script &#8211; que chamei de build-yui.xml &#8211; basta apenas executar com o ant pelo eclipse &#8211; vide imagem abaixo &#8211; ou em linha de comando. Estou usando o Ant 7.1 com java 6u10 e Eclipse 3.4, portanto caso haja um erro atente para a versão das ferramentas usadas.</p>
<p><img src="http://www.milfont.org/tech/wp-content/uploads/2008/12/build.jpg" alt="" title="build"  class="aligncenter size-medium wp-image-464" /></p>
<p>Após executar, observe a redução de tamanho na versão minificada [../build/remendux-min.js] para a versão concatenada [../output/remendux.js ]. A versão final ficou com 30% do tamanho com documentação e identação.</p>

<div class="wp_syntax"><div class="code"><pre class="abap" style="font-family:monospace;">Buildfile<span style="color: #808080;">:</span> C<span style="color: #808080;">:</span>\workspace\remendux\build<span style="color: #808080;">-</span>yui<span style="color: #808080;">.</span>xml
     <span style="color: #808080;">&#91;</span>echo<span style="color: #808080;">&#93;</span> Building <span style="color: #500066; text-transform: uppercase; font-weight: bold; zzz:keyword;">output</span>
clean<span style="color: #808080;">:</span>
    <span style="color: #808080;">&#91;</span>mkdir<span style="color: #808080;">&#93;</span> Created dir<span style="color: #808080;">:</span> C<span style="color: #808080;">:</span>\workspace\remendux\build
    <span style="color: #808080;">&#91;</span>mkdir<span style="color: #808080;">&#93;</span> Created dir<span style="color: #808080;">:</span> C<span style="color: #808080;">:</span>\workspace\remendux\<span style="color: #500066; text-transform: uppercase; font-weight: bold; zzz:keyword;">output</span>
main<span style="color: #808080;">:</span>
<span style="color: #808080;">&#91;</span>yui<span style="color: #808080;">-</span>compressor<span style="color: #808080;">&#93;</span>
 <span style="color: #808080;">&#91;</span><span style="color: #3399ff;">30</span><span style="color: #808080;">%</span><span style="color: #808080;">&#93;</span> remendux<span style="color: #808080;">.</span>js <span style="color: #808080;">&#91;</span><span style="color: #3399ff;">5775</span><span style="color: #808080;">&#93;</span> <span style="color: #808080;">---&gt;</span> <span style="color: #202020;">remendux</span><span style="color: #808080;">-</span><span style="color: #500066; text-transform: uppercase; font-weight: bold; zzz:keyword;">min</span><span style="color: #808080;">.</span>js <span style="color: #808080;">&#91;</span><span style="color: #3399ff;">1734</span><span style="color: #808080;">&#93;</span>
<span style="color: #808080;">&#91;</span>yui<span style="color: #808080;">-</span>compressor<span style="color: #808080;">&#93;</span>
 <span style="color: #808080;">&#91;</span>JavaScript<span style="color: #808080;">&#93;</span> Compressed <span style="color: #3399ff;">1</span> files <span style="color: #500066; text-transform: uppercase; font-weight: bold; zzz:keyword;">to</span> <span style="color: #3399ff;">30</span><span style="color: #808080;">%</span> <span style="color: #808080;">&#40;</span>5KB <span style="color: #500066; text-transform: uppercase; font-weight: bold; zzz:keyword;">to</span> 1KB<span style="color: #808080;">,</span> saving 4KB<span style="color: #808080;">&#41;</span>
<span style="color: #808080;">&#91;</span>yui<span style="color: #808080;">-</span>compressor<span style="color: #808080;">&#93;</span>
 <span style="color: #808080;">&#91;</span>CSS<span style="color: #808080;">&#93;</span> <span style="color: #500066; text-transform: uppercase; font-weight: bold; zzz:keyword;">No</span> files <span style="color: #500066; text-transform: uppercase; font-weight: bold; zzz:keyword;">to</span> compress<span style="color: #808080;">,</span> <span style="color: #500066; text-transform: uppercase; font-weight: bold; zzz:keyword;">or</span> <span style="color: #500066; text-transform: uppercase; font-weight: bold; zzz:keyword;">all</span> files already <span style="color: #500066; text-transform: uppercase; font-weight: bold; zzz:keyword;">up to</span> <span style="color: #500066; text-transform: uppercase; font-weight: bold; zzz:keyword;">date</span>
<span style="color: #808080;">&#91;</span>yui<span style="color: #808080;">-</span>compressor<span style="color: #808080;">&#93;</span>
 Compressed <span style="color: #3399ff;">1</span> files <span style="color: #500066; text-transform: uppercase; font-weight: bold; zzz:keyword;">to</span> <span style="color: #3399ff;">30</span><span style="color: #808080;">%</span> <span style="color: #808080;">&#40;</span>5KB <span style="color: #500066; text-transform: uppercase; font-weight: bold; zzz:keyword;">to</span> 1KB<span style="color: #808080;">,</span> saving 4KB<span style="color: #808080;">&#41;</span>
BUILD SUCCESSFUL
Total <span style="color: #500066; text-transform: uppercase; font-weight: bold; zzz:keyword;">time</span><span style="color: #808080;">:</span> <span style="color: #3399ff;">12</span> <span style="color: #500066; text-transform: uppercase; font-weight: bold; zzz:keyword;">seconds</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.milfont.org/tech/2008/12/16/minificacao-de-javascript-com-ant-task/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Encontro em Iguatu</title>
		<link>http://www.milfont.org/tech/2008/11/04/encontro-em-iguatu/</link>
		<comments>http://www.milfont.org/tech/2008/11/04/encontro-em-iguatu/#comments</comments>
		<pubDate>Tue, 04 Nov 2008 12:19:34 +0000</pubDate>
		<dc:creator>cmilfont</dc:creator>
				<category><![CDATA[(X)HTML]]></category>
		<category><![CDATA[Ajax]]></category>
		<category><![CDATA[cejug]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[DWR]]></category>
		<category><![CDATA[Ext]]></category>
		<category><![CDATA[Frameworks]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[JSON]]></category>
		<category><![CDATA[palestras]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Prototype]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[web2.0]]></category>
		<category><![CDATA[XMLHttpRequest]]></category>
		<category><![CDATA[YUI]]></category>
		<category><![CDATA[ExtJS]]></category>
		<category><![CDATA[Jquery]]></category>

		<guid isPermaLink="false">http://www.milfont.org/tech/?p=365</guid>
		<description><![CDATA[O evento em Iguatu foi excelente, tivemos uma tarde muito agradável no encontro das comunidades PHP e Java no dia 1/11/2008. Fernando Chucre iniciou o evento palestrando pelo CEPUG sobre PHP Orientado a objetos. Logo em seguida foi a vez do Jefferson [organizador do evento] palestrar sobre Debug no PHP. Pelo CEJUG o Silveira Neto [...]]]></description>
			<content:encoded><![CDATA[<p>O evento em Iguatu foi excelente, tivemos uma tarde muito agradável no <a href="http://www.milfont.org/tech/2008/10/24/encontro-java-e-php-em-iguatu-ce/">encontro das comunidades PHP e Java</a> no dia 1/11/2008.</p>
<p><a href="http://horizontesdigitais.com/">Fernando Chucre</a> iniciou o evento palestrando pelo <a href="http://cepug.org/2008/11/evento-em-iguatu-foi-um-sucesso-agora-e-fortaleza/">CEPUG</a> sobre PHP Orientado a objetos. Logo em seguida foi a vez do <a href="http://jefferson.eti.br/">Jefferson</a> [organizador do evento] palestrar sobre Debug no PHP.<br />
Pelo <a href="http://www.cejug.org/display/cejug/Apresentando+o+CEJUG+e+o+poder+do+Java+e+Frameworks+AJAX+em+Iguatu+-+01.11.08">CEJUG</a> o <a href="http://silveiraneto.net/2008/11/03/1%c2%ba-encontro-cejugcepug-em-iguatu/">Silveira Neto</a> apresentou uma palestra sobre a comunidade e o poder do Java, seguido por mim sobre Frameworks Ajax focado em Java com utilização de DWR e ExtJS.</p>
<p>O detalhe mais importante foi constatar a maturidade de duas comunidades tão distintas que compartilharam o mesmo evento sem nenhum problema, egocentrismo ou picuinha. Eu já estou cansando de ir em eventos onde o pessoal só fala de outra tecnologia, como eventos de linguagem onde falam mal de Java o evento inteiro. Cada um apresentou sua palestra sem desmerecer nenhuma tecnologia ou ninguém.</p>
<h2>Material</h2>
<div id="__ss_719498" style="width: 425px; text-align: left;"><a style="font:14px Helvetica,Arial,Sans-serif;display:block;margin:12px 0 3px 0;text-decoration:underline;" title="Frameworks Ajax" href="http://www.slideshare.net/cmilfont/frameworks-ajax-presentation?type=powerpoint">Frameworks Ajax</a><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="425" height="355" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="allowFullScreen" value="true" /><param name="allowScriptAccess" value="always" /><param name="src" value="http://static.slideshare.net/swf/ssplayer2.swf?doc=frameworksajax-1225798962914024-9&amp;stripped_title=frameworks-ajax-presentation" /><embed type="application/x-shockwave-flash" width="425" height="355" src="http://static.slideshare.net/swf/ssplayer2.swf?doc=frameworksajax-1225798962914024-9&amp;stripped_title=frameworks-ajax-presentation" allowscriptaccess="always" allowfullscreen="true"></embed></object></p>
<div style="font-size: 11px; font-family: tahoma,arial; height: 26px; padding-top: 2px;">View SlideShare <a style="text-decoration:underline;" title="View Frameworks Ajax on SlideShare" href="http://www.slideshare.net/cmilfont/frameworks-ajax-presentation?type=powerpoint">presentation</a> or <a style="text-decoration:underline;" href="http://www.slideshare.net/upload?type=powerpoint">Upload</a> your own. (tags: <a style="text-decoration:underline;" href="http://slideshare.net/tag/ajax">ajax</a> <a style="text-decoration:underline;" href="http://slideshare.net/tag/iguatu">iguatu</a>)</div>
</div>
<h2>Fotos</h2>
<p><a href="http://picasaweb.google.com.br/cmilfont/Iguatu1112008">Picasa do CMilfont</a><br />
<a href="http://www.flickr.com/photos/silveiraneto/sets/72157608607361149/">Flcikr do Silveira</a></p>
<p><img src="http://lh5.ggpht.com/_Mm7CP-3dJvI/SQ7tkg3kpLI/AAAAAAAAAvc/woXXELjYiJg/s400/IMG_2173.JPG" alt="iguatu" /></p>
<p><img src="http://farm4.static.flickr.com/3163/2997081263_b20482857b.jpg?v=0" alt="minha apresentacao" /></p>
]]></content:encoded>
			<wfw:commentRss>http://www.milfont.org/tech/2008/11/04/encontro-em-iguatu/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Os melhores livros de Javascript</title>
		<link>http://www.milfont.org/tech/2008/10/13/os-melhores-livros-de-javascript/</link>
		<comments>http://www.milfont.org/tech/2008/10/13/os-melhores-livros-de-javascript/#comments</comments>
		<pubDate>Mon, 13 Oct 2008 09:00:58 +0000</pubDate>
		<dc:creator>cmilfont</dc:creator>
				<category><![CDATA[Ajax]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[JSON]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[web2.0]]></category>
		<category><![CDATA[John Resig]]></category>
		<category><![CDATA[livros]]></category>
		<category><![CDATA[Nicholas C. Zakas]]></category>

		<guid isPermaLink="false">http://www.milfont.org/tech/?p=82</guid>
		<description><![CDATA[A maioria dos livros sobre Javascript que conheço, abordam somente a API dos objetos nativos (built-in) como Function, String e Array, além da API BOM (Browser Object Model). Tudo bem que o Javascript tem sua maior utilidade como linguagem a ser utilizada no Browser, mas a explicação da teoria de orientação a objetos na linguagem [...]]]></description>
			<content:encoded><![CDATA[<p>A maioria dos livros sobre Javascript que conheço, abordam somente a API dos objetos nativos (built-in) como Function, String e Array, além da API BOM (Browser Object Model).</p>
<p>Tudo bem que o Javascript tem sua maior utilidade como linguagem a ser utilizada no Browser, mas a explicação da teoria de orientação a objetos na linguagem e técnicas avançadas de contrução dos objetos é precária.</p>
<p>Três bons livros na galeria abaixo se destacam: &#8220;<a href="http://jspro.org/">Pro JavaScript Techniques</a>&#8221; do <a href="http://ejohn.org/">John Resig</a> (criador do <a href="http://jquery.com/">JQuery</a>); <a href="http://www.amazon.com/gp/product/0764579088/">Professional JavaScript for Web Developers</a> do <a href="http://www.nczonline.net/">Nicholas C. Zakas</a>, <a href="http://www.nczonline.net/about/">software engineer</a> do Yahoo; e o <a href="http://www.amazon.com/gp/product/0471777781/">Professional Ajax (Programmer to Programmer)</a> também com o Nicholas mas em parceria com outros dois autores, <a href="http://www.amazon.com/exec/obidos/search-handle-url/ref=ntt_athr_dp_sr_2?_encoding=UTF8&#038;search-type=ss&#038;index=books&#038;field-author=Jeremy%20McPeak">Jeremy McPeak</a> e <a href="http://www.amazon.com/exec/obidos/search-handle-url/ref=ntt_athr_dp_sr_3?_encoding=UTF8&#038;search-type=ss&#038;index=books&#038;field-author=Joe%20Fawcett">Joe Fawcett</a>.</p>
<p>Os dois livros do Nicholas são bem completos, abordam &#8211; com fartos exemplos &#8211; toda a orientação a objetos na linguagem e fornecem boas práticas de como trabalhar. O primeiro, do Resig já é mais moderno e cobre alguns pontos que faltaram nos demais, como <a href="http://www.jibbering.com/faq/faq_notes/closures.html">Closure</a>. Basicamente esses 3 livros são necessários.</p>
<div id="ShelfariWidget71421"><a href='http://www.shelfari.com/'>Shelfari: Book reviews on your book blog</a><script src="http://www.shelfari.com/ws/71421/widget.js" type="text/javascript" language="javascript"></script><noscript>
<p>Share a <a href="http://www.shelfari.com/books">book review</a> on Shelfari, where this <a href="http://www.shelfari.com/">reader</a> meets fellow readers.</p>
<p></noscript></div>
]]></content:encoded>
			<wfw:commentRss>http://www.milfont.org/tech/2008/10/13/os-melhores-livros-de-javascript/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>JSONRequest para evitar o Eval</title>
		<link>http://www.milfont.org/tech/2008/01/04/jsonrequest-para-evitar-o-eval/</link>
		<comments>http://www.milfont.org/tech/2008/01/04/jsonrequest-para-evitar-o-eval/#comments</comments>
		<pubDate>Fri, 04 Jan 2008 12:07:27 +0000</pubDate>
		<dc:creator>cmilfont</dc:creator>
				<category><![CDATA[Ajax]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[JSON]]></category>
		<category><![CDATA[XMLHttpRequest]]></category>
		<category><![CDATA[Crockford]]></category>
		<category><![CDATA[Douglas Crockford]]></category>
		<category><![CDATA[JSONRequest]]></category>
		<category><![CDATA[W3C]]></category>
		<category><![CDATA[XHR]]></category>

		<guid isPermaLink="false">http://www.milfont.org/tech/2008/01/04/jsonrequest-para-evitar-o-eval/</guid>
		<description><![CDATA[Em artigo passado, vimos a proposta de Douglas Crockford, denominado de JSON (JavaScript Object Notation) para a troca de dados. Ele propôs também uma especificação para um novo objeto como serviço nativo nos navegadores, JSONRequest, devido a ineficiência do objeto XMLHttpRequest para as novas aplicações nas próximas geração WEB (WEB 2+). Um dos pontos principais [...]]]></description>
			<content:encoded><![CDATA[<p>Em <a href="http://www.milfont.org/tech/2007/11/04/o-que-e-json/">artigo passado</a>, vimos a proposta de Douglas <a href="http://www.crockford.com/">Crockford</a>, denominado de <a href="http://www.json.org/">JSON</a> (JavaScript Object Notation) para a troca de dados. Ele propôs também uma especificação para um novo objeto como serviço nativo nos navegadores, <a href="http://www.json.org/JSONRequest.html">JSONRequest</a>, devido a ineficiência do objeto <a href="http://www.milfont.org/tech/2007/10/03/destilando-o-xmlhttprequest/">XMLHttpRequest</a> para as novas aplicações nas próximas geração WEB (WEB 2+). Um dos pontos principais desse novo objeto é a troca segura de objetos por meio de JSON entre o lado cliente e servidor sem expô-los ao perigo.</p>
<p>A especificação do <a href="http://www.milfont.org/tech/2007/10/03/destilando-o-xmlhttprequest/">XHR</a> define, por medida de segurança, que uma chamada remota só pode ser efetuada ao mesmo caminho de onde o script foi baixado, o JSONRequest resolveria esse problema habilitando o navegador a uma chamada remota a outros servidores diferentes do host original da página, possibilitando a facilidade de acesso a WEB Services REST na camada javascript.</p>
<p>Hoje como alternativa a esse modelo do <a href="http://www.milfont.org/tech/2007/10/03/destilando-o-xmlhttprequest/">XHR</a> temos o <a href="http://www.milfont.org/tech/2007/10/08/script-tag/">Scripttag</a>, dessa forma conseguimos acessar recursos remotos de outros servidores mas com o problema de XSS (cross site scripting). O problema principal do XSS é a injeção de código malicioso pelo parser a partir do método &#8220;Eval&#8221; para processar o código recebido. Vimos uma <a href="http://www.milfont.org/tech/2007/10/02/eval-is-evil/">alternativa de contornar</a> o problema mas mesmo assim não é suficiente. Uma das vantagens principais do JSONRequest seria evitar o XSS.</p>
<p>Esse objeto JSONRequest seria nativo e global, desenhado para ser simples, teria apenas 3 métodos: get, post e cancel.</p>
<p>Existe já plugin para o <a href="http://crypto.stanford.edu/jsonrequest/">Firefox</a>  que habilita o navegador a oferecer nativamente o objeto JSONRequest.</p>
<p>Para todos os navegadores somente com javascript na camada mais alta, para isso existe também o projeto <a href="http://www.devpro.it/JSON/files/JSON-js.html">JSONRequest</a> de <a href="http://www.3site.eu/">Andrea Giammarchi</a>, que criou o objeto em javascript seguindo a especificação. Compatível com os principais navegadores: Opera, IE, Firefox, Safari e konqueror.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
    JSONRequest.<span style="color: #660066;">get</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;processaJSON.jsp&quot;</span><span style="color: #339933;">,</span>
        <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>sn<span style="color: #339933;">,</span> response<span style="color: #339933;">,</span> exception<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
             <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span>exception <span style="color: #339933;">||</span> response<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">catch</span><span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
      <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>O W3C <a href="http://www.w3.org/TR/access-control/">especificou</a> medidas seguras para acesso a recursos web em outro servidores, assim como já existem <a href="http://wiki.mozilla.org/Cross_Site_XMLHttpRequest">movimentos</a> para uma nova especificação do um novo <a href="http://lists.w3.org/Archives/Public/public-webapi/2006Jun/0012">XHR</a>, seria algo como um <a href="http://www.w3.org/2006/webapi/track/products/8">XHR2</a>. A diferença no meu entendimento é que o JSONRequest trata exclusivamente da troca de objetos nativos com base em JSON entre os dois ambientes físicos, enquanto o XHR trata da troca via XML, portanto uma nova especificação do XHR não seria suficiente para substituir a proposta do JSONRequest, a não ser que ele fizesse o parser também de JSON como faz com XML.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.milfont.org/tech/2008/01/04/jsonrequest-para-evitar-o-eval/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>O que é JSON</title>
		<link>http://www.milfont.org/tech/2007/11/04/o-que-e-json/</link>
		<comments>http://www.milfont.org/tech/2007/11/04/o-que-e-json/#comments</comments>
		<pubDate>Sun, 04 Nov 2007 09:21:35 +0000</pubDate>
		<dc:creator>cmilfont</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[JSON]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[Crockford]]></category>
		<category><![CDATA[ECMAScript]]></category>

		<guid isPermaLink="false">http://www.milfont.org/tech/2007/11/04/o-que-e-json/</guid>
		<description><![CDATA[A especificação do &#8220;ECMA Script&#8221; (ECMA262, 3rd Edition, December 1999), que formaliza o Javascript, define na página 2 (4.2) a sentença: &#8220;An ECMAScript object is an unordered collection of properties each with zero or more attributes&#8230;&#8221; Essa definição é o que chamamos de objeto literal, uma coleção não ordenada de propriedades com um ou mais [...]]]></description>
			<content:encoded><![CDATA[<p>A especificação do &#8220;ECMA  Script&#8221; (<a href="http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-262.pdf">ECMA262</a>, 3rd Edition, December 1999), que formaliza o Javascript, define na página 2 (4.2) a sentença:</p>
<p><cite>&#8220;An ECMAScript object is an unordered collection of properties each with zero or more attributes&#8230;&#8221; </cite></p>
<p>Essa definição é o que chamamos de objeto literal, uma coleção não ordenada de propriedades com um ou mais elementos, onde esses elementos podem ser valores primitivos comuns a todas as linguagens como: inteiro, string ou char; ou outros objetos.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> Produto <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>
	nome<span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;Microprocessador AMD Turion 64&quot;</span><span style="color: #339933;">,</span>
	value<span style="color: #339933;">:</span><span style="color: #CC0000;">150</span><span style="color: #339933;">,</span>
	custo<span style="color: #339933;">:</span><span style="color: #CC0000;">50</span><span style="color: #339933;">,</span>
	getValue<span style="color: #339933;">:</span><span style="color: #003366; font-weight: bold;">function</span><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> <span style="color: #009900;">&#40;</span>value <span style="color: #339933;">+</span> custo<span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Douglas <a href="http://www.crockford.com/">Crockford</a>, propôs um  formato de troca de dados simples com base no objeto literal do JavaScript, que denominou de <a href="http://www.json.org/">JSON</a> (JavaScript Object Notation). Esse mecanismo simples é um subconjunto do objeto literal e é facil de qualquer linguagem processar e gerar por ser baseado no formato texto, como linguagem completamente independente que usa conceitos similares às linguagens C-like. Esses motivos tornam o JSON o formato ideal de troca de dados.</p>
<p>JSON é construído com base em uma coleção de pares chave/valor (que definem as propriedades e seus valores), iniciado com &#8220;{&#8221; (chave aberta) e finalizado com &#8220;}&#8221; (chave fechada) . Cada chave é seguida de &#8220;:&#8221; (dois pontos) e os pares são separados por &#8220;,&#8221; (vírgula).</p>
<p><img src="http://json.org/object.gif" alt="objeto json" /></p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> Contato <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #3366CC;">&quot;nome&quot;</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;Christiano Milfont&quot;</span><span style="color: #339933;">,</span>
	<span style="color: #3366CC;">&quot;email&quot;</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;cmilfont@gmail.com&quot;</span><span style="color: #339933;">,</span>
	<span style="color: #3366CC;">&quot;aniversário&quot;</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;28/12/1977&quot;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Um array pode ser usado como valor para uma chave, iniciado por &#8220;[" (colchete aberto) e finalizado por "]&#8221; (colchete fechado). Cada valor do array é separado por &#8220;,&#8221; (vírgula).</p>
<p><img src="http://json.org/array.gif" alt="array json" /></p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> Contato <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #3366CC;">&quot;nome&quot;</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;Christiano Milfont&quot;</span><span style="color: #339933;">,</span>
	<span style="color: #3366CC;">&quot;telefones&quot;</span><span style="color: #339933;">:</span><span style="color: #009900;">&#91;</span>
		<span style="color: #3366CC;">'91942365'</span><span style="color: #339933;">,</span>
		<span style="color: #3366CC;">'88293759'</span>
	<span style="color: #009900;">&#93;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Um valor pode ser uma String em aspas duplas (em javascript o valor pode ser aspa simples, é preferível que o parser resolva as duas formas, apesar de que em linguagens como java as aspas simples representam um char), ou um número, ou um booleano, ou um null, ou um outro objeto ou um array.</p>
<p><img src="http://json.org/value.gif" alt="valores json" /></p>
<p>No caso do objeto e do array, essas estrutura podem ser aninhadas.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> Contato <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #3366CC;">&quot;nome&quot;</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;Christiano Milfont&quot;</span><span style="color: #339933;">,</span>
	<span style="color: #3366CC;">&quot;endereco&quot;</span><span style="color: #339933;">:</span><span style="color: #009900;">&#123;</span>
		<span style="color: #3366CC;">&quot;rua&quot;</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;Eurico Medina&quot;</span><span style="color: #339933;">,</span>
		<span style="color: #3366CC;">&quot;numero&quot;</span><span style="color: #339933;">:</span><span style="color: #CC0000;">185</span><span style="color: #339933;">,</span>
		<span style="color: #3366CC;">&quot;mapa&quot;</span><span style="color: #339933;">:</span><span style="color: #009900;">&#123;</span>
			<span style="color: #3366CC;">&quot;latitude&quot;</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;&quot;</span><span style="color: #339933;">,</span>
			<span style="color: #3366CC;">&quot;longitude&quot;</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;&quot;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
	<span style="color: #3366CC;">&quot;telefones&quot;</span><span style="color: #339933;">:</span><span style="color: #009900;">&#91;</span>
		<span style="color: #3366CC;">'91942365'</span><span style="color: #339933;">,</span>
		<span style="color: #3366CC;">'88293759'</span>
	<span style="color: #009900;">&#93;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>String é uma coleção de zero ou mais caracteres <a href="http://pt.wikipedia.org/wiki/Unicode">Unicode</a>, onde a barra invertida pode ser usada para passar caracteres especais como quebra de linha, tab, entre outros. Números podem ser inteiros ou reais, menos hexadecimal ou octal.</p>
<p>Existem códigos de processamento JSON prontos em dezenas de linguagens, praticamente em todas as linguagens modernas voce encontra no <a href="http://www.json.org/">site do projeto</a>.</p>
<p>A vantagem do JSON sobre o XML como formato de troca de dados é a diminuição do tamanho da resposta, facilidade de entendimento para o programador (já que o código é similiar a linguagem que você usa), e principalmente, no caso de javascript, o parser facilitado porque é baseado em sua especificação de objeto.</p>
<p>Código de retorno do Flickr em <a href="http://www.flickr.com/services/rest/?method=flickr.test.echo&amp;format=soap2&amp;foo=bar&amp;api_key=08d9221b2468be6ccfe5bc229db50181">XML</a> e <a href="http://www.flickr.com/services/rest/?method=flickr.test.echo&amp;format=json&amp;api_key=08d9221b2468be6ccfe5bc229db50181">JSON</a> respectivamente:</p>
<p>&lt;?xml version=&#8221;1.0&#8243; encoding=&#8221;utf-8&#8243; ?&gt;<br />
&lt;s:Envelope xmlns:s=&#8221;http://www.w3.org/2003/05/soap-envelope&#8221;&gt;<br />
&lt;s:Body&gt;<br />
&lt;FlickrResponse xmlns=&#8221;http://flickr.com/ns/api#&#8221;&gt;<br />
&lt;method&gt;flickr.test.echo&lt;/method&gt;<br />
&lt;format&gt;soap2&lt;/format&gt;<br />
&lt;foo&gt;bar&lt;/foo&gt;<br />
&lt;api_key&gt;08d9221b2468be6ccfe5bc229db50181&lt;/api_key&gt;<br />
&lt;/FlickrResponse&gt;<br />
&lt;/s:Body&gt;<br />
&lt;/s:Envelope&gt;</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">&nbsp;
jsonFlickrApi<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #3366CC;">&quot;method&quot;</span><span style="color: #339933;">:</span><span style="color: #009900;">&#123;</span>
		<span style="color: #3366CC;">&quot;_content&quot;</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;flickr.test.echo&quot;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
	<span style="color: #3366CC;">&quot;format&quot;</span><span style="color: #339933;">:</span><span style="color: #009900;">&#123;</span>
		<span style="color: #3366CC;">&quot;_content&quot;</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;json&quot;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
	<span style="color: #3366CC;">&quot;api_key&quot;</span><span style="color: #339933;">:</span><span style="color: #009900;">&#123;</span>
		<span style="color: #3366CC;">&quot;_content&quot;</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;08d9221b2468be6ccfe5bc229db50181&quot;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
	<span style="color: #3366CC;">&quot;stat&quot;</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;ok&quot;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span></pre></div></div>

<p>Dessa forma você pode usar as estratégias de &#8220;<a href="http://www.milfont.org/tech/2007/10/02/eval-is-evil/">Eval</a>&#8221;  ou &#8220;<a href="http://www.milfont.org/tech/2007/10/08/script-tag/">Scripttag</a>&#8221; para processar o JSON de forma transparente em sua aplicação AJAX. Usado como configuração em aplicações no lado servidor, você pode construir uma arquitetura com base em interfaces para validar os dados, assim como validaria usando schemas no XML.</p>
<p>A maioria das APIs  de web services dos principais Players no mercado WEB, passaram a oferecer o JSON como alternativa ao XML pela facilidade de interpretação para a arquitetura REST. <a href="http://developer.yahoo.com/common/json.html">Yahoo</a> e <a href="http://code.google.com/apis/gdata/json.html">Google</a> são os principais expoentes desse mecanismo.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.milfont.org/tech/2007/11/04/o-que-e-json/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Script Tag</title>
		<link>http://www.milfont.org/tech/2007/10/08/script-tag/</link>
		<comments>http://www.milfont.org/tech/2007/10/08/script-tag/#comments</comments>
		<pubDate>Mon, 08 Oct 2007 16:51:22 +0000</pubDate>
		<dc:creator>cmilfont</dc:creator>
				<category><![CDATA[Ajax]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[JSON]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[XMLHttpRequest]]></category>

		<guid isPermaLink="false">http://www.milfont.org/tech/2007/10/08/script-tag/</guid>
		<description><![CDATA[Para implementar o dinamismo nas nossas páginas, usando o Javascript, precisamos trocar informações entre as camadas físicas diferentes, o cliente (por intermédio de um Browser) solicitando recursos de um servidor remoto (lado servidor). Dentre as estratégias para essa troca de recursos entre as camadas distintas, temos IFrame, XHR e o Scripttag. IFrame era uma técnica [...]]]></description>
			<content:encoded><![CDATA[<p>Para implementar o dinamismo nas nossas páginas, usando o Javascript, precisamos trocar informações entre as camadas físicas diferentes, o cliente (por intermédio de um Browser) solicitando recursos de um servidor remoto (lado servidor).</p>
<p>Dentre as estratégias para essa troca de recursos entre as camadas distintas, temos IFrame, <a href="http://www.milfont.org/tech/category/web-development/xmlhttprequest/">XHR</a> e o Scripttag.</p>
<p>IFrame era uma técnica muito comum na era pré-ajax, mas que causava vários problemas, além da complexidade desnecessária e natureza gambiarrosa. Um dos problemas da técnica era quando se perdia a referência entre os frames e as páginas que os evocam (acontecia com uma frequência não tão insignificante). Geralmente os frameworks implementam a técnica de IFrame por questão de compatibilidade com browsers mais antigos. Quem não se lembra do escondido.jsp (ou escondido.php, escondido.asp, escondido.etc &#8230;)?</p>
<p>Como vimos em um <a href="http://www.milfont.org/tech/2007/10/02/eval-is-evil/">post passado</a>, a técnica de usar o XHR nos proporciona trabalhar com o parsing de XML ou a montagem dinâmica de objetos serializáveis, seja com &#8220;Eval&#8221; ou usando a capacidade dinâmica da linguagem de definir objetos de forma simples em tempo de execução. Vimos que usar Eval não é bom porque &#8220;<a href="http://www.milfont.org/tech/2007/10/02/eval-is-evil/">Eval is Evil</a>&#8220;.</p>
<p>A técnica de Scripttag  está em alta porque aproveita a própria capacidade do browser para instanciar um trecho de código serializável entre as camadas físicas distintas. A técnica está descrita no <a href="http://ajaxpatterns.org/On-Demand_Javascript">Pattern</a> Lazy Loading Javascript ou  On-Demand javascript</p>
<p>A técnica consiste em se obter um recurso do servidor em forma de texto, mas já formatado como um código (entidade) javascript e adicionar esse trecho na seção head da página, fazendo com que o próprio Browser instancie como se estivesse lendo a página na carga inicial. Vejamos:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> JSONRequest<span style="color: #009900;">&#40;</span>url<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
   <span style="color: #003366; font-weight: bold;">var</span> head <span style="color: #339933;">=</span> document.<span style="color: #660066;">getElementsByTagName</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;head&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
   <span style="color: #003366; font-weight: bold;">var</span> script <span style="color: #339933;">=</span> document.<span style="color: #660066;">createElement</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'script'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   script.<span style="color: #660066;">id</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">'TriadworksOnDemand'</span><span style="color: #339933;">;</span>
   script.<span style="color: #660066;">type</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">'text/javascript'</span><span style="color: #339933;">;</span>
   script.<span style="color: #660066;">src</span> <span style="color: #339933;">=</span> url<span style="color: #339933;">;</span>
   head.<span style="color: #660066;">appendChild</span><span style="color: #009900;">&#40;</span>script<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">function</span> montaGrid<span style="color: #009900;">&#40;</span>usuarios<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #006600; font-style: italic;">//aguarda um array de usuarios</span>
    <span style="color: #000066; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">var</span> x <span style="color: #000066; font-weight: bold;">in</span> usuarios<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #006600; font-style: italic;">//pega usuarios[x]...</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">function</span> pesquisar<span style="color: #009900;">&#40;</span>id<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #003366; font-weight: bold;">var</span> url <span style="color: #339933;">=</span> <span style="color: #3366CC;">'http://server_path/usuario/'</span><span style="color: #339933;">+</span>id
                 <span style="color: #339933;">+</span><span style="color: #3366CC;">&quot;/?callback=&quot;</span><span style="color: #339933;">+</span>montaGrid<span style="color: #339933;">;</span>
    JSONRequest<span style="color: #009900;">&#40;</span>url<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
pesquisar<span style="color: #009900;">&#40;</span><span style="color: #CC0000;">101</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Observe que criamos uma função chamada JSONRequest, que basicamente pega uma url e adiciona dinamicamente na seção head da página. Essa url é uma saída texto pelo servidor no formato JSON, utilizando o modelo REST para obter um recurso, ou seja, o servidor responde com um objeto serializável no endereço /usuario/id porque ele reconhece que as requisições a esse endereço são lógicas CRUD para a captura do recurso &#8220;usuário&#8221;. Passo como parâmetro uma variável chamada callback para o servidor renderizar a execução dessa função para ser interpretada assim que o Browser anexar a resposta.</p>
<p>A resposta viria mais ou menos assim:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">montaGrid<span style="color: #009900;">&#40;</span> <span style="color: #009900;">&#91;</span>
          <span style="color: #009900;">&#123;</span><span style="color: #3366CC;">'id'</span><span style="color: #339933;">:</span><span style="color: #3366CC;">'101'</span><span style="color: #339933;">,</span>
           <span style="color: #3366CC;">'nome'</span><span style="color: #339933;">:</span><span style="color: #3366CC;">'Christiano'</span><span style="color: #339933;">,</span>
           <span style="color: #3366CC;">'sobrenome'</span><span style="color: #339933;">:</span><span style="color: #3366CC;">'Milfont'</span><span style="color: #339933;">,</span>
           <span style="color: #3366CC;">'email'</span><span style="color: #339933;">:</span><span style="color: #3366CC;">'cmilfont@gmail.com'</span>
          <span style="color: #009900;">&#125;</span> <span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#41;</span></pre></div></div>

<p>AO executar a função <strong>JSONRequest</strong>, o código anexa a resposta do servidor na seção Head da página e então o Browser interpreta como se estivesse lendo na carga da página, executando a função montaGrid.</p>
<p>Diferenças entre as abordagens Scripttag e XHR.</p>
<table>
<tr>
<th scope="col"></th>
<th scope="col">XmlHttpRequest</th>
<th scope="col">Dynamic script Tag</th>
</tr>
<tr>
<th scope="row">Compatível com Cross-browser?</th>
<td>Não *</td>
<td>Sim</td>
</tr>
<tr>
<th scope="row">Cross-domain browser security enforced?</th>
<td>Sim</td>
<td>Não</td>
</tr>
<tr>
<th scope="row">Trabalha com  HTTP status codes?</th>
<td>Sim</td>
<td>Não (falha com outro código HTTP diferente de  200)</td>
</tr>
<tr>
<th scope="row">Supports HTTP GET and POST?</th>
<td>Sim</td>
<td>Não (Somente GET)</td>
</tr>
<tr>
<th scope="row">Pode receber/enviar HTTP headers?</th>
<td>Sim</td>
<td>Não</td>
</tr>
<tr>
<th scope="row">Pode receber XML?</th>
<td>Sim</td>
<td>Sim (mas embutido na sentença JavaScript)</td>
</tr>
<tr>
<th scope="row">Pode receber JSON?</th>
<td>Sim</td>
<td>Sim (mas embutido na sentença JavaScript)</td>
</tr>
<tr>
<th scope="row">Oferece chamadas síncronas e assíncronas?</th>
<td>Sim</td>
<td>Não (somente assíncronas)</td>
</tr>
</table>
<p>* &#8211; Basicamente poderíamos dizer que é compatível sim, mas com a diferença na implementação. Somente os browsers mais antigos não possuirão o objeto necessário.</p>
<p>Então o uso racional das abordagens vai depender da necessidade de características de cada uma, cada qual possui suas vantagens e desvantagens. Mais em <a href="http://www.xml.com/lpt/a/1636">XML.com</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.milfont.org/tech/2007/10/08/script-tag/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
	</channel>
</rss>

