<?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>Appcelerant &#187; Example</title>
	<atom:link href="http://www.appcelerant.com/category/example/feed" rel="self" type="application/rss+xml" />
	<link>http://www.appcelerant.com</link>
	<description>Appcelerator blog focused on helping you build your next killer mobile, desktop and web based applications</description>
	<lastBuildDate>Thu, 24 Jun 2010 17:43:53 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Using Appcelerator Interceptors for I18N, L10N, G11N</title>
		<link>http://www.appcelerant.com/using-appcelerator-interceptors-for-i18n-l10n-g11n.html</link>
		<comments>http://www.appcelerant.com/using-appcelerator-interceptors-for-i18n-l10n-g11n.html#comments</comments>
		<pubDate>Fri, 17 Oct 2008 15:10:10 +0000</pubDate>
		<dc:creator>Andrew Zuercher</dc:creator>
				<category><![CDATA[Documentation]]></category>
		<category><![CDATA[Example]]></category>

		<guid isPermaLink="false">http://www.appcelerant.com/?p=93</guid>
		<description><![CDATA[What&#8217;s the problem?
Just implementing resource bundles to localize your application doesn&#8217;t quite cut it.  You need to do things like work with localized dates in the browser (including formatting), numbers, currencies, and who knows what else to munge your data.  It sure would be nice if there were a way to transparently make [...]<script type="text/javascript">SHARETHIS.addEntry({ title: "Using Appcelerator Interceptors for I18N, L10N, G11N", url: "http://www.appcelerant.com/using-appcelerator-interceptors-for-i18n-l10n-g11n.html" });</script>]]></description>
			<content:encoded><![CDATA[<p></p><h3>What&#8217;s the problem?</h3>
<p>Just implementing resource bundles to localize your application doesn&#8217;t quite cut it.  You need to do things like work with localized dates in the browser (including formatting), numbers, currencies, and who knows what else to munge your data.  It sure would be nice if there were a way to transparently make this happen in a message oriented way that does not require server side awareness for services, can you help me with this problem?  sure.</p>
<h3>Built in &#8216;ization&#8217; support in Appcelerator</h3>
<p>Globalization (G11N) and Localization (L10N) both get lumped into Internationalization (I18N) &#8211; how to deal with languages, time, data formats and everything else that goes on making it so that people in different places in the world can use your glorious application.  Appcelerator <a href="http://doc.appcelerator.org/reference/localization/index.html">localization</a> helps you out with this on some really simple levels with the langid attribute:</p>

<div class="wp_syntax"><div class="code"><pre class="xml">  <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;span</span> <span style="color: #000066;">langid</span>=<span style="color: #ff0000;">&quot;account.number.title&quot;</span><span style="font-weight: bold; color: black;">&gt;</span></span><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/span<span style="font-weight: bold; color: black;">&gt;</span></span></span>:<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;input</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;text&quot;</span><span style="font-weight: bold; color: black;">&gt;</span></span><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/input<span style="font-weight: bold; color: black;">&gt;</span></span></span></pre></div></div>

<p>This should arm you successfully with an ability to deal with things like simple messages and labeling in your application.  Now if you want to blend in your data payload to render localized text, you can make use of appcelerator javascript functions Appcelerator.Localization.get and the more powerful but less documented Appcelerator.Localization.getWithFormat.</p>

<div class="wp_syntax"><div class="code"><pre class="xml"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;script<span style="font-weight: bold; color: black;">&gt;</span></span></span>
  var en_lang_bundle = {
	&quot;invalidlogin.message&quot;: 
&quot;Dear sir/madame, the username you provided '#{username}' does not exist:&quot;
  }
  Appcelerator.Localization.addLanguageBundle(&quot;en&quot;,English&quot;,$H(en_lang_bundle));
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/script<span style="font-weight: bold; color: black;">&gt;</span></span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;span</span> <span style="color: #000066;">on</span>=<span style="color: #ff0000;">&quot;l:invalidlogin.response then value[text]&quot;</span><span style="font-weight: bold; color: black;">&gt;</span></span><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/span<span style="font-weight: bold; color: black;">&gt;</span></span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;app:script</span> <span style="color: #000066;">on</span>=<span style="color: #ff0000;">&quot;r:invalidlogin.response then execute&quot;</span><span style="font-weight: bold; color: black;">&gt;</span></span>
  var text = Appcelerator.Localization.getWithFormat('invalidlogin.message',
null,null,{username:'azuercher'});
  $MQ('l:invalidlogin.response',{text:text});
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/app:script<span style="font-weight: bold; color: black;">&gt;</span></span></span></pre></div></div>

<p>This is a nice way to use message indirection for munging messages, but really is quite messy and anything but transparent.  There must be a better way!</p>
<h3>Interceptors</h3>
<p>A lesser known feature of Appcelerator is the concept of interceptors &#8211; client side behavior that you can have play in-between the delivery of queued messages to their recipients.  In the case for client-2-server orchestration all server requests and their corresponding response messages are enqueued and subject to perversion by interceptors.  You just have to know how to implement them.  Lets say that whenever I send a CRUD request to the server called &#8216;r:createorder.request&#8217; I want to add a new attribute called last_modified_utc which is a numerical representation of a utc date as a long.  I can add that to the payload to the back end service completely transparently with the Appcelerator.Util.ServiceBroker.addInterceptor method &#8211; the method takes a callback to the following:</p>
<ul>
<li>interceptQueue &#8211; where requests from client to server are intercepted</li>
<li>interceptSendToListener &#8211; where responses from server to client are intercepted</li>
</ul>
<p>In the example below I</p>
<ul>
<li>add &#8216;last_modified_utc&#8217; as a current utc long to r:createorder.request which is consumed by my back end service</li>
<li>transform &#8216;last_modified_utc&#8217; in the r:createorder.response from utc to a localized string in the browser</li>
</ul>

<div class="wp_syntax"><div class="code"><pre class="javascript"><span style="color: #66cc66;">&lt;</span>app:script<span style="color: #66cc66;">&gt;</span>
	<span style="color: #003366; font-weight: bold;">var</span> interceptor = <span style="color: #66cc66;">&#123;</span>
	    interceptQueue: <span style="color: #003366; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span>msg, callback, messageType, scope<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
			<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #66cc66;">&#40;</span>messageType==<span style="color: #3366CC;">'remote:createorder.request'</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
				msg.<span style="color: #006600;">data</span>.<span style="color: #006600;">last_modified_utc</span> = <span style="color: #003366; font-weight: bold;">new</span> Date<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">getTime</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
			<span style="color: #66cc66;">&#125;</span>
	        <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">true</span>;
	    <span style="color: #66cc66;">&#125;</span>,
	    interceptDispatch: <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #66cc66;">&#40;</span>requestid, type, data, datatype<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
	        <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">true</span>;
	    <span style="color: #66cc66;">&#125;</span>,
	    interceptSendToListener: <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #66cc66;">&#40;</span>listener, messageType, data, datatype<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
			<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #66cc66;">&#40;</span>messageType==<span style="color: #3366CC;">'createorder.response'</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
				date = <span style="color: #003366; font-weight: bold;">new</span> Date<span style="color: #66cc66;">&#40;</span>data.<span style="color: #006600;">last_modified_utc</span><span style="color: #66cc66;">&#41;</span>;
				data.<span style="color: #006600;">last_modified</span> = date.<span style="color: #006600;">toString</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
			<span style="color: #66cc66;">&#125;</span>
	        <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">true</span>;
	    <span style="color: #66cc66;">&#125;</span>
	<span style="color: #66cc66;">&#125;</span>;
	Appcelerator.<span style="color: #006600;">Util</span>.<span style="color: #006600;">ServiceBroker</span>.<span style="color: #006600;">addInterceptor</span><span style="color: #66cc66;">&#40;</span>interceptor<span style="color: #66cc66;">&#41;</span>;
	$MQ<span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'r:createorder.request'</span>,<span style="color: #66cc66;">&#123;</span>hi:<span style="color: #3366CC;">'there'</span><span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&lt;/</span>app:script<span style="color: #66cc66;">&gt;</span></pre></div></div>

<p>Obviously, you can take this a step further and then add interceptors that munge your data conditionally based on the current locale defined in Appcelerator.Localization.  The benefit here is that this data transformation happens at a layer outside of my normal pub/sub for messages in Appcelerator &#8211; the normal pattern is to either replace or add attributes in the payload.  </p>
<h3>wrap up</h3>
<p>Although not a shrink wrapped solution for I18N in all its glory, its not hard to implement interceptors to do so.  Beyond I18N, a lot of other aspects for your messages can be mutated in the browser non-intrusively.  Although the key demonstration here is data transformation, you would potentially add other horizontal services into your application.</p>
<p>
this article cross-posted at <a href="http://blog.zuerchtech.com/2008/10/13/using-appcelerator-interceptors-for-i18n-l10n-g11n/">http://blog.zuerchtech.com/2008/10/13/using-appcelerator-interceptors-for-i18n-l10n-g11n</a></p>
<p><a href="http://sharethis.com/item?&wp=2.8.4&amp;publisher=fb25d17b-38b5-47ed-9857-f171051e9899&amp;title=Using+Appcelerator+Interceptors+for+I18N%2C+L10N%2C+G11N&amp;url=http%3A%2F%2Fwww.appcelerant.com%2Fusing-appcelerator-interceptors-for-i18n-l10n-g11n.html">ShareThis</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.appcelerant.com/using-appcelerator-interceptors-for-i18n-l10n-g11n.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Five Ways To Load Images Faster On Browser</title>
		<link>http://www.appcelerant.com/five-ways-to-load-images-faster-on-browser.html</link>
		<comments>http://www.appcelerant.com/five-ways-to-load-images-faster-on-browser.html#comments</comments>
		<pubDate>Mon, 29 Sep 2008 17:45:00 +0000</pubDate>
		<dc:creator>Hamed Hashemi</dc:creator>
				<category><![CDATA[Example]]></category>
		<category><![CDATA[images]]></category>

		<guid isPermaLink="false">http://www.appcelerant.com/?p=86</guid>
		<description><![CDATA[If you&#8217;re running a heavy-app, you most likely will end up looking for ways to optimize its load time. Sometimes the issues are in your JS code, but many times it comes down to how many resources the browser has to load. Loading many JS files and images is generally not good because of the [...]<script type="text/javascript">SHARETHIS.addEntry({ title: "Five Ways To Load Images Faster On Browser", url: "http://www.appcelerant.com/five-ways-to-load-images-faster-on-browser.html" });</script>]]></description>
			<content:encoded><![CDATA[<p></p><p>If you&#8217;re running a heavy-app, you most likely will end up looking for ways to optimize its load time. Sometimes the issues are in your JS code, but many times it comes down to how many resources the browser has to load. Loading many JS files and images is generally not good because of the number of HTTP requests that your browser will have to make. And sometimes doing JS processing on your images can cause slow downs as well. Here are some ways that you can speed up the images on your app:</p>
<p>1) <strong>Limit transparent PNGs.</strong> Unless you are a Facebook or Apple, you probably don&#8217;t have the clout to ask users to upgrade from IE6. And in any real-world website, you&#8217;ll want to support both IE6 and do transparent PNGs. The way to do this is adding ActiveX filters to your images. But this is an expensive operation, so instead of having many transparent PNG icons you may want to consider serving up GIFs where possible for IE6 users. It may require having extra images around, but you&#8217;ll see an improvement on the page load.</p>
<p style="text-align: left;">2) <strong>Consider using CSS background images. </strong>If you have a large image to load or many small images that are not essential for the app, consider moving them from img tags to background images in a CSS selector. The document will start loading and rendering instead of waiting for all the images to load. Some browsers won&#8217;t even display the page until all the images are downloaded and this should solve that.</p>
<p style="text-align: left;">3) <strong>Use image concatenation. </strong>If you have a few images that are all the same size (e.g. toolbar icons), make them all one image side-by-side. Then you can use background-position in your CSS to display different parts of the image. The trick here is that you&#8217;ll be saving many of those expensive HTTP requests to the server.</p>
<p style="text-align: left;">4) <strong>Correct response</strong><strong> headers</strong>. This one is probably a no brainer. But you&#8217;ll want to be sure that your web server is sending the correct headers in the HTTP response so that the browser knows how to cache the images.</p>
<p style="text-align: left;">5) <strong>Load images in Javascript. </strong>If you have a few large images (say for a front page news bulletin), it maybe best to preload them using new Image() while displaying a loading indicator. This will at least get the rest of the site loaded and processed.</p>
<p>A really good tool to use for inspecting the resources of your app is the Net section of Firebug. Here you&#8217;ll see the files have been fetched via HTTP, whether or not a subsequent HTTP request returned a not modified response, the file sizes, the load time, and also just as important, the order that the resources were fetched.</p>
<p><a href="http://sharethis.com/item?&wp=2.8.4&amp;publisher=fb25d17b-38b5-47ed-9857-f171051e9899&amp;title=Five+Ways+To+Load+Images+Faster+On+Browser&amp;url=http%3A%2F%2Fwww.appcelerant.com%2Ffive-ways-to-load-images-faster-on-browser.html">ShareThis</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.appcelerant.com/five-ways-to-load-images-faster-on-browser.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Deep-linking into RIAs</title>
		<link>http://www.appcelerant.com/deep-linking-into-rias.html</link>
		<comments>http://www.appcelerant.com/deep-linking-into-rias.html#comments</comments>
		<pubDate>Fri, 05 Sep 2008 14:32:58 +0000</pubDate>
		<dc:creator>Mark Luffel</dc:creator>
				<category><![CDATA[Documentation]]></category>
		<category><![CDATA[Example]]></category>

		<guid isPermaLink="false">http://www.appcelerant.com/?p=81</guid>
		<description><![CDATA[Deep-linking is important. It&#8217;s what makes the web so &#8230; webby. Usability guru Jakob Nielsen tells us that Deep Linking is Good Linking, and hypertext pioneer Doug Engelbart encourages us to make &#8220;Every Object Addressable.&#8221;
With the old-web, deep-linking was easy because everything was a page and every page had a URL. In the new RIA [...]<script type="text/javascript">SHARETHIS.addEntry({ title: "Deep-linking into RIAs", url: "http://www.appcelerant.com/deep-linking-into-rias.html" });</script>]]></description>
			<content:encoded><![CDATA[<p></p><p>Deep-linking is important. It&#8217;s what makes the web so &#8230; webby. Usability guru Jakob Nielsen tells us that <a href="http://www.useit.com/alertbox/20020303.html">Deep Linking is Good Linking</a>, and hypertext pioneer Doug Engelbart encourages us to make &#8220;<a href="http://www.bootstrap.org/augdocs/augment-132082.htm#11K">Every Object Addressable</a>.&#8221;</p>
<p>With the old-web, deep-linking was easy because everything was a page and every page had a URL. In the new RIA web however, a complex web app can fit into a single page, and without some careful programming, we lose the ability to bookmark or share objects and places inside the app.</p>
<p>To get deep-linking in an RIA, we need to store the link info in the <a href="http://www.unix.com.ua/orelly/web/jscript/refp_419.html">hash part</a> of the URL. For example, the Google Docreader team has documented their scheme for <a href="http://code.google.com/docreader/#p=google-documentation-reader&amp;s=google-documentation-reader&amp;t=UrlFormat">deep-linking into ajax-ified documentation</a>. Deep-linking to Flash content with <a href="http://www.asual.com/swfaddress/">SWFAddress</a> also takes advantage of the hash component of a URL.</p>
<p>In Appcelerator, a convenient way to provide deep-linkable addresses (as well as sane forward-backward button support) is to use <a href="http://appceleratordemo.appspot.com/routes">Appcelerator Routes</a> to map the hash part of a URL onto an Appcelerator message. Routes have a similar syntax to <a href="http://manuals.rubyonrails.com/read/chapter/65">Ruby on Rails routes</a>, but are entirely client-side.</p>
<p>An example routes definition:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript">routes<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#123;</span>
    <span style="color: #3366CC;">'#home'</span> :                  <span style="color: #3366CC;">'r:get.home.request'</span>,
    <span style="color: #3366CC;">'#cat/:id'</span> :               <span style="color: #3366CC;">'r:get.animal.request[type=cat,id=#{id}]'</span>,
    <span style="color: #3366CC;">'#dog/:id'</span> :               <span style="color: #3366CC;">'r:get.animal.request[type=dog,id=#{id}]'</span>,
    <span style="color: #3366CC;">'#yaps/:fromid/:toid'</span> :    <span style="color: #3366CC;">'r:get.messages.request[dogid=#{fromid},catid=#{toid}]'</span>,
    <span style="color: #3366CC;">'#hisses/:fromid/:toid'</span> :  <span style="color: #3366CC;">'r:get.messages.request[catid=#{fromid},dogid=#{toid}]'</span>,
<span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>;</pre></div></div>

<p>Now, when someone navigates to <tt>http://yourapp.com/pets#dog/fido</tt>, the message <tt>r:get.animal.request[type=dog,id=fido]</tt> will be fired on page load. Inside your UI code, you can react to the response of this message to switch the active section of your app:</p>

<div class="wp_syntax"><div class="code"><pre class="xml"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;div</span> <span style="color: #000066;">on</span>=<span style="color: #ff0000;">&quot;r:get.animal.response[type=dog] then show and bind[dog_info] else hide&quot;</span> <span style="color: #000066;">style</span>=<span style="color: #ff0000;">&quot;display: none&quot;</span><span style="font-weight: bold; color: black;">&gt;</span></span>
  My Cat Friends:
  <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;</span> app:iterator <span style="color: #000066;">on</span>=<span style="color: #ff0000;">&quot;r:get.animal.request[type=dog] then execute&quot;</span> <span style="color: #000066;">property</span>=<span style="color: #ff0000;">&quot;dog_info.cat_friends&quot;</span><span style="font-weight: bold; color: black;">&gt;</span></span>
    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;a</span> <span style="color: #000066;">href</span>=<span style="color: #ff0000;">&quot;#cat/#{cat_id}&quot;</span><span style="font-weight: bold; color: black;">&gt;</span></span>#{name}<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/a<span style="font-weight: bold; color: black;">&gt;</span></span></span> (<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;a</span> <span style="color: #000066;">href</span>=<span style="color: #ff0000;">&quot;#yaps/#{my_id}/#{cat_id}&quot;</span><span style="font-weight: bold; color: black;">&gt;</span></span>Our messages<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/a<span style="font-weight: bold; color: black;">&gt;</span></span></span>)<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;br</span><span style="font-weight: bold; color: black;">/&gt;</span></span>
  <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;</span> /app:iterator<span style="font-weight: bold; color: black;">&gt;</span></span>
  <span style="color: #009900;"><span style="color: #808080; font-style: italic;">&lt;!-- more UI for viewing a dog --&gt;</span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/div<span style="font-weight: bold; color: black;">&gt;</span></span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;div</span> <span style="color: #000066;">on</span>=<span style="color: #ff0000;">&quot;r:get.animal.response[type=cat] then show and bind[cat_info] else hide&quot;</span> <span style="color: #000066;">style</span>=<span style="color: #ff0000;">&quot;display: none&quot;</span><span style="font-weight: bold; color: black;">&gt;</span></span>
  <span style="color: #009900;"><span style="color: #808080; font-style: italic;">&lt;!-- UI for viewing a cat --&gt;</span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/div<span style="font-weight: bold; color: black;">&gt;</span></span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;div<span style="font-weight: bold; color: black;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #808080; font-style: italic;">&lt;!-- another section of the app --&gt;</span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/div<span style="font-weight: bold; color: black;">&gt;</span></span></span></pre></div></div>

<p>So, when <tt>http://yourapp.com/pets#dog/fido</tt> loads, a remote message will be fired, a response (hopefully containing some friends) will return, the iterator will be executed, and links will be generated. If Fido has a cat friend named Milo, we&#8217;d get HTML generated (client-side), like this:</p>

<div class="wp_syntax"><div class="code"><pre class="xml">    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;a</span> <span style="color: #000066;">href</span>=<span style="color: #ff0000;">&quot;#cat/milo&quot;</span><span style="font-weight: bold; color: black;">&gt;</span></span>Milo<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/a<span style="font-weight: bold; color: black;">&gt;</span></span></span> (<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;a</span> <span style="color: #000066;">href</span>=<span style="color: #ff0000;">&quot;#yaps/fido/milo&quot;</span><span style="font-weight: bold; color: black;">&gt;</span></span>Our messages<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/a<span style="font-weight: bold; color: black;">&gt;</span></span></span>)</pre></div></div>

<p>Both of those links will fire an Appcelerator message when clicked, as well as changing the hash component of the URL (which is what makes forward/backward usable). Because we&#8217;ve set up an else-clause for the dog-ui section (<tt>r:get.animal.request[type=dog] then show and bind[dog_info] else hide</tt>), if the user clicks the <tt>#cat/milo</tt> link, the currect section will hide, and the cat-ui section will be shown.</p>
<p>So, with a few lines of declarative javascript, we&#8217;ve been able to retain all the webby goodness of deep-linking, and also reap the benefits of Appcelerator&#8217;s transparent client/server messaging and client-side templating. Cool, huh?</p>
<p><a href="http://sharethis.com/item?&wp=2.8.4&amp;publisher=fb25d17b-38b5-47ed-9857-f171051e9899&amp;title=Deep-linking+into+RIAs&amp;url=http%3A%2F%2Fwww.appcelerant.com%2Fdeep-linking-into-rias.html">ShareThis</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.appcelerant.com/deep-linking-into-rias.html/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Snappshot &#8212; Photo Editing Tool</title>
		<link>http://www.appcelerant.com/snappshot-photo-editing-tool.html</link>
		<comments>http://www.appcelerant.com/snappshot-photo-editing-tool.html#comments</comments>
		<pubDate>Thu, 22 May 2008 20:20:18 +0000</pubDate>
		<dc:creator>Hamed Hashemi</dc:creator>
				<category><![CDATA[Example]]></category>

		<guid isPermaLink="false">http://www.appcelerant.com/?p=59</guid>
		<description><![CDATA[Recently a popular photo editing suite released an online version of their application. And it was written and deployed using Flex. Naturally of course the first thing we wanted to do was prove that we could write something similar using Appcelerator.
We enjoy using simple web standards (CSS/HTML) to build UIs, and with Appcelerator writing server/client [...]<script type="text/javascript">SHARETHIS.addEntry({ title: "Snappshot &#8212; Photo Editing Tool", url: "http://www.appcelerant.com/snappshot-photo-editing-tool.html" });</script>]]></description>
			<content:encoded><![CDATA[<p></p><p>Recently a popular photo editing suite released an online version of their application. And it was written and deployed using Flex. Naturally of course the first thing we wanted to do was prove that we could write something similar using Appcelerator.</p>
<p>We enjoy using simple web standards (CSS/HTML) to build UIs, and with Appcelerator writing server/client code is trivial and just could not be any easier. So, we gave it our best shot to see what we could do in 2 days amount of work. The result? <a href="http://snappshot.appcelerator.org/">Snappshot</a>.</p>
<p>It&#8217;s all written using HTML, CSS, Javascript, Appcelerator, and with Ruby on Rails on the backend. </p>
<p>Best of all, here&#8217;s the <a href="http://demos.appcelerator.org/snappshot.zip">link to the entire code</a> so you can see how we did it.</p>
<p><a href="http://sharethis.com/item?&wp=2.8.4&amp;publisher=fb25d17b-38b5-47ed-9857-f171051e9899&amp;title=Snappshot+%26%238212%3B+Photo+Editing+Tool&amp;url=http%3A%2F%2Fwww.appcelerant.com%2Fsnappshot-photo-editing-tool.html">ShareThis</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.appcelerant.com/snappshot-photo-editing-tool.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Appcelerator Plus Flex</title>
		<link>http://www.appcelerant.com/appcelerator-plus-flex.html</link>
		<comments>http://www.appcelerant.com/appcelerator-plus-flex.html#comments</comments>
		<pubDate>Sat, 26 Apr 2008 17:30:58 +0000</pubDate>
		<dc:creator>Tejus Parikh</dc:creator>
				<category><![CDATA[Example]]></category>

		<guid isPermaLink="false">http://www.appcelerant.com/?p=56</guid>
		<description><![CDATA[Appcelerator&#8217;s Unified Widget Platform enables developers to both create new widgets and to wrap existing widgets.  The latter capability is very powerful because it gives developers one platform from which they can leverage any widget.   Currently, our platform contains widgets from Yahoo, ExtJS and several small widget providers.  In this blog [...]<script type="text/javascript">SHARETHIS.addEntry({ title: "Appcelerator Plus Flex", url: "http://www.appcelerant.com/appcelerator-plus-flex.html" });</script>]]></description>
			<content:encoded><![CDATA[<p></p><p>Appcelerator&#8217;s Unified Widget Platform enables developers to both create new widgets and to wrap existing widgets.  The latter capability is very powerful because it gives developers one platform from which they can leverage any widget.   Currently, our platform contains widgets from Yahoo, ExtJS and several small widget providers.  In this blog post, I will show you how to create an Appcelerator widget that wraps a Flex component using Adobe&#8217;s Flex-Ajax Bridge.  </p>
<p>What is the Flex-Ajax Bridge?  In Adobe&#8217;s own words:</p>
<blockquote style="font-size: smaller; margin: 10px 20px"><p>
 Rather than having to define new, simplified APIs to expose a graph of ActionScript objects to JavaScript, with FABridge you can make your ActionScript classes available to JavaScript without any additional coding. After you insert the library, essentially anything you can do with ActionScript, you can do with JavaScript.
</p></blockquote>
<p>As a demonstration, I wrapped <a href="http://dougmccune.com/blog/">Doug Mccune&#8217;s</a> <a href="http://dougmccune.com/blog/2007/11/19/flex-coverflow-performance-improvement-flex-carousel-component-and-vertical-coverflow/">Flex Cover Flow</a> library as a Appcelerator Widget.   <a href="http://www.jamesward.org/wordpress/">James Ward</a> from Adobe was kind enough to donate the MXML shell with the Flex Ajax Bridge baked-in.</p>
<p>Once we had that, all we needed to do was just build a widget.  The details of building this widget are covered in the Create Widget Screencasts, <a href="http://www.appcelerator.org/screencast_view?id=4&#038;flash=true">Part 1</a> and <a href="">Part 2</a>.  The first screencast shows the basics of wrapping the widget.  The second adds some embellishments and demonstrates adding additional features into this widget.</p>
<p>The final result?  Our widget turned:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
</pre></td><td class="code"><pre class="xml"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;script</span> <span style="color: #000066;">language</span>=<span style="color: #ff0000;">&quot;JavaScript&quot;</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;text/javascript&quot;</span><span style="font-weight: bold; color: black;">&gt;</span></span>
    FABridge.addInitializationCallback(&quot;b_FlexFlow&quot;, FlexFlowInit);
&nbsp;
    function FlexFlowInit()
    {
        b = FABridge[&quot;b_FlexFlow&quot;].root();
        b.setReflectionEnable(true);
        b.setBgColor(0x000000);
        b.setHorizontalSpacing(100);
        b.setTweenDuration(0.65);
        b.setRotationAngle(70);
        b.setMaxImageWidth(200);
        b.setMaxImageHeight(200);
        b.setDataProvider(['P1230065.JPG','P1240078.JPG','P1260094.JPG','P1260095.JPG','P1260097.JPG']);
        b.getCfc().addEventListener(&quot;click&quot;, function() {;});
    }
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/script<span style="font-weight: bold; color: black;">&gt;</span></span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;object</span> <span style="color: #000066;">classid</span>=<span style="color: #ff0000;">&quot;clsid:D27CDB6E-AE6D-11cf-96B8-444553540000&quot;</span>
<span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;FlexFlowTest&quot;</span> <span style="color: #000066;">width</span>=<span style="color: #ff0000;">&quot;100%&quot;</span> <span style="color: #000066;">height</span>=<span style="color: #ff0000;">&quot;500&quot;</span>
<span style="color: #000066;">codebase</span>=<span style="color: #ff0000;">&quot;http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab&quot;</span><span style="font-weight: bold; color: black;">&gt;</span></span>
  <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;param</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;movie&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;FlexFlow.swf&quot;</span> <span style="font-weight: bold; color: black;">/&gt;</span></span>
  <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;param</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;flashvars&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;bridgeName=b_FlexFlow&quot;</span><span style="font-weight: bold; color: black;">/&gt;</span></span>
  <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;param</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;quality&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;high&quot;</span> <span style="font-weight: bold; color: black;">/&gt;</span></span>
  <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;param</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;allowScriptAccess&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;sameDomain&quot;</span> <span style="font-weight: bold; color: black;">/&gt;</span></span>
  <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;embed</span> <span style="color: #000066;">src</span>=<span style="color: #ff0000;">&quot;FlexFlow.swf&quot;</span> <span style="color: #000066;">quality</span>=<span style="color: #ff0000;">&quot;high&quot;</span>
    <span style="color: #000066;">width</span>=<span style="color: #ff0000;">&quot;100%&quot;</span> <span style="color: #000066;">height</span>=<span style="color: #ff0000;">&quot;500&quot;</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;FlexFlowTest&quot;</span> 
    <span style="color: #000066;">align</span>=<span style="color: #ff0000;">&quot;middle&quot;</span>
    <span style="color: #000066;">play</span>=<span style="color: #ff0000;">&quot;true&quot;</span>
    <span style="color: #000066;">loop</span>=<span style="color: #ff0000;">&quot;false&quot;</span>
    <span style="color: #000066;">quality</span>=<span style="color: #ff0000;">&quot;high&quot;</span>
    <span style="color: #000066;">allowScriptAccess</span>=<span style="color: #ff0000;">&quot;sameDomain&quot;</span>
    <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;application/x-shockwave-flash&quot;</span>
    <span style="color: #000066;">pluginspage</span>=<span style="color: #ff0000;">&quot;http://www.adobe.com/go/getflashplayer&quot;</span> 
    <span style="color: #000066;">flashvars</span>=<span style="color: #ff0000;">&quot;bridgeName=b_FlexFlow&quot;</span><span style="font-weight: bold; color: black;">&gt;</span></span>
  <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/embed<span style="font-weight: bold; color: black;">&gt;</span></span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/object<span style="font-weight: bold; color: black;">&gt;</span></span></span></pre></td></tr></table></div>

<p>into:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="xml">        <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;app:as_flexflow</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;flow&quot;</span> <span style="color: #000066;">on</span>=<span style="color: #ff0000;">&quot;r:get.albums.response then execute&quot;</span> 
                <span style="color: #000066;">property</span>=<span style="color: #ff0000;">&quot;covers&quot;</span> <span style="color: #000066;">img_height</span>=<span style="color: #ff0000;">&quot;400&quot;</span> <span style="color: #000066;">img_width</span>=<span style="color: #ff0000;">&quot;400&quot;</span><span style="font-weight: bold; color: black;">&gt;</span></span>
        <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/app:as_flexflow<span style="font-weight: bold; color: black;">&gt;</span></span></span></pre></td></tr></table></div>

<p>With a few more enhancements, this widget became a big part of our <a href="http://apptunes.appspot.com">Apptunes</a> demo (it&#8217;s the big piece in the middle).<br />
<iframe src="http://apptunes.appspot.com" height="645px" width="600px"></iframe></p>
<p>With the Flex-Ajax Bridge and Appcelerator, you can get the benefits of Flex-based components without having to abandon HTML, CSS and Javascript.</p>
<div class="techtags">Tech Tags: <a href="http://technorati.com/tag/ajax," rel="tag" class="techtag">ajax,</a> <a href="http://technorati.com/tag/appcelerator," rel="tag" class="techtag">appcelerator,</a> <a href="http://technorati.com/tag/flex," rel="tag" class="techtag">flex</a></div>
<p><a href="http://sharethis.com/item?&wp=2.8.4&amp;publisher=fb25d17b-38b5-47ed-9857-f171051e9899&amp;title=Appcelerator+Plus+Flex&amp;url=http%3A%2F%2Fwww.appcelerant.com%2Fappcelerator-plus-flex.html">ShareThis</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.appcelerant.com/appcelerator-plus-flex.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Implementing an Appcelerator Plugin</title>
		<link>http://www.appcelerant.com/implementing-an-appcelerator-plugin.html</link>
		<comments>http://www.appcelerant.com/implementing-an-appcelerator-plugin.html#comments</comments>
		<pubDate>Tue, 04 Mar 2008 11:24:58 +0000</pubDate>
		<dc:creator>Andrew Zuercher</dc:creator>
				<category><![CDATA[Documentation]]></category>
		<category><![CDATA[Example]]></category>
		<category><![CDATA[Opinion]]></category>

		<guid isPermaLink="false">http://www.appcelerant.com/implementing-an-appcelerator-plugin.html</guid>
		<description><![CDATA[Purpose
The Appcelerator framework allows for the extension of the build and deployment process so that you can add components and modify the behavior of your service implementations.  It is quite powerful and not only restricted to services, plugins for example could span across to the modification of applications and the entire build and deployment [...]<script type="text/javascript">SHARETHIS.addEntry({ title: "Implementing an Appcelerator Plugin", url: "http://www.appcelerant.com/implementing-an-appcelerator-plugin.html" });</script>]]></description>
			<content:encoded><![CDATA[<p></p><h3>Purpose</h3>
<p>The Appcelerator framework allows for the extension of the build and deployment process so that you can add components and modify the behavior of your service implementations.  It is quite powerful and not only restricted to services, plugins for example could span across to the modification of applications and the entire build and deployment process for that matter.  For simplicity, this article will identify how to create a new component added to our java service for monitoring performance.</p>
<h3>Install Appcelerator</h3>
<p>I&#8217;ve assumed that you&#8217;ve successfully downloaded and installed Appcelerator from <a href="http://www.appcelerator.org/products">http://www.appcelerator.org/products</a>.  Once you&#8217;ve gone through the installer you can get the java service</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="html4strict">  app install:service java</pre></td></tr></table></div>

<p>You may want to get an existing plugin (I needed the java:spring plugin to implement my plugin):</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="html4strict">  app install:plugin java:spring</pre></td></tr></table></div>

<h3>Plugin Creation</h3>
<p>Lets assume that our plugin is going to be called java:perf, to create the plugin project:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="html4strict">  cd $HOME/workspace
  app create:plugin . java:perf</pre></td></tr></table></div>

<p>This will create a sub directory named java_perf, now you will want to create a proper license entry in your build.yml for example check out <a href="http://svn.appcelerator.org/appcelerator_plugins/java_perf/trunk/build.yml">build.yml</a>.  You now have the opportunity to modify the entry points in your <a href="http://svn.appcelerator.org/appcelerator_plugins/java_perf/trunk/src/java_perf.rb">java_perf.rb</a>.  I personally wanted to setup my install script so that:</p>
<ul>
<li> it dynamically builds the jar when we add the plugin to a project</li>
<li> modifies the spring.xml to include the bean entries for my component</li>
</ul>
<p>All of this is in before_add_plugin(event) callback.  If you want to see where this is called, check out <a href="http://svn.appcelerator.org/appcelerator_sdk/trunk/components/runtime/src/cmdline/commands/add_plugin.rb">add_plugin.rb</a>.  Once my coding is complete (added my source files to java_perf/src), I created the plugin distribution:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="html4strict">rake zip</pre></td></tr></table></div>

<h3>Install the plugin</h3>
<p>As you noticed, I haven&#8217;t covered debugging the plugin just yet, this is because I want to first set up the plugin for installation and then work with it in my install directory.  Lets install it to the local machine:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="html4strict">app install:plugin java_perf.zip</pre></td></tr></table></div>

<h3>Add the plugin to my project</h3>
<p>I thought that I&#8217;d create a blank java project real quick</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="html4strict">cd workspace
app create:project . myproject java</pre></td></tr></table></div>

<p>now we can add the spring plugin and our new java:perf plugin to our project</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="html4strict">cd myproject
app add:plugin java:spring
app add:plugin java:perf</pre></td></tr></table></div>

<p>You can now directly modify the java_perf.rb file in your install directory</p>
<ul>
<li> windows: c:/Program Files/Appcelerator/releases/plugin/java_perf/1.0</li>
<li> unix: /usr/local/Appcelerator/releases/plugin/java_perf/1.0</li>
<li> mac os: /Library/Appcelerator/releases/plugin/java_perf/1.0</li>
</ul>
<p>I suggest that you continue to modify the java_perf.rb this way to debug it and then finalize by copying back over to $HOME/workspace/java_perf</p>
<h3>Next Steps</h3>
<p>As a final parting you can release your new plugin so that others may be able to leverage it</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="html4strict">cd $HOME/workspace/java_perf
app release java_perf.zip</pre></td></tr></table></div>

<p>-andrew</p>
<p>this article is cross posted at:<br />
<a href="http://zuerchtech.com/2008/3/4/implementing-an-appcelerator-plugin">http://zuerchtech.com/2008/3/4/implementing-an-appcelerator-plugin</a></p>
<p><a href="http://sharethis.com/item?&wp=2.8.4&amp;publisher=fb25d17b-38b5-47ed-9857-f171051e9899&amp;title=Implementing+an+Appcelerator+Plugin&amp;url=http%3A%2F%2Fwww.appcelerant.com%2Fimplementing-an-appcelerator-plugin.html">ShareThis</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.appcelerant.com/implementing-an-appcelerator-plugin.html/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Effectively Implementing Appcelerator RIAs and Services</title>
		<link>http://www.appcelerant.com/effectively-implementing-appcelerator-rias-and-services.html</link>
		<comments>http://www.appcelerant.com/effectively-implementing-appcelerator-rias-and-services.html#comments</comments>
		<pubDate>Tue, 26 Feb 2008 06:53:47 +0000</pubDate>
		<dc:creator>Andrew Zuercher</dc:creator>
				<category><![CDATA[Documentation]]></category>
		<category><![CDATA[Example]]></category>
		<category><![CDATA[Opinion]]></category>

		<guid isPermaLink="false">http://www.appcelerant.com/effectively-implementing-appcelerator-rias-and-services.html</guid>
		<description><![CDATA[Purpose
If you are venturing to implement a Rich Internet Application (RIA) with Appcelerator, then there are features about the framework that I&#8217;m really geared up about that help you implement your solution effectively.  When used together these items enable the agile creation of solutions in a shorter time that integrate nicely with services in [...]<script type="text/javascript">SHARETHIS.addEntry({ title: "Effectively Implementing Appcelerator RIAs and Services", url: "http://www.appcelerant.com/effectively-implementing-appcelerator-rias-and-services.html" });</script>]]></description>
			<content:encoded><![CDATA[<p></p><h3>Purpose</h3>
<p>If you are venturing to implement a Rich Internet Application (RIA) with Appcelerator, then there are features about the framework that I&#8217;m really geared up about that help you implement your solution effectively.  When used together these items enable the agile creation of solutions in a shorter time that integrate nicely with services in an existing architecture and provide a richer user experience for clients.</p>
<h3>Achieving Re-use</h3>
<p>There are a bunch of ways to do this, personally I leverage app:content files judiciously.  You can provide args in the definition of your content files so that you can use the same content file over again.  Some things to keep in mind:</p>
<ul>
<li>reference the args as #{argname} in your element ids, any variables, and make sure that functions you call take this into account (possibly make them stateless)</li>
<li>the order in which the content file is loaded to make sure that listeners are properly setup to respond to messages</li>
</ul>
<p>here is an example app:content reference</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="xml"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;app:content</span> <span style="color: #000066;">lazy</span>=<span style="color: #ff0000;">&quot;false&quot;</span> <span style="color: #000066;">on</span>=<span style="color: #ff0000;">&quot;mainstate[person] then show else hide&quot;</span> 
  <span style="color: #000066;">args</span>=<span style="color: #ff0000;">&quot;{'prefix':'person'}&quot;</span><span style="font-weight: bold; color: black;">&gt;</span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/app:content<span style="font-weight: bold; color: black;">&gt;</span></span></span></pre></td></tr></table></div>

<p>here is the content.html file</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="html4strict"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;div</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#{prefix}header&quot;</span> ...
<span style="color: #000000; font-weight: bold;">&lt;/div&gt;</span></span></pre></td></tr></table></div>

<p>I know that this may be abstract, but the point is that you can use the arg &#8220;prefix&#8221; to reuse the file and provide alternative behavior based on it.</p>
<h3>Mocking Services</h3>
<p>You can mock out server side services extremely easily with the framework.  This is extremely useful whether your goal is:</p>
<ul>
<li>Visual Use Cases: implementing a prototype that results in 100% useable application code</li>
<li>Working offline: no need to run a web server at all, you can directly run off of a simple file</li>
</ul>
<p>Once you have this in place, you have a well defined contract in place which makes knocking out the service implementation a snap.</p>
<h3>No restart</h3>
<p>If you are just working on your application (no service work), you can directly make changes to your application without requiring rebuilding and redeploying your application.  In java I typically work directly in my tomcat deploy directory and have an ant task to pull the web files into my workspace.  With our next version of the framework coming out, this will be even easier with our support for Jetty coming and the Ruby based command line tool.  In the meantime, the following is useful in your java project:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="xml">ant pullweb</pre></td></tr></table></div>

<p>Make sure that you have your deploy.dir setup in your $HOME/.ant.properties for example:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="xml">deploy.dir=/Applications/apache-tomcat-6.0.14/webapps</pre></td></tr></table></div>

<p>With our Ruby implementation for example, this is even easier (running webbrick directly in your workspace).</p>
<h3>Great Support for Model Objects</h3>
<p>I&#8217;ve touched a bit on this in a previous post on <a href="http://www.appcelerant.com/json-serialization-with-appcelerator-java-services.html"><span class="caps">JSON</span> serialization with Appcelerator java services</a>.  To summarize the framework enables</p>
<ul>
<li>Hibernate persistence: ModelObjects can easily be used with our Hibernate integration</li>
<li><span class="caps">JSON</span> serialization: Serializing and deserialing complex objects is a snap</li>
</ul>
<h3>Slick support for forms</h3>
<p>In case you haven&#8217;t looked, you dont need to include a form tag anywhere in the application: simply add a fieldset attribute to your input elements and put something like this</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="xml"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;input</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;age&quot;</span> <span style="color: #000066;">fieldset</span>=<span style="color: #ff0000;">&quot;save_person&quot;</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;text&quot;</span><span style="font-weight: bold; color: black;">/&gt;</span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;input</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;name&quot;</span> <span style="color: #000066;">fieldset</span>=<span style="color: #ff0000;">&quot;save_person&quot;</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;text&quot;</span><span style="font-weight: bold; color: black;">/&gt;</span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;input</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;Create Person&quot;</span> <span style="color: #000066;">fieldset</span>=<span style="color: #ff0000;">&quot;save_person&quot;</span><span style="font-weight: bold; color: black;">/&gt;</span></span>
  on=&quot;click then r:create.person.request&quot; type=&quot;button&quot;/&gt;</pre></td></tr></table></div>

<p>This will create a message of type r:create.person.request with the payload being all your input elements with fieldset of &#8220;save_person&#8221; ex:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="javascript"><span style="color: #66cc66;">&#123;</span><span style="color: #3366CC;">'name'</span>:<span style="color: #3366CC;">'jim'</span>,<span style="color: #3366CC;">'age'</span>:<span style="color: #3366CC;">'35'</span><span style="color: #66cc66;">&#125;</span></pre></td></tr></table></div>

<p>To me, this is very eloquent solution to leveraging form input elements with a messaging architecture.</p>
<h3>Easy to use UI widgets</h3>
<p>I love some of the widgets that are at your fingertips.  Some of the ones that i use the most</p>
<ul>
<li>app:panel: slick styling</li>
<li>app:datatable: great way to show rows of data</li>
<li>app:chart: fantastic visual effects to bring life to data</li>
</ul>
<p>All these widgets have a very terse usage that is very intuitive.  For example, using this set, I was able to knock out a realtime dashboard application in 3 evenings.</p>
<h3>Service Platform Options</h3>
<p>Pitching the right framework is something that varies from project to project.  For example, possibly your client wants to leverage an existing java infrastructure and is sold on its robustness for scaling enterprise applications, while on the other side possibly you want to take advantage of using a Rails controller and <span class="caps">ORM</span>/Active Record implementation for rapid development.  On the same level you also have the option for implementing services to customers that deliver in a .Net solution architecture.  Many other platforms also exist (python, <span class="caps">PHP</span>) enabling the opportunity to plug into those services as well.</p>
<p>The app:get non-visual widget also makes pre-existing services accessible as well and since Messaging is at the heart of the implementation, plugging into an <span class="caps">ESB</span> or pure <span class="caps">MOM</span> framework is perfectly setup as well.</p>
<h3>Wrap Up</h3>
<p>In this article 7 key tips have been covered</p>
<ul>
<li>re-use</li>
<li>mock services</li>
<li>no restart</li>
<li>model objects</li>
<li>messaging &#38; forms</li>
<li>UI widgets</li>
<li>platform options</li>
</ul>
<p>Although there are more items that have not been covered here, these are the ones that appeal personally to me and have noticed a huge gain in doing much more with less effort.</p>
<p>
this article cross-posted at <a href="http://blog.zuerchtech.com/2008/02/26/effectively-implementing-appcelerator-rias-and-services/">http://blog.zuerchtech.com/2008/02/26/effectively-implementing-appcelerator-rias-and-services/</a></p>
<p><a href="http://sharethis.com/item?&wp=2.8.4&amp;publisher=fb25d17b-38b5-47ed-9857-f171051e9899&amp;title=Effectively+Implementing+Appcelerator+RIAs+and+Services&amp;url=http%3A%2F%2Fwww.appcelerant.com%2Feffectively-implementing-appcelerator-rias-and-services.html">ShareThis</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.appcelerant.com/effectively-implementing-appcelerator-rias-and-services.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Debugging Appcelerator Applications</title>
		<link>http://www.appcelerant.com/debugging-appcelerator-applications.html</link>
		<comments>http://www.appcelerant.com/debugging-appcelerator-applications.html#comments</comments>
		<pubDate>Thu, 21 Feb 2008 04:05:29 +0000</pubDate>
		<dc:creator>Andrew Zuercher</dc:creator>
				<category><![CDATA[Documentation]]></category>
		<category><![CDATA[Example]]></category>
		<category><![CDATA[Opinion]]></category>

		<guid isPermaLink="false">http://www.appcelerant.com/debugging-appcelerator-applications.html</guid>
		<description><![CDATA[Purpose
The ability to debug applications is critical when things go sideways on you.  I understand that for some of the developers out there learning a new framework can be challenging.  Appcelerator provides developers with the tool-set to drastically reduce the amount of javascript code that they need to write and to be honest [...]<script type="text/javascript">SHARETHIS.addEntry({ title: "Debugging Appcelerator Applications", url: "http://www.appcelerant.com/debugging-appcelerator-applications.html" });</script>]]></description>
			<content:encoded><![CDATA[<p></p><h3>Purpose</h3>
<p>The ability to debug applications is critical when things go sideways on you.  I understand that for some of the developers out there learning a new framework can be challenging.  Appcelerator provides developers with the tool-set to drastically reduce the amount of javascript code that they need to write and to be honest I think that the more you use the framework, the less you will need to debug applications as you familiarize yourself with the syntax.</p>
<h3>Alerts</h3>
<p>Prior to logging, alerts were the best way to display state during execution (showing you how old school I&#8217;ve been).  Nonetheless, sometimes this is just easier since it blocks execution until you confirm.  When you do this, you may want want to display objects.  Lets take for example the following</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="html4strict">alert(myobject);</pre></td></tr></table></div>

<p>You make get an alert that shows:</p>
<p><a href="http://www.appcelerant.com/wp-content/uploads/2008/02/alert_object.png" title="alert_object.png"><img src="http://www.appcelerant.com/wp-content/uploads/2008/02/alert_object.png" alt="alert_object.png" /></a></p>
<p>Well that isn&#8217;t very useful.  If you want a nice string representation, use the following</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="html4strict">alert(Object.toJSON(myobject));</pre></td></tr></table></div>

<p>Now you&#8217;ll get a nice JSON representation.</p>
<p><a href="http://www.appcelerant.com/wp-content/uploads/2008/02/alert_json.png" title="alert_json.png"><img src="http://www.appcelerant.com/wp-content/uploads/2008/02/alert_json.png" alt="alert_json.png" /></a></p>
<h3>Logging</h3>
<p>Safari and Firefox both provide you with the ability to view logging in the console.  For firefox, you need to install <a href="https://addons.mozilla.org/en-US/firefox/addon/1843">firebug</a>.  If you are a safari user, you can use <a href="http://webkit.org/">webkit</a> (from the Debug menu, click &#8220;Show Javascript Console&#8221;).  Both of which make available a console that displays log statements.</p>
<p>In firefox you can do the following in javascript</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="html4strict">console.log(&quot;wassup&quot;);</pre></td></tr></table></div>

<p>I suggest however that you dont do that!  Instead make use of the abstracted Logger</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="html4strict">Logger.info(&quot;wassup&quot;);</pre></td></tr></table></div>

<p>This will not only show up in Firefox, but also in Safari&#8217;s console.</p>
<p><a href="http://www.appcelerant.com/wp-content/uploads/2008/02/wassup.png" title="wassup.png"><img src="http://www.appcelerant.com/wp-content/uploads/2008/02/wassup.png" alt="wassup.png" /></a></p>
<p>On another note, you can use the debug=1 parameter in your URL and you will see a ton of appcelerator messages (ex: http:localhos:8080/myapp?debug=1).  I will caution you that it will almost look like spam given the amount of detail that is logged, but nonetheless its there if you want it.</p>
<p>You can also expand the Get and Post statements in firefox which will let you know what you have sent in your request and the JSON result that was returned from the server.</p>
<p><a href="http://www.appcelerant.com/wp-content/uploads/2008/02/ajaxlog.png" title="ajaxlog.png"><img src="http://www.appcelerant.com/wp-content/uploads/2008/02/ajaxlog.png" alt="ajaxlog.png" width="650" height="196" /></a></p>
<h3>In-line Debugging</h3>
<p>Lets say that you have an error in your app:script.  Well in Firefox, you can take a look at the console and that will give you some pretty good feedback, however its going to be some cryptic text and you can&#8217;t step through it.  You have 2 options that will enable you to step through the code:</p>
<ul>
<li>can make a call to a javascript function from your app:script (I normally define a project specific javascript file and put my functions in it)</li>
<li>define a $MQL in your javascript file &#8211; app:script goes away</li>
</ul>
<p>Here is scenario 1:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="html4strict"><span style="color: #009900;">&lt;app:script on<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;r:someevent.response then execute&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
  Myapp.dosomething(this.data);
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;</span><span style="color: #66cc66;">/</span>app:script&gt;</span></pre></td></tr></table></div>

<p>and the corresponding javascript</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="html4strict">Myapp = Class.create();
Myapp.dosomething = function(data)
{
  //code here
}</pre></td></tr></table></div>

<p>For scenario 2: alternatively you could just define in your javascript file</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="html4strict">$MQL('r:someevent.response',function(type,msg,datatype,from)
{
	//code here
});</pre></td></tr></table></div>

<p>The downside of this is that your implementation is not colocated in a single html file, but the upside is that you can debug it.  Note that if you are not using content files, then you could alternatively define the above in a script element instead (a little cleaner), however if its a large app, then you really will want to decompose your app and use content files.</p>
<h3>IE Specific Debugging</h3>
<p>To be honest I&#8217;m not a huge IE fan, but it makes up an install base of 80% of the market.  Chances are that pretty much everyone out there is using IE if you are building an application that appeals to the general public.  To this end, Microsoft has made the .Net Developer Studio available for debugging your applications.  The steps are pretty simple:</p>
<ul>
<li>install .Net Studio and create a project</li>
<li>add your javascript files to your project</li>
<li>start IE with your app&#8217;s url</li>
<li>in Visual studio, select debug process and select your iexplorer.exe (sometimes it wont attach, but just keep trying and you should get there eventually)</li>
</ul>
<p>For understanding styling, I suggest downloading the <a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=e59c3964-672d-4511-bb3e-2d5e1db91038&amp;DisplayLang=en">Internet Explorer Developer Toolbar</a>.  This will allow you to inspect individual elements (using the hover) and then setting styling attributes on your elements.  This is much better than changing your html and reloading your page, especially for large applications.</p>
<h3>Firefox (Firebug) Specific debugging</h3>
<p>As with IE, you can use the firefox plugin to step through your code.</p>
<ul>
<li>load your app</li>
<li>open firebug</li>
<li>click script and select the html or javascript file and set your breakpoints</li>
</ul>
<p>As with IE, using the Inspect module in firebug is very useful for styling your application.</p>
<h3>Wrap Up</h3>
<p>In this article we covered a bunch of ways that you can get down to the details in your application</p>
<ul>
<li>alerts (and displaying objects as strings)</li>
<li>logging (appcelerator debug mode, custom log statements, ajax payloads)</li>
<li>in line javascript debugging and styling</li>
</ul>
<p>For many this may be an obvious repeat of the mechanisms that they currently use as web developers, but hopefully it will uncover some of the tactics that are used.</p>
<p>-andrew</p>
<p>this blog is cross posted at:<br />
<a href="http://zuerchtech.com/2008/2/21/debugging-appcelerator-applications">http://zuerchtech.com/2008/2/21/debugging-appcelerator-applications</a></p>
<p><a href="http://sharethis.com/item?&wp=2.8.4&amp;publisher=fb25d17b-38b5-47ed-9857-f171051e9899&amp;title=Debugging+Appcelerator+Applications&amp;url=http%3A%2F%2Fwww.appcelerant.com%2Fdebugging-appcelerator-applications.html">ShareThis</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.appcelerant.com/debugging-appcelerator-applications.html/feed</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Performance Tuning Appcelerator Applications</title>
		<link>http://www.appcelerant.com/performance-tuning-appclerator-applications.html</link>
		<comments>http://www.appcelerant.com/performance-tuning-appclerator-applications.html#comments</comments>
		<pubDate>Wed, 20 Feb 2008 05:25:57 +0000</pubDate>
		<dc:creator>Andrew Zuercher</dc:creator>
				<category><![CDATA[Documentation]]></category>
		<category><![CDATA[Example]]></category>
		<category><![CDATA[Opinion]]></category>

		<guid isPermaLink="false">http://www.appcelerant.com/performance-tuning-appclerator-applications.html</guid>
		<description><![CDATA[Purpose
Once you have developed a functional application and are priming for a roll-out, it will be in your interest to tune your application and identify those touch-points which are candidates for tuning.  I&#8217;ve preferred taking a quantitative approach to performance tuning so that you can compare metrics before and afterwards to identify improvement from [...]<script type="text/javascript">SHARETHIS.addEntry({ title: "Performance Tuning Appcelerator Applications", url: "http://www.appcelerant.com/performance-tuning-appclerator-applications.html" });</script>]]></description>
			<content:encoded><![CDATA[<p></p><h3>Purpose</h3>
<p>Once you have developed a functional application and are priming for a roll-out, it will be in your interest to tune your application and identify those touch-points which are candidates for tuning.  I&#8217;ve preferred taking a quantitative approach to performance tuning so that you can compare metrics before and afterwards to identify improvement from a measurable perspective.  To this end, it is possible to record statistics both client and server side (currently only for java services).  Sometimes the culprit may be server side or client side and determining the area where performance bottlenecks exist is important which is why taking on a triangulation approach is important.</p>
<h3>Client Side</h3>
<p>Currently in the client, you can invoke the Appcelerator.Util.Performance component.  To enable it, simply include logStats=1 in your url, for example: http://localhost:8080/myapp?logStats=1.  The performance component by design will have no impact on your application unless you include this parameter.  By default, the servicebroker will calculate the statistics for handling all message types both local and remote.  The statistics will include the following:</p>
<ul>
<li>last &#8211; the last recorded time</li>
<li>mean</li>
<li>hits &#8211; aka count</li>
<li>min</li>
<li>max</li>
<li>total &#8211; total time overall</li>
</ul>
<p>These statistics will be logged to the console (available in Firefox with Firebug and in Safari with Webkit).</p>
<p><a href="http://www.appcelerant.com/wp-content/uploads/2008/02/picture-15.png" title="logging output"><img src="http://www.appcelerant.com/wp-content/uploads/2008/02/picture-15.png" alt="logging output" /></a></p>
<p>However, you do not need to have logging available to inspect the statistics (please see the section &#8220;Viewing Client Side statistics&#8221; below). In addition the component also allows for resetting all statistics to restart your recording.</p>
<h3>Capturing your own statistics</h3>
<p>If for some reason you want to capture statistics at a finer level, you can easily to this in javascript:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="html4strict">var stat = Appcelerator.Util.Performance.createStat();
//do some work
Appcelerator.Util.Performance.endStat(stat,&quot;mystat&quot;,&quot;mycategory&quot;);</pre></td></tr></table></div>

<p>In this example we create a statistic called &#8220;mystat&#8221; that will be included in a category of &#8220;mycategory&#8221;.  This is useful for filtering through your stats as well as being able to compare statistics side by side.  For example, the service broker will automatically record the following categories:</p>
<ul>
<li>remote</li>
<li>local</li>
</ul>
<h3>Viewing Client Side statistics</h3>
<p>You may want to include the following content file in your application and make it visible when the logStats=1 parameter is included.</p>
<p><a href="http://www.appcelerant.com/wp-content/uploads/2008/02/picture-13.png" title="performance screenshot"><img src="http://www.appcelerant.com/wp-content/uploads/2008/02/picture-13.png" alt="performance screenshot" /></a></p>
<p>Here is the content source itself<br />
<a href="http://www.appcelerant.com/wp-content/uploads/2008/02/clientperformancehtml.txt" title="clientperformance content file">clientperformance.html</a></p>
<h3>Tuning Considerations</h3>
<p>As you develop larger applications, it may be useful to consider the following tips:</p>
<ul>
<li>use lazy=true for app:content files.  this will help to delay long initial load times for your applications</li>
<li>if you do not lazily load your content files, consider postponing app:message invocations until they are needed</li>
<li>consider using CSS selectors in the implementation of your app:iterator rather than re-firing messages for logic</li>
<li>leverage the app:datacache to reduce the number of outgoing messages</li>
<li>make use of pagination if rendering large datasets &#8211; the app:datatable allows for client side pagination for example</li>
</ul>
<h3>Wrap Up</h3>
<p>We covered in this article</p>
<ul>
<li>how you can capture statistics for client side applications</li>
<li>some performance tips in regards to client applications</li>
</ul>
<p>In a later article we will identify how you can take this a step further to capture statistics on the server side as well with java services.This article has been cross posted on</p>
<li><a href="http://zuerchtech.com/2008/2/20/performance-tuning-appcelerator-applications">http://zuerchtech.com/2008/2/20/performance-tuning-appcelerator-applications</a></li>
<p><a href="http://sharethis.com/item?&wp=2.8.4&amp;publisher=fb25d17b-38b5-47ed-9857-f171051e9899&amp;title=Performance+Tuning+Appcelerator+Applications&amp;url=http%3A%2F%2Fwww.appcelerant.com%2Fperformance-tuning-appclerator-applications.html">ShareThis</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.appcelerant.com/performance-tuning-appclerator-applications.html/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>JSON serialization with appcelerator java services</title>
		<link>http://www.appcelerant.com/json-serialization-with-appcelerator-java-services.html</link>
		<comments>http://www.appcelerant.com/json-serialization-with-appcelerator-java-services.html#comments</comments>
		<pubDate>Fri, 08 Feb 2008 06:44:50 +0000</pubDate>
		<dc:creator>Andrew Zuercher</dc:creator>
				<category><![CDATA[Documentation]]></category>
		<category><![CDATA[Example]]></category>
		<category><![CDATA[Opinion]]></category>
		<category><![CDATA[JSON java service appcelerator]]></category>

		<guid isPermaLink="false">http://www.appcelerant.com/json-serialization-with-appcelerator-java-services.html</guid>
		<description><![CDATA[Using Model Objects
The issue of serializing/transforming model objects is not new, heck I&#8217;ve been doing this for quite some time:

rmi (ejb/corba)
xml (jms, soap, etc..)
json

JSON is not the only way to serialize objects for web2.0 applications, but its the most abundant and heavily used throughout our framework.  Doing this is actually really easy to do [...]<script type="text/javascript">SHARETHIS.addEntry({ title: "JSON serialization with appcelerator java services", url: "http://www.appcelerant.com/json-serialization-with-appcelerator-java-services.html" });</script>]]></description>
			<content:encoded><![CDATA[<p></p><h3>Using Model Objects</h3>
<p>The issue of serializing/transforming model objects is not new, heck I&#8217;ve been doing this for quite some time:</p>
<ul>
<li>rmi (ejb/corba)</li>
<li>xml (jms, soap, etc..)</li>
<li>json</li>
</ul>
<p>JSON is not the only way to serialize objects for web2.0 applications, but its the most abundant and heavily used throughout our framework.  Doing this is actually really easy to do with appcelerator IModelObejects.  Our IModelObjects can easily be used along with hibernate for persistance, but lets leave that for later for now.  When you define your Model classes, there are some very simple things to keep in mind:</p>
<ul>
<li>annotate your attributes with @MessageAttr</li>
<li>have your class implement IModelObject</li>
</ul>
<p>Here is a simple example:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
</pre></td><td class="code"><pre class="html4strict">public class User implements IModelObject, Serializable {
  private static final long serialVersionUID = 1L;
&nbsp;
  @MessageAttr
  public String name;
&nbsp;
  public void setUsername(String username) {
    this.username = username;
  }
&nbsp;
 public void setPassword(String password) {
   this.password = password;
  }
&nbsp;
  ...
}</pre></td></tr></table></div>

<h3>Unit test it</h3>
<p>Now to test the rendering of our object to JSON with a simple junit test&#8230;.  As you can see, we leverage the Appcelerator framework to serialize our objects to JSON</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
</pre></td><td class="code"><pre class="html4strict">public class ForumTest extends TestCase { 
&nbsp;
public void testSimple() {
  User user = createUser();
  Message message = new Message();
  JSONMessageDataObject data = new JSONMessageDataObject();
  message.setData(data);
  message.getData().put(&quot;user&quot;, user);
  message.getData().put(&quot;count&quot;, 1);
  String messagestr = data.toDataString();
  assertEquals(messagestr,&quot;\&quot;user\&quot;:{\&quot;password\&quot;:\&quot;pwd\&quot;,\&quot;threads\&quot;:0,\&quot;fullName\&quot;
  :\&quot;antewew\&quot;,\&quot;username\&quot;:\&quot;azuercher\&quot;,\&quot;state\&quot;:\&quot;mystate\&quot;,\&quot;email\&quot;:\&quot;email\&quot;,
  \&quot;posts\&quot;:0,\&quot;id\&quot;:0},\&quot;count\&quot;:1}&quot;);
}
&nbsp;
private User createUser() {
  User user = new User();
  user.setEmail(&quot;email&quot;);
  user.setFullName(&quot;ante wew&quot;);
  user.setId(new Long(0));
  user.setPassword(&quot;pwd&quot;);
  user.setPosts(new Long(0));
  user.setState(&quot;mystate&quot;);
  user.setThreads(new Long(0));
  user.setUsername(&quot;azuercher&quot;);
  return user;
}
&nbsp;
}</pre></td></tr></table></div>

<h3>Dealing with recursion</h3>
<p>Whats always a bit of a tangle is understanding how to deal with the recursive/circular relationship.<br />
If you take a look at JSONObject you will see 2 overridden methods for createBean</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="html4strict">public static JSONObject createBean(IModelObject object,MessageAttr parentAtt, String context,String[] parentSuppres,int level, int maxlevels)
public static JSONObject createBean(IModelObject object)</pre></td></tr></table></div>

<p>The latter is obviously a bit more simple, but the former is where the power is.  In the MessageAttr annotation, you can provide the suppress attribute which is a comma separated list of aggregates (using bean.name notation to not serialize).  This is used for attributes in your IModelObject implementation where the association is with another IModelObject. The following model is for a forum object model where the following aggregate hierarchy exists:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="html4strict">* Forum
** ForumThread
*** Post</pre></td></tr></table></div>

<p>In the snippet below, I&#8217;ve omitted the getter/setter methods for the aggregates for simplicity.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
</pre></td><td class="code"><pre class="html4strict">public class User implements IModelObject, Serializable {
  @MessageAttr (suppress=&quot;user,thread.lastPost&quot;)
  public Post lastPost;
}
&nbsp;
public class Post implements IModelObject, Serializable {
  @MessageAttr(suppress=&quot;lastPost,forum.lastPost&quot;)
  public Forumthread thread;
&nbsp;
  @MessageAttr (suppress=&quot;lastPost&quot;)
  public User user;
}
&nbsp;
public class Forumthread implements IModelObject, Serializable {
  @MessageAttr (suppress=&quot;lastPost&quot;)
  public Forum forum;
&nbsp;
  @MessageAttr (suppress=&quot;thread,user.lastPost&quot;)
  public Post lastPost;
}
&nbsp;
public class Forum implements IModelObject, Serializable {
  @MessageAttr (suppress=&quot;thread.forum,thread.lastPost,user.lastPost&quot;)
  public Post lastPost;
&nbsp;
}</pre></td></tr></table></div>

<h3>Rolling your own serialization</h3>
<p>Assuming you know what your JSON string is going to look like, you can use our RawMessageDataList and RawMessageDataObject to serialze your objects.  This is pretty useful if you already are rendering JSON in an existing framework and don&#8217;t want to have to transform to and back again.  The snippet below shows with static strings just so that you get the idea:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code"><pre class="html4strict">IMessageDataList people = new RawMessageDataList(
&quot;[{'name':'joe','age':22},{'name':'jane','age':33}]&quot;);
&nbsp;
IMessageDataList dog = new RawMessageDataObject(&quot;{'breed':'doberman','weight':78}&quot;);
&nbsp;
Message message = new Message();
message.setData(new JSONMessageDataObject());
message.getData().put(&quot;people&quot;, people);
message.getData().put(&quot;dog&quot;, dog);</pre></td></tr></table></div>

<h3>Using Coarse Grained objects</h3>
<p>This is probably the simplest/prettiest way to implement your services assuming that you aren&#8217;t interested in using fine grained classes that are associated with most of today&#8217;s persistence frameworks.  Here is how you would create a single compound JSON object:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="html4strict">IMessageDataObject dog = MessageUtils.createMessageDataObject();
obj.put(&quot;breed&quot;,&quot;doberman&quot;);
obj.put(&quot;wieght&quot;,78);Message message = new Message();
message.setData(new JSONMessageDataObject());
message.getData().put(&quot;dog&quot;, dog);</pre></td></tr></table></div>

<p>and now with a collection:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
</pre></td><td class="code"><pre class="html4strict">IMessageDataList<span style="color: #ddbb00;">&amp;lt;</span>IMessageDataObject<span style="color: #ddbb00;">&amp;gt;</span> people =
MessageUtils.createMessageDataObjectList();
&nbsp;
IMessageDataObject joe = MessageUtils.createMessageDataObject();
joe.put(&quot;name&quot;,&quot;joe&quot;);
joe.put(&quot;age&quot;,22);
&nbsp;
IMessageDataObject jane = MessageUtils.createMessageDataObject();
joe.put(&quot;name&quot;,&quot;jane&quot;);
joe.put(&quot;age&quot;,33);
&nbsp;
people.put(joe);
people.put(jane);
&nbsp;
Message message = new Message();
message.setData(new JSONMessageDataObject());
message.getData().put(&quot;people&quot;, people);</pre></td></tr></table></div>

<h3>Summary</h3>
<p>As you can see there are quite a bit of alternatives for you based on what your needs are to accommodate your service implementations.  I&#8217;ve personally used all of the above as I&#8217;ve implemented:</p>
<ul>
<li>Model Objects: using hibernate for persistence</li>
<li>Custom Serialization: for integrating with pre-rendered objects (commons-monitoring)</li>
<li>Coarse Grained: in implementing a dashboard/event driven solution</li>
</ul>
<p>cheers and enjoy,</p>
<p>-andrew</p>
<p>cross-posted @ <a href="http://zuerchtech.com/2008/2/8/json-serialization-with-appcelerator-java-services" target="_blank">http://zuerchtech.com/2008/2/8/json-serialization-with-appcelerator-java-services</a></p>
<p><a href="http://sharethis.com/item?&wp=2.8.4&amp;publisher=fb25d17b-38b5-47ed-9857-f171051e9899&amp;title=JSON+serialization+with+appcelerator+java+services&amp;url=http%3A%2F%2Fwww.appcelerant.com%2Fjson-serialization-with-appcelerator-java-services.html">ShareThis</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.appcelerant.com/json-serialization-with-appcelerator-java-services.html/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
