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

<channel>
	<title>Blog de GreenIvory &#187; JavaScript</title>
	<atom:link href="http://blog.greenivory.fr/tag/javascript/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.greenivory.fr</link>
	<description>Développement agile sur technologies web 2.0</description>
	<lastBuildDate>Fri, 03 Feb 2012 11:23:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>GWT et les NullPointerException</title>
		<link>http://blog.greenivory.fr/2009/04/01/gwt-et-les-nullpointerexception/</link>
		<comments>http://blog.greenivory.fr/2009/04/01/gwt-et-les-nullpointerexception/#comments</comments>
		<pubDate>Wed, 01 Apr 2009 16:11:23 +0000</pubDate>
		<dc:creator>Frédéric</dc:creator>
				<category><![CDATA[Développement]]></category>
		<category><![CDATA[exception]]></category>
		<category><![CDATA[GWT]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[null]]></category>

		<guid isPermaLink="false">http://blog.greenivory.fr/?p=221</guid>
		<description><![CDATA[Quelle histoire, ce sabotage de Google ! Un peu de sérieux, en attendant des nouvelles de ce cher Serge-Jean (plus facile à écrire qu&#8217;à dire !). Je me suis fait avoir par quelque chose d&#8217;assez subtil avec GWT. En parsant du XML avec le XMLParser fourni par GWT, j&#8217;ai eu besoin de récupérer la valeur d&#8217;attributs [...]]]></description>
			<content:encoded><![CDATA[<div style="height:33px;" class="really_simple_share robots-nocontent snap_nopreview"><div class="really_simple_share_facebook_like" style="width:100px;">
				<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fblog.greenivory.fr%2F2009%2F04%2F01%2Fgwt-et-les-nullpointerexception%2F&amp;layout=button_count&amp;show_faces=false&amp;width=100&amp;action=like&amp;colorscheme=light&amp;send=false&amp;height=27" 
						scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:100px; height:27px;" allowTransparency="true"></iframe>
				</div><div class="really_simple_share_google1" style="width:90px;">
					<g:plusone size="medium" href="http://blog.greenivory.fr/2009/04/01/gwt-et-les-nullpointerexception/" ></g:plusone>
				</div><div class="really_simple_share_twitter" style="width:110px;">
					<a href="http://twitter.com/share" class="twitter-share-button" data-count="horizontal" 
						data-text="GWT et les NullPointerException" data-url="http://blog.greenivory.fr/2009/04/01/gwt-et-les-nullpointerexception/" 
						data-via="" ></a> 
				</div></div>
		<div style="clear:both;"></div><p>Quelle histoire, ce <a href="http://blog.greenivory.fr/2009/04/01/google-menace/">sabotage de Google</a> ! Un peu de sérieux, en attendant des nouvelles de ce cher Serge-Jean (plus facile à écrire qu&#8217;à dire !).</p>
<p>Je me suis fait avoir par quelque chose d&#8217;assez subtil avec GWT. En parsant du XML avec le <code>XMLParser</code> fourni par GWT, j&#8217;ai eu besoin de récupérer la valeur d&#8217;attributs optionnels. J&#8217;avais donc écrit des blocs de code qui ressemblent à peu près à ceci :</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">NamedNodeMap paramAttrs <span style="color: #339933;">=</span> paramNode.<span style="color: #006633;">getAttributes</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #003399;">String</span> view <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
   view <span style="color: #339933;">=</span> paramAttrs.<span style="color: #006633;">getNamedItem</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;view&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getNodeValue</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">NullPointerException</span> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #009900;">&#125;</span></pre></div></div>

<p>En me disant que si un élément est <code>null</code> dans la chaîne d&#8217;exécution, alors <code>view</code> vaudrait tout simplement <code>null</code>. Ceci est valable en Java, mais une fois traduit en JavaScript par GWT, ça ne marche pas du tout. La solution est donc de tester &laquo;&nbsp;à la main&nbsp;&raquo; les valeurs nulles :</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">NamedNodeMap paramAttrs <span style="color: #339933;">=</span> paramNode.<span style="color: #006633;">getAttributes</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
Node item <span style="color: #339933;">=</span> paramAttrs.<span style="color: #006633;">getNamedItem</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;view&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #003399;">String</span> view <span style="color: #339933;">=</span> item <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span> <span style="color: #339933;">?</span> item.<span style="color: #006633;">getNodeValue</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span></pre></div></div>

<p>Dans cet exemple, je vous l&#8217;accorde, ce n&#8217;est pas plus long et c&#8217;est même plus propre, mais j&#8217;avais un peu plus d&#8217;éléments dans ma ligne, et donc plusieurs valeurs (potentiellement nulles) à tester.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.greenivory.fr/2009/04/01/gwt-et-les-nullpointerexception/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

