<?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>LogikDevelopment &#187; smoreau</title>
	<atom:link href="http://www.logikdev.com/author/smoreau/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.logikdev.com</link>
	<description>&#34;Il n&#039;y a pas de problème, il n&#039;y a que des solutions. L&#039;esprit de l&#039;homme invente ensuite le problème.&#34; André Gide</description>
	<lastBuildDate>Fri, 27 Aug 2010 08:54:27 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Validate file size prior upload</title>
		<link>http://www.logikdev.com/2010/08/26/validate-file-size-prior-upload/</link>
		<comments>http://www.logikdev.com/2010/08/26/validate-file-size-prior-upload/#comments</comments>
		<pubDate>Thu, 26 Aug 2010 20:53:37 +0000</pubDate>
		<dc:creator>smoreau</dc:creator>
				<category><![CDATA[Html]]></category>
		<category><![CDATA[ActiveX]]></category>
		<category><![CDATA[file input]]></category>
		<category><![CDATA[file upload]]></category>
		<category><![CDATA[fileSize function]]></category>
		<category><![CDATA[Internet Explorer]]></category>
		<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://www.logikdev.com/?p=687</guid>
		<description><![CDATA[If I ask you what is the most complex thing in HTML, what would you reply? For me, it would be the file upload (or maybe character encoding, but this is not the topic! ). One of the problem around the file upload functionality is that there is, no matter what, a file size limit [...]]]></description>
			<content:encoded><![CDATA[<p>If I ask you what is the most complex thing in HTML, what would you reply?<br />
For me, it would be the file upload (or maybe character encoding, but this is not the topic! <img src='http://www.logikdev.com/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' />  ).</p>
<p>One of the problem around the file upload functionality is that there is, no matter what, a file size limit set on the server. The limit could be 100Kb such as 100Mb depending on the configuration of the server.<br />
But what happens if the user tries to upload a file bigger than the limit?<br />
It&#8217;s simple, the file is going to be uploaded on the server until the limit is reached. Once it happens, the server returns an error message to the client.<br />
Well, this is not ideal!<br />
Indeed, depending on the connection speed of the user, the error message could be displayed a few minutes later. And you know how impatient users are! <img src='http://www.logikdev.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>So obviously, the solution would be to validate the file size before the upload starts.<br />
To do that, we can simply use the <code>fileSize</code> Javascript function against the upload field.<br />
But, surprising enough, this function doesn&#8217;t work on Internet Explorer! <img src='http://www.logikdev.com/wp-includes/images/smilies/icon_evil.gif' alt=':evil:' class='wp-smiley' /> </p>
<p>And the only solution I found to get the file size with IE was using ActiveX:</p>
<pre class="brush: jscript;">
var oas = new ActiveXObject(&quot;Scripting.FileSystemObject&quot;);
var e = oas.getFile(document.forms[0].file.value);
var size = e.size;
</pre>
<p>Finally, here is the whole Javascript function to validate the file size:</p>
<pre class="brush: jscript;">
function validateFileSize(file, maxSize) {
	if (navigator.appName==&quot;Microsoft Internet Explorer&quot;) {
		if (file.value) {
			var oas = new ActiveXObject(&quot;Scripting.FileSystemObject&quot;);
			var e = oas.getFile(file.value);
			var size = e.size;
		}
	} else {
		if (file.files[0]!=undefined) {
			var size = file.files[0].fileSize;
		}
	}
	if (size!=undefined &amp;&amp; size &gt; maxSize)
		return false;
	return true;
}
</pre>
<p>with <code>file</code> the file input field to validate and <code>maxSize</code> the maximum size in bits.</p>
<p>For example, you can call this function as follow:</p>
<pre class="brush: jscript; light: true;">
validateImageSize(document.forms[0].file, 500000)
</pre>
<p><br/>I successfully tested this code on:</p>
<ul>
<li>Google Chrome 6;</li>
<li>Firefox 3.6;</li>
<li>Internet Explorer 6;</li>
<li>Internet Explorer 7.</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.logikdev.com/2010/08/26/validate-file-size-prior-upload/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Relation between TortoiseSVN and locale</title>
		<link>http://www.logikdev.com/2010/08/15/relation-between-tortoisesvn-and-locale/</link>
		<comments>http://www.logikdev.com/2010/08/15/relation-between-tortoisesvn-and-locale/#comments</comments>
		<pubDate>Sun, 15 Aug 2010 20:23:25 +0000</pubDate>
		<dc:creator>smoreau</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[locale]]></category>
		<category><![CDATA[svn]]></category>
		<category><![CDATA[TortoiseSVN]]></category>

		<guid isPermaLink="false">http://www.logikdev.com/?p=684</guid>
		<description><![CDATA[The other day, I got stuck on a problem with TortoiseSVN for about half a day! Yes, I know, it is a pretty long time to get a simple subversion client working&#8230; The error I was continuously getting was: Network connection closed unexpectedly Nothing else! Nothing in the log files on both the client and [...]]]></description>
			<content:encoded><![CDATA[<p>The other day, I got stuck on a problem with TortoiseSVN for about half a day! <img src='http://www.logikdev.com/wp-includes/images/smilies/icon_eek.gif' alt='8-O' class='wp-smiley' /><br />
Yes, I know, it is a pretty long time to get a simple subversion client working&#8230;</p>
<p>The error I was continuously getting was:</p>
<pre class="brush: plain; light: true;">
Network connection closed unexpectedly
</pre>
<p>Nothing else! Nothing in the log files on both the client and the server. <img src='http://www.logikdev.com/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' /><br />
The funny thing is that it was working perfectly fine using a command line client or even <a href="http://www.eclipse.org/subversive/">Eclipse Subversive</a>.</p>
<p>After a (too) long time of investigation, I noticed that I was getting the following warnings when I was running the following command line directly on the server:</p>
<pre class="brush: bash; light: true;">
$ svn list svn+ssh://smoreau@localhost/data/svn/
svn: warning: cannot set LC_CTYPE locale
svn: warning: environment variable LANG is en_US.UTF-8
svn: warning: please check that your locale name is correct
smoreau@localhost's password:
svnserve: warning: cannot set LC_CTYPE locale
svnserve: warning: environment variable LANG is en_US.UTF-8
svnserve: warning: please check that your locale name is correct
branches/
tags/
trunk/
</pre>
<p>Actually, any <code>svn</code> command was triggering the warning messages:</p>
<pre class="brush: bash; light: true;">
$ svn info
svn: warning: cannot set LC_CTYPE locale
svn: warning: environment variable LANG is en_US.UTF-8
svn: warning: please check that your locale name is correct
</pre>
<p><br/>Could it possibly be related with my TortoiseSVN problem?<br />
Because I didn&#8217;t have any other idea, I decided to give it a go. <img src='http://www.logikdev.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>It appears that these warning messages came from a configuration problem around the locale package on the server. Indeed, look what we get if we run the <code>locale</code> command:</p>
<pre class="brush: bash; light: true;">
$ locale -a
locale: Cannot set LC_CTYPE to default locale: No such file or directory
locale: Cannot set LC_MESSAGES to default locale: No such file or directory
locale: Cannot set LC_COLLATE to default locale: No such file or directory
C
POSIX
</pre>
<p>After some more investigation, it looks like this problem appeared when I upgraded the version of the locale package via <a href="http://en.wikipedia.org/wiki/Advanced_Packaging_Tool">APT</a>. <img src='http://www.logikdev.com/wp-includes/images/smilies/icon_confused.gif' alt=':-?' class='wp-smiley' /> </p>
<p>Once again, I asked my friend Google to help me out. It suggested me the following solutions:</p>
<ul>
<li>Run <code>locale-gen en_US.UTF-8</code> &#8211; <strong>Didn&#8217;t work</strong></li>
<li>Run <code>update-locale LANG=en_US.UTF-8</code> &#8211; <strong>Didn&#8217;t work</strong></li>
<li>Run <code>dpkg-reconfigure locales</code> &#8211; <strong>WORKED</strong> <img src='http://www.logikdev.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </li>
</ul>
<p><br/>In conclusion, I wasn&#8217;t able to use TortoiseSVN because of a configuration problem on the locale package after an upgrade&#8230; Does it make sense? <img src='http://www.logikdev.com/wp-includes/images/smilies/icon_rolleyes.gif' alt=':roll:' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.logikdev.com/2010/08/15/relation-between-tortoisesvn-and-locale/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Use ServerXMLHTTP through a proxy</title>
		<link>http://www.logikdev.com/2010/07/07/use-serverxmlhttp-through-proxy/</link>
		<comments>http://www.logikdev.com/2010/07/07/use-serverxmlhttp-through-proxy/#comments</comments>
		<pubDate>Wed, 07 Jul 2010 19:22:17 +0000</pubDate>
		<dc:creator>smoreau</dc:creator>
				<category><![CDATA[Tricks]]></category>
		<category><![CDATA[VBScript]]></category>
		<category><![CDATA[proxy]]></category>
		<category><![CDATA[proxycfg tool]]></category>
		<category><![CDATA[ServerXMLHTTP]]></category>

		<guid isPermaLink="false">http://www.logikdev.com/?p=647</guid>
		<description><![CDATA[The other day, I was trying to use the ServerXMLHTTP object. For information, this object was created to allow you to establish server-to-server HTTP connections. The code I firstly wrote looked like the following: Dim oXMLHTTP Set oXMLHTTP = Server.CreateObject(&#34;MSXML2.ServerXMLHTTP&#34;) oXMLHTTP.open &#34;POST&#34;, sURL, false oXMLHTTP.setRequestHeader &#34;Content-Type&#34;, &#34;application/x-www-form-urlencoded&#34; oXMLHTTP.send sParams Response.Write oXMLHTTP.responseText with sURL the URL [...]]]></description>
			<content:encoded><![CDATA[<p>The other day, I was trying to use the <strong>ServerXMLHTTP</strong> object. For information, this object was created to allow you to establish server-to-server HTTP connections.</p>
<p>The code I firstly wrote looked like the following:</p>
<pre class="brush: vb;">
Dim oXMLHTTP
Set oXMLHTTP = Server.CreateObject(&quot;MSXML2.ServerXMLHTTP&quot;)
oXMLHTTP.open &quot;POST&quot;, sURL, false
oXMLHTTP.setRequestHeader &quot;Content-Type&quot;, &quot;application/x-www-form-urlencoded&quot;
oXMLHTTP.send sParams
Response.Write oXMLHTTP.responseText
</pre>
<p>with <code>sURL</code> the URL to call and <code>sParams</code> the parameters to send with the URL.</p>
<p>The problem was that <code>oXMLHTTP.responseText</code> didn&#8217;t return anything. Or to be exact, it returned an empty string, which was obviously not the expected response&#8230; <img src='http://www.logikdev.com/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' /> </p>
<p>After some investigation, it appeared that the problem was because the server was seating behind a proxy. All this is good and well, but the question now is how to tell the application to use the proxy?<br />
<br/><br />
First of all, the ServerXMLHTTP object has a <code>setProxy</code> method:<br />
<a href="http://msdn.microsoft.com/en-us/library/ms760236(v=VS.85).aspx">http://msdn.microsoft.com/en-us/library/ms760236(v=VS.85).aspx</a><br />
So I tried to add the following line to the previous code:</p>
<pre class="brush: vb;">
oXMLHTTP.setProxy 2, &quot;myProxyServer:80&quot;, &quot;&quot;
</pre>
<p>Unfortunately, this didn&#8217;t fix the problem. It looks like this line is simply ignored. If somebody knows why, please tell me! <img src='http://www.logikdev.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /><br />
<br/><br />
So the solution I finally adopted was to configure the proxy through the <strong>proxycfg</strong> tool.<br />
There are two ways of using this tool:</p>
<ul>
<li>Import the proxy settings from the current user&#8217;s Microsoft Internet Explorer manual settings using the command <code>proxycfg.exe -u</code></li>
<li>Configure the proxy settings manually using the command <code>proxycfg -p myProxyServer:80</code></li>
</ul>
<p>This last solution works for me and I hope it will help a few people. <img src='http://www.logikdev.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /><br />
<br/><br />
<strong>PS:</strong> I found the following page when writing this article: <a href="http://support.microsoft.com/kb/289481/">http://support.microsoft.com/kb/289481/</a>. It would have been so good to find it during my investigation but anyway.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.logikdev.com/2010/07/07/use-serverxmlhttp-through-proxy/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to configure JSF to get the browser Back button working</title>
		<link>http://www.logikdev.com/2010/06/23/configure-jsf-to-get-the-back-button-working/</link>
		<comments>http://www.logikdev.com/2010/06/23/configure-jsf-to-get-the-back-button-working/#comments</comments>
		<pubDate>Wed, 23 Jun 2010 20:03:56 +0000</pubDate>
		<dc:creator>smoreau</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Back button]]></category>
		<category><![CDATA[JSF]]></category>
		<category><![CDATA[MyFaces]]></category>
		<category><![CDATA[numberOfViewsInSession]]></category>
		<category><![CDATA[RichFaces]]></category>

		<guid isPermaLink="false">http://www.logikdev.com/?p=615</guid>
		<description><![CDATA[Lately, I had a problem with one of my JSF applications which is using RichFaces. The problem was happening when the user was hitting the browser Back button. Well, you would say that it is a usual problem in web development. But still, because we cannot disable the browser Back button, the web application needs [...]]]></description>
			<content:encoded><![CDATA[<p>Lately, I had a problem with one of my JSF applications which is using RichFaces.<br />
The problem was happening when the user was hitting the browser Back button. Well, you would say that it is a usual problem in web development. But still, because we cannot disable the browser Back button, the web application needs to work fine if the user decides to click on it!</p>
<p>Anyway, let&#8217;s get back on topic. As I said, the problem occurred if the user was clicking on the Back button but the funniest thing is it was happening when he was clicking twice on it! Why did it work fine when clicking once but not twice? <img src='http://www.logikdev.com/wp-includes/images/smilies/icon_surprised.gif' alt=':o' class='wp-smiley' /> </p>
<p>The solution is quite simple actually.<br />
It was coming from one of the options in MyFaces configuration: <code>com.sun.faces.numberOfViewsInSession</code>.<br />
Here is a quick explanation of this option:</p>
<blockquote><p>
<strong>com.sun.faces.numberOfViewsInSession</strong><br />
Specifies the number of views that are stored in the session when Server-Side State Saving is used. If set to true while client-side state saving is being used, reduces the number of bytes sent to the client by compressing the state before it is encoded and written as a hidden field. The default for this parameter is 15.
</p></blockquote>
<p>So basically, JSF is storing each page previously viewed by the user in session. And, as you can see from the description above, JSF will stored a maximum of <strong>15</strong> pages by default. However, it was set to <strong>1</strong> in my application, which means only ONE page would be stored&#8230;<br />
This was obviously the reason why the application was working fine if the user was clicking only once on the Back button but not twice! <img src='http://www.logikdev.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>
<p>For the same reason, you should also check the option <code>org.apache.myfaces.NUMBER_OF_VIEWS_IN_SESSION</code> which is default to 20:</p>
<blockquote><p>
<strong>org.apache.myfaces.NUMBER_OF_VIEWS_IN_SESSION</strong><br />
Defines the number of the latest views that are stored in session. This option is only applicable if the state saving method is set to server. The default for this parameter is 20.
</p></blockquote>
<p>For more information about JSF options, please have a look at the following page:<br />
<a href="http://publib.boulder.ibm.com/infocenter/wasinfo/v7r0/index.jsp?topic=/com.ibm.websphere.express.doc/info/exp/ae/rweb_jsfengine.html">http://publib.boulder.ibm.com/infocenter/wasinfo/v7r0/index.jsp?topic=/com.ibm.websphere.express.doc/info/exp/ae/rweb_jsfengine.html</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.logikdev.com/2010/06/23/configure-jsf-to-get-the-back-button-working/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Image manipulation in VBScript</title>
		<link>http://www.logikdev.com/2010/06/09/image-manipulation-in-vbscript/</link>
		<comments>http://www.logikdev.com/2010/06/09/image-manipulation-in-vbscript/#comments</comments>
		<pubDate>Wed, 09 Jun 2010 21:35:57 +0000</pubDate>
		<dc:creator>smoreau</dc:creator>
				<category><![CDATA[VBScript]]></category>
		<category><![CDATA[ImageMagick]]></category>
		<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://www.logikdev.com/?p=572</guid>
		<description><![CDATA[I am back on Windows development. It is not what I prefer but still, it is development so I am right here! My task was to upload an image from a website (nothing difficult there) but the application has to resize and crop the uploaded image before saving it on the hard drive in order [...]]]></description>
			<content:encoded><![CDATA[<p>I am back on Windows development. It is not what I prefer but still, it is development so I am right here! <img src='http://www.logikdev.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>My task was to upload an image from a website (nothing difficult there) but the application has to resize and crop the uploaded image before saving it on the hard drive in order to save space.<br />
Oh, and I forgot to mention that the website is built in VBScript (it would have been too easy if it has been built in ASP.Net&#8230;). <img src='http://www.logikdev.com/wp-includes/images/smilies/icon_rolleyes.gif' alt=':roll:' class='wp-smiley' /> </p>
<p>I went across a lot of image management libraries which work with VBScript during my search:</p>
<ul>
<li><strong>AspImage</strong> from <a href="http://serverobjects.com/">ServerObjects Inc</a>;</li>
<li><strong>ImageGlue</strong> from <a href="http://www.websupergoo.com/">webSupergoo</a>;</li>
<li><strong>Active Image Processing Component</strong> from <a href="http://www.ultrashareware.com/">Ultra Shareware</a>.</li>
</ul>
<p>But I must admit that the most difficult part of this task was to find a good and FREE library.<br />
The one I finally picked is <a href="http://www.imagemagick.org/"><strong>ImageMagick</strong></a>.</p>
<p>Once the library is installed (click <a href="http://www.imagemagick.org/script/binary-releases.php#windows">here</a> to go to the download page), you can use the following code to resize the image to a maximum of 800 pixels and crop the white space around it:</p>
<pre class="brush: vb;">
Dim imageMagick
Set imageMagick = CreateObject(&quot;ImageMagickObject.MagickImage.1&quot;)

imageMagick.Convert &quot;C:/testimage.jpg&quot;, &quot;-fuzz&quot;, &quot;10%&quot;, &quot;-trim&quot;, &quot;-resize&quot;, &quot;800x800&gt;&quot;, &quot;C:/thumb-testimage.jpg&quot;
</pre>
<p>Obviously, this tool can do much more than that, but this will be subject of another topic.<br />
Or you can simply read the documentation: <a href="http://www.imagemagick.org/Usage/">http://www.imagemagick.org/Usage/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.logikdev.com/2010/06/09/image-manipulation-in-vbscript/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using the &#8216;date&#8217; command in your crontab</title>
		<link>http://www.logikdev.com/2010/05/25/using-the-date-command-in-your-crontab/</link>
		<comments>http://www.logikdev.com/2010/05/25/using-the-date-command-in-your-crontab/#comments</comments>
		<pubDate>Tue, 25 May 2010 18:15:42 +0000</pubDate>
		<dc:creator>smoreau</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[cron]]></category>
		<category><![CDATA[date command]]></category>
		<category><![CDATA[shell]]></category>

		<guid isPermaLink="false">http://www.logikdev.com/?p=550</guid>
		<description><![CDATA[Crontab, as most people know, enables users to schedule commands or shell scripts to run periodically at certain times or dates. The other day, this very useful Linux tool gave me a hard time! Indeed, one of my commands wasn&#8217;t working in cron but was working perfectly fine when written in a shell console. The [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Crontab</strong>, as most people know, enables users to schedule commands or shell scripts to run periodically at certain times or dates.</p>
<p>The other day, this very useful Linux tool gave me a hard time! <img src='http://www.logikdev.com/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' /><br />
Indeed, one of my commands wasn&#8217;t working in cron but was working perfectly fine when written in a shell console.</p>
<p>The faulty command looked like this:</p>
<pre class="brush: bash; light: true;">
0 5 * * 3 /data/script.sh &gt; /data/script_`date +%y%m%d`.log 2&gt;&amp;1
</pre>
<p>If I run this command in a shell console, everything works fine and I get a log file containing today&#8217;s date in its filename. However, if I set this command line in my crontab, it doesn&#8217;t work and no log file is even created!</p>
<p>Reading the documentation of cron, I discovered the following statement:</p>
<blockquote><p>Percent-signs (%) in the command, unless escaped with backslash (\), will be changed into newline characters, and all data after the first % will be sent to the command as standard input.</p></blockquote>
<p>Well, this is good to know, isn&#8217;t it? <img src='http://www.logikdev.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /><br />
We need to escape the percent-signs on our command line.</p>
<p>So in order to get our &#8216;faulty&#8217; command to run in cron, it needs to look like the following:</p>
<pre class="brush: bash; light: true;">
0 5 * * 3 /data/script.sh &gt; /data/script_`date +\%y\%m\%d`.log 2&gt;&amp;1
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.logikdev.com/2010/05/25/using-the-date-command-in-your-crontab/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Validate your EAN barcode</title>
		<link>http://www.logikdev.com/2010/05/13/validate-your-ean-barcode/</link>
		<comments>http://www.logikdev.com/2010/05/13/validate-your-ean-barcode/#comments</comments>
		<pubDate>Thu, 13 May 2010 21:04:33 +0000</pubDate>
		<dc:creator>smoreau</dc:creator>
				<category><![CDATA[Html]]></category>
		<category><![CDATA[EAN barcode]]></category>
		<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://www.logikdev.com/?p=520</guid>
		<description><![CDATA[On one of the applications I am working on, I had to validate an EAN (European Article Number) barcode. This application is mostly using JavaScript validation so I asked my friend Google to find me a JavaScript method which would check my EAN barcode. It found validators in different languages but none in JavaScript. Because [...]]]></description>
			<content:encoded><![CDATA[<p>On one of the applications I am working on, I had to validate an EAN (<a target="_blank" href="http://en.wikipedia.org/wiki/European_Article_Number">European Article Number</a>) barcode.<br />
This application is mostly using JavaScript validation so I asked my friend Google to find me a JavaScript method which would check my EAN barcode.<br />
It found validators in different languages but none in JavaScript. <img src='http://www.logikdev.com/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' /> </p>
<p>Because one is never better served than by oneself, I decided to write it myself and share it with you. <img src='http://www.logikdev.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<pre class="brush: jscript;">
function checkEan(eanCode) {
	// Check if only digits
	var ValidChars = &quot;0123456789&quot;;
	for (i = 0; i &lt; eanCode.length; i++) {
		digit = eanCode.charAt(i);
		if (ValidChars.indexOf(digit) == -1) {
			return false;
		}
	}

	// Add five 0 if the code has only 8 digits
	if (eanCode.length == 8 ) {
		eanCode = &quot;00000&quot; + eanCode;
	}
	// Check for 13 digits otherwise
	else if (eanCode.length != 13) {
		return false;
	}

	// Get the check number
	originalCheck = eanCode.substring(eanCode.length - 1);
	eanCode = eanCode.substring(0, eanCode.length - 1);

	// Add even numbers together
	even = Number(eanCode.charAt(1)) +
	       Number(eanCode.charAt(3)) +
	       Number(eanCode.charAt(5)) +
	       Number(eanCode.charAt(7)) +
	       Number(eanCode.charAt(9)) +
	       Number(eanCode.charAt(11));
	// Multiply this result by 3
	even *= 3;

	// Add odd numbers together
	odd = Number(eanCode.charAt(0)) +
	      Number(eanCode.charAt(2)) +
	      Number(eanCode.charAt(4)) +
	      Number(eanCode.charAt(6)) +
	      Number(eanCode.charAt(8)) +
	      Number(eanCode.charAt(10));

	// Add two totals together
	total = even + odd;

	// Calculate the checksum
    // Divide total by 10 and store the remainder
    checksum = total % 10;
    // If result is not 0 then take away 10
    if (checksum != 0) {
        checksum = 10 - checksum;
    }

	// Return the result
	if (checksum != originalCheck) {
		return false;
	}

    return true;
}
</pre>
<p>Note that this code can validate EAN-8 and EAN-13 barcodes.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.logikdev.com/2010/05/13/validate-your-ean-barcode/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The message tags of MyFaces and RichFaces</title>
		<link>http://www.logikdev.com/2010/05/06/message-tags-of-myfaces-and-richfaces/</link>
		<comments>http://www.logikdev.com/2010/05/06/message-tags-of-myfaces-and-richfaces/#comments</comments>
		<pubDate>Thu, 06 May 2010 19:25:37 +0000</pubDate>
		<dc:creator>smoreau</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Ajax]]></category>
		<category><![CDATA[FacesMessage]]></category>
		<category><![CDATA[Html]]></category>
		<category><![CDATA[JSF]]></category>
		<category><![CDATA[message tag]]></category>
		<category><![CDATA[MyFaces]]></category>
		<category><![CDATA[RichFaces]]></category>

		<guid isPermaLink="false">http://www.logikdev.com/?p=472</guid>
		<description><![CDATA[Working on an application using MyFaces and RichFaces, I had no choice but understand what is the difference between the message tag provided by Myfaces (h:message) and the message tag overridden by RichFaces (rich:message). These tags allow to display information about the first FacesMessage that is assigned to the component referenced by the &#8220;for&#8221; attribute. [...]]]></description>
			<content:encoded><![CDATA[<p>Working on an application using MyFaces and RichFaces, I had no choice but understand what is the difference between the message tag provided by Myfaces (<code>h:message</code>) and the message tag overridden by RichFaces (<code>rich:message</code>).</p>
<p>These tags allow to display information about the first FacesMessage that is assigned to the component referenced by the &#8220;for&#8221; attribute. The difference is that the RichFaces tag has some extra functionalities such as Ajax rendering, error markers and predefined css class names.<br />
Have a look at the following page for more details: <a target="_blank" href="http://livedemo.exadel.com/richfaces-demo/richfaces/message.jsf">http://livedemo.exadel.com/richfaces-demo/richfaces/message.jsf</a></p>
<p>This is all nice and well but it is not the only difference. Indeed, the HTML code generated by both these frameworks will also be different!</p>
<p>First of all, let&#8217;s see how the tag <code>&lt;h:message styleClass="errormsg" for="element"/&gt;</code> will be transformed. If there is no message to display, nothing will be generated (which is a good behaviour). However, if a message is present, the tag will be replaced by the following HTML code:</p>
<pre class="brush: xml;">
&lt;span class=&quot;errormsg&quot;&gt;Required.&lt;/span&gt;
</pre>
<p>So far, so good!</p>
<p>But now let&#8217;s check what code RichFaces is generating for the tag <code>&lt;rich:message styleClass="errormsg" for="element"/&gt;</code>.<br />
The following is the code created if there is NO message to render:</p>
<pre class="brush: xml;">
&lt;span class=&quot;rich-message errormsg&quot; id=&quot;form:j_id255&quot;&gt;
    &lt;span class=&quot;rich-message-label&quot;&gt;&lt;/span&gt;
&lt;/span&gt;
</pre>
<p>And here is the code which will replace the RichFaces tag if there is a message to display:</p>
<pre class="brush: xml;">
&lt;span id=&quot;bookingform:j_id255&quot; class=&quot;rich-message errormsg&quot;&gt;
    &lt;span class=&quot;rich-message-label&quot;&gt;Required.&lt;/span&gt;
&lt;/span&gt;
</pre>
<p>As you can see, the main difference is that RichFaces is wrapping the original <code>span</code> tag into another <code>span</code> tag. But, it is also generating some code even if there is no message to display! You would ask why is it doing that? The response is simple. The wrapper span element is necessary for RichFaces to Ajax-render the message tag if an error message has to be displayed for the targeting element.</p>
<p>So make sure you don&#8217;t put any padding or margin style in your custom CSS class which I called &#8216;errormsg&#8217; in my example. Otherwise, you might have a gap when you were expecting nothing&#8230; (this happened to me) <img src='http://www.logikdev.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.logikdev.com/2010/05/06/message-tags-of-myfaces-and-richfaces/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to personalise the URLs with Faces Navigation?</title>
		<link>http://www.logikdev.com/2010/03/24/how-to-personalise-the-urls-with-faces-navigation/</link>
		<comments>http://www.logikdev.com/2010/03/24/how-to-personalise-the-urls-with-faces-navigation/#comments</comments>
		<pubDate>Wed, 24 Mar 2010 20:01:29 +0000</pubDate>
		<dc:creator>smoreau</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[EL expressions]]></category>
		<category><![CDATA[Faces Navigation]]></category>
		<category><![CDATA[JSF]]></category>
		<category><![CDATA[SEO]]></category>
		<category><![CDATA[view handler]]></category>

		<guid isPermaLink="false">http://www.logikdev.com/?p=418</guid>
		<description><![CDATA[This is an important question if you want to have search engine friendly URLs on your website! But unfortunately, the solution is not straightforward with JavaServer Faces (JSF). First of all, for security reason JSF doesn&#8217;t allow you to use the GET method for your forms. I didn&#8217;t really understand why but this is very [...]]]></description>
			<content:encoded><![CDATA[<p>This is an important question if you want to have search engine friendly URLs on your website!<br />
But unfortunately, the solution is not straightforward with JavaServer Faces (JSF). <img src='http://www.logikdev.com/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' /> </p>
<p>First of all, for security reason JSF doesn&#8217;t allow you to use the GET method for your forms. I didn&#8217;t really understand why but this is very (too) restrictive!<br />
Can you imagine Google doing the same thing? We would have the same URL for every search terms <code>http://www.google.co.uk/search</code> instead of something like <code>http://www.google.co.uk/search?hl=en&amp;safe=off&amp;esrch=FT1&amp;q=test&amp;meta=&amp;aq=f&amp;aqi=g10&amp;aql=&amp;oq=&amp;gs_rfai=</code>.<br />
It wouldn&#8217;t be very easy to share a search page with a friend if Google was using the POST method. <img src='http://www.logikdev.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>So the question is how to get around this JSF limitation?</p>
<p>Let&#8217;s take a look at how would look our <code>faces-navigation.xml</code> file for a search page:</p>
<pre class="brush: xml;">
&lt;navigation-case&gt;
    &lt;from-action&gt;#{searchBean.searchAction}&lt;/from-action&gt;
    &lt;from-outcome&gt;success&lt;/from-outcome&gt;
    &lt;to-view-id&gt;/search.xhtml&lt;/to-view-id&gt;
    &lt;redirect /&gt;
&lt;/navigation-case&gt;
</pre>
<p>In this example, all the JSF elements calling the action <code>searchBean.searchAction</code> will be redirected to the <code>search.xhtml</code> page.<br />
But, how are we going to get the search parameters into the URL?</p>
<p>Ideally, it would be great to be able to do something like the following:</p>
<pre class="brush: xml;">
&lt;navigation-case&gt;
    &lt;from-action&gt;#{searchBean.searchAction}&lt;/from-action&gt;
    &lt;from-outcome&gt;success&lt;/from-outcome&gt;
    &lt;to-view-id&gt;/search.xhtml?q=#{param.q}&lt;/to-view-id&gt;
    &lt;redirect /&gt;
&lt;/navigation-case&gt;
</pre>
<p>This solution would allow us to inject EL expressions into the URL before the page is redirected to the destination page.<br />
In order to do this, we need to create our own view handler and register it to our application.  <img src='http://www.logikdev.com/wp-includes/images/smilies/icon_cool.gif' alt='8-)' class='wp-smiley' /> </p>
<p>The code below is the view handler class which also includes some comments:</p>
<pre class="brush: java;">
package com.logikdev.gui.handler;

import javax.el.ExpressionFactory;
import javax.el.ValueExpression;
import javax.faces.application.ViewHandler;
import javax.faces.context.FacesContext;

import com.sun.facelets.FaceletViewHandler;

/**
 * Overrides the Facelet view handler to support EL expressions in URLs.
 * @author Stéphane Moreau
 */
public class DynamicViewHandler extends FaceletViewHandler {

	public DynamicViewHandler(ViewHandler parent) {
		super(parent);
	}

	/* (non-Javadoc)
	 * @see com.sun.facelets.FaceletViewHandler#getActionURL(javax.faces.context.FacesContext, java.lang.String)
	 */
	@Override
	public String getActionURL(FacesContext context, String viewId) {
		String queryString = null;

		// Separate the query string from the URL
		int dotIndex = viewId.lastIndexOf('.');
		int questionMarkIndex = viewId.indexOf('?');
		if (questionMarkIndex != -1) {
			queryString = viewId.substring(questionMarkIndex, dotIndex);
			viewId = viewId.substring(0, questionMarkIndex) + viewId.substring(dotIndex);
		}

		// Call the parent without the query string
		String result = super.getActionURL(context, viewId);

		// Replace the EL expressions in the URL
		ExpressionFactory expressionFactory = context.getApplication().getExpressionFactory();
		ValueExpression valueExpression = expressionFactory.createValueExpression(context.getELContext(), result, String.class);
		result = (String) valueExpression.getValue(context.getELContext());

		// Replace the EL expressions in the query string
		if (queryString != null) {
			valueExpression = expressionFactory.createValueExpression(context.getELContext(), queryString, String.class);
			queryString = (String) valueExpression.getValue(context.getELContext());

	        result += queryString;
		}

	    return result;
	}

}
</pre>
<p>And the following is the code to put in the <code>faces-config.xml</code> file in order to register the newly created view handler to the application:</p>
<pre class="brush: xml;">
&lt;application&gt;
	&lt;variable-resolver&gt;org.springframework.web.jsf.DelegatingVariableResolver&lt;/variable-resolver&gt;
	&lt;view-handler&gt;com.logikdev.gui.handler.DynamicViewHandler&lt;/view-handler&gt;
&lt;/application&gt;
</pre>
<p><strong>One last thing!</strong><br />
This view handler also has a limitation which I wasn&#8217;t able to fix. <img src='http://www.logikdev.com/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' />  The file extension has to ALWAYS be placed at the end of the <code>to-view-id</code> URL! The view handler will then put it back before the question mark.<br />
For example:</p>
<pre class="brush: xml;">
&lt;navigation-case&gt;
	&lt;from-action&gt;#{searchBean.searchAction}&lt;/from-action&gt;
	&lt;from-outcome&gt;success&lt;/from-outcome&gt;
	&lt;!-- The extension has to be at the end --&gt;
	&lt;to-view-id&gt;/search?q=#{param.q}.xhtml&lt;/to-view-id&gt;
	&lt;redirect /&gt;
&lt;/navigation-case&gt;
</pre>
<p>If you perform a search on &#8216;jsf&#8217; with the above navigation rule, the user will be redirected to the page <code>/search.xhtml?q=jsf</code>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.logikdev.com/2010/03/24/how-to-personalise-the-urls-with-faces-navigation/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>limitToList attribute prevents flashing</title>
		<link>http://www.logikdev.com/2010/03/02/limittolist-attribute-prevents-flashing/</link>
		<comments>http://www.logikdev.com/2010/03/02/limittolist-attribute-prevents-flashing/#comments</comments>
		<pubDate>Tue, 02 Mar 2010 18:56:36 +0000</pubDate>
		<dc:creator>smoreau</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Tricks]]></category>
		<category><![CDATA[Ajax]]></category>
		<category><![CDATA[flash/twinkle]]></category>
		<category><![CDATA[limitToList]]></category>
		<category><![CDATA[RichFaces]]></category>

		<guid isPermaLink="false">http://www.logikdev.com/?p=395</guid>
		<description><![CDATA[If you have some elements (or even the whole page) that flash/twinkle using RichFaces, it probably means that these elements are AJAX-rendering. The question is by whom and how to fix it? A lot of tags in RichFaces can AJAX-render elements such as: &#60;a4j:form&#62; &#60;a4j:jsFunction name=&#34;updateName&#34; reRender=&#34;showname&#34;&#62; &#60;a4j:actionparam name=&#34;param1&#34; assignTo=&#34;#{userBean.name}&#34; /&#62; &#60;/a4j:jsFunction&#62; &#60;/a4j:form&#62; On the above [...]]]></description>
			<content:encoded><![CDATA[<p>If you have some elements (or even the whole page) that flash/twinkle using RichFaces, it probably means that these elements are AJAX-rendering. The question is by whom and how to fix it?</p>
<p>A lot of tags in RichFaces can AJAX-render elements such as:</p>
<pre class="brush: xml;">
&lt;a4j:form&gt;
    &lt;a4j:jsFunction name=&quot;updateName&quot; reRender=&quot;showname&quot;&gt;
        &lt;a4j:actionparam name=&quot;param1&quot; assignTo=&quot;#{userBean.name}&quot;  /&gt;
    &lt;/a4j:jsFunction&gt;
&lt;/a4j:form&gt;
</pre>
<p>On the above example, the JavaScript function <code>updateName</code> will AJAX-render the element which has the ID <code>showname</code>.</p>
<p>In some cases, you would have some elements that would AJAX-render without asking them to do so!<br />
I still didn&#8217;t figure it out why. <img src='http://www.logikdev.com/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' />  (if anybody has an idea, please don&#8217;t hesitate to tell me!)</p>
<p>But, I found a way to prevent this!<br />
You simply can add the following attribute to your tag:</p>
<pre class="brush: xml; light: true;">limitToList=&quot;true&quot;</pre>
<p>You even can add it to the tags that don&#8217;t have a <code>reRender</code> attribute.<br />
For example:</p>
<pre class="brush: xml;">
&lt;a4j:form&gt;
    &lt;a4j:poll id=&quot;poll&quot; interval=&quot;1000&quot; limitToList=&quot;true&quot; /&gt;
&lt;/a4j:form&gt;
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.logikdev.com/2010/03/02/limittolist-attribute-prevents-flashing/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
