<?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>Web 3.0, 6 Bladed Razors, 7 Minute Abs &#187; JSF</title>
	<atom:link href="http://www.zachleat.com/web/tag/jsf/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.zachleat.com/web</link>
	<description></description>
	<lastBuildDate>Fri, 30 Jul 2010 20:02:38 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
		<item>
		<title>JavaScript Frameworks and JSF</title>
		<link>http://www.zachleat.com/web/2007/07/10/javascript-frameworks-and-jsf/</link>
		<comments>http://www.zachleat.com/web/2007/07/10/javascript-frameworks-and-jsf/#comments</comments>
		<pubDate>Wed, 11 Jul 2007 02:24:05 +0000</pubDate>
		<dc:creator>Zach Leatherman</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Dojo]]></category>
		<category><![CDATA[ExtJS]]></category>
		<category><![CDATA[Facelets]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[JSF]]></category>
		<category><![CDATA[Mootools]]></category>
		<category><![CDATA[Prototype]]></category>

		<guid isPermaLink="false">http://www.zachleat.com/web/2007/07/10/javascript-frameworks-and-jsf/</guid>
		<description><![CDATA[You&#8217;re programming a new web application using JSF, maybe with Facelets, maybe without. Which client-side JavaScript framework is going to work with it&#8217;s unstandardized method of assigning ID attributes to it&#8217;s elements? Here is an example of a JSF file: &#60;%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %&#62; &#60;%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %&#62; &#60;html&#62; &#60;body&#62; &#60;f:view&#62; &#60;h:form id="myForm"&#62; [...]]]></description>
			<content:encoded><![CDATA[<p>You&#8217;re programming a new web application using JSF, maybe with Facelets, maybe without.  Which client-side JavaScript framework is going to work with it&#8217;s unstandardized method of assigning ID attributes to it&#8217;s elements?  Here is an example of a JSF file:<br />
<code><br />
&lt;%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %&gt;<br />
&lt;%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %&gt;<br />
&lt;html&gt;<br />
 &lt;body&gt;<br />
   &lt;f:view&gt;<br />
     &lt;h:form id="myForm"&gt;<br />
      &lt;h:inputText id="myText"/&gt;<br />
     &lt;/h:form&gt;<br />
   &lt;/f:view&gt;<br />
 &lt;/body&gt;<br />
&lt;/html&gt;<br />
</code></p>
<p>or maybe the same thing using Facelets:<br />
<code><br />
&lt;html xmlns="http://www.w3.org/1999/xhtml"<br />
      xmlns:h="http://java.sun.com/jsf/html"<br />
      xmlns:f="http://java.sun.com/jsf/core"&gt;<br />
 &lt;body&gt;<br />
   &lt;f:view&gt;<br />
     &lt;form jsfc="h:form" id="myForm"&gt;<br />
      &lt;input type="text" jsfc="h:inputText" id="myText"/&gt;<br />
     &lt;/form&gt;<br />
   &lt;/f:view&gt;<br />
 &lt;/body&gt;<br />
&lt;/html&gt;<br />
</code></p>
<p>These will both output the following result:<br />
<code><br />
&lt;html xmlns="http://www.w3.org/1999/xhtml"<br />
      xmlns:ui="http://java.sun.com/jsf/facelets"&gt;<br />
 &lt;body&gt;<br />
     &lt;form id="myForm"&gt;<br />
      &lt;input type="text" id="myForm:myText"/&gt;<br />
     &lt;/form&gt;<br />
 &lt;/body&gt;<br />
&lt;/html&gt;<br />
</code></p>
<p>Notice how the resulting text field has an ID attribute with the parent id prepended on.  Now the real question is, how do we select this result node using the various JavaScript frameworks that are available to us?</p>
<h1>Works, but we don&#8217;t care: Raw JavaScript or any GetById Function</h1>
<p>Obviously using <code>document.getElementById( 'myForm:myText' );</code> will function correctly.  As will any framework that has a similar &#8220;GetById&#8221; function (YAHOO.util.Dom.get, or $ in Prototype, etc)  What is more interesting to us is the behavior using the various CSS selector packages included with each JavaScript library.</p>
<h1>Does not work: <a href="http://extjs.com/deploy/ext/docs/output/Ext.DomQuery.html">DomQuery</a> in Ext 1.1 Beta 2</h1>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">Ext.<span style="color: #660066;">query</span><span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">'#myForm:myText'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
Ext.<span style="color: #660066;">query</span><span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">'#myForm<span style="color: #000099; font-weight: bold;">\:</span>myText'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>These two tests will throw the error <code>Ext.DomQuery.pseudos[name] is not a function</code>, which obviously means that myText is not a pseudo class like :first or :last.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">Ext.<span style="color: #660066;">query</span><span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">'#myForm<span style="color: #000099; font-weight: bold;">\\</span>:myText'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Throws the error: <code>Error parsing selector, parsing failed at "\:myText"</code></p>
<h1>Works: <a href="http://docs.jquery.com/DOM/Traversing/Selectors">jQuery</a> 1.1.3</h1>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">jQuery<span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">'#myForm<span style="color: #000099; font-weight: bold;">\\</span>:myText'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>As of version 1.1.3 (the latest of this writing), they have added support for the colon in ID selection when escaped with a double backslash.  Versions older than 1.1.3 will not function properly.  This is not yet in the documentation but can be viewed in the <a href="http://jquery.com/blog/2007/07/01/jquery-113-800-faster-still-20kb/">Escape selectors section of a blog post</a>.</p>
<h1>Does not Work: <a href="http://www.prototypejs.org/api/utility/dollar-dollar">Prototype</a> 1.5.1.1</h1>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$$<span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">'#myForm:myText'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
$$<span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">'#myForm<span style="color: #000099; font-weight: bold;">\:</span>myText'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Returns the form instead of the input element and treats myText as a pseudo class.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$$<span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">'#myForm<span style="color: #000099; font-weight: bold;">\\</span>:myText'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Interprets as XPATH selectors (\\ means anywhere in the document), using myText as a pseudo selector now, so it returns ALL nodes in the document.</p>
<h1>Does not Work: <a href="http://dojotoolkit.org/node/336">Dojo query</a> 0.9.0 Beta</h1>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">dojo.<span style="color: #660066;">query</span><span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">'#myForm:myText'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
dojo.<span style="color: #660066;">query</span><span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">'#myForm<span style="color: #000099; font-weight: bold;">\:</span>myText'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
dojo.<span style="color: #660066;">query</span><span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">'#myForm<span style="color: #000099; font-weight: bold;">\\</span>:myText'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>It&#8217;s becoming mind numbingly obvious that if the framework doesn&#8217;t specifically say that you can escape selectors, it&#8217;s not going to let you do so.  In the first two tests, Dojo performs the same as Prototype.  In the double backslash test however, Dojo returns no result nodes.</p>
<h1>Does not Work: <a href="http://docs.mootools.net/Element/Element-Selectors.js">Mootools</a> 1.11</h1>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$$<span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">'#myForm:myText'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
$$<span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">'#myForm<span style="color: #000099; font-weight: bold;">\:</span>myText'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
$$<span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">'#myForm<span style="color: #000099; font-weight: bold;">\\</span>:myText'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>All throw the error <code>The expression is not a legal expression." code: "51</code>.</p>
<p>There you have it folks.  jQuery is the JavaScript library of choice for the discerning JSF applications developer.  Kudos to you if you&#8217;re already using it.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.zachleat.com/web/2007/07/10/javascript-frameworks-and-jsf/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
	</channel>
</rss>
