<?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>hugomonteiro.net &#187; Software Development</title>
	<atom:link href="http://hugomonteiro.net/category/software-development/feed/" rel="self" type="application/rss+xml" />
	<link>http://hugomonteiro.net</link>
	<description>&#34;When two men in business always agree, one of them is unnecessary.&#34; - William Wrigley Jr.</description>
	<lastBuildDate>Wed, 14 Dec 2011 00:12:42 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
		<item>
		<title>Client Certificates and Play!</title>
		<link>http://hugomonteiro.net/2011/09/30/client-certificates-and-play/</link>
		<comments>http://hugomonteiro.net/2011/09/30/client-certificates-and-play/#comments</comments>
		<pubDate>Thu, 29 Sep 2011 23:09:20 +0000</pubDate>
		<dc:creator>Hugo Monteiro</dc:creator>
				<category><![CDATA[Internet]]></category>
		<category><![CDATA[play]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[certificates]]></category>
		<category><![CDATA[keytool]]></category>
		<category><![CDATA[openssl]]></category>
		<category><![CDATA[rsa]]></category>
		<category><![CDATA[security]]></category>

		<guid isPermaLink="false">http://hugomonteiro.net/?p=409</guid>
		<description><![CDATA[Sometimes we need the authentication of the client. That means, for instance, if you want to limit the access to your web application, from the people who has the right certificate. This is possible, using client certificates, which are installed inside the browser, and the user without this certificate cannot access the web application. To [...]]]></description>
			<content:encoded><![CDATA[<p>Sometimes we need the authentication of the client. That means, for instance, if you want to limit the access to your web application, from the people who has the right certificate.<br />
This is possible, using client certificates, which are installed inside the browser, and the user without this certificate cannot access the web application.</p>
<p>To create client certificates, you need to check if you have <em><a title="openssl" href="http://www.openssl.org/">openssl</a></em> installed. After this verification, you need to find where the auxiliary command CA and/or CA.pl is installed. On my Mac  it&#8217;s located in &#8220;<em>/System/Library/OpenSSL/misc/CA.pl</em>&#8220;.</p>
<p><strong>1. First, we need to create a Certificate Authority (CA): </strong></p>
<pre>$ CA.pl -newca</pre>
<p>After pressing enter, and following some instructions, a new folder &#8220;<em>demoCA</em>&#8221; is created with our newly created Certificate Authority.</p>
<p><strong>2. Create a certificate signing request:</strong></p>
<pre>$ CA.pl -newreq</pre>
<p>Follow the instructions to create the certificate signing request. Two files will be created: &#8220;Request is in <em>newreq.pem</em>, private key is in <em>newkey.pem</em>&#8220;.</p>
<p><strong>3. Sign it with the CA:</strong></p>
<pre>$ CA.pl -sign</pre>
<p>The signed certificate <em>newcert.pem</em> is generated.</p>
<p><strong>4. Create a client certificate that our user will install in his browser:</strong></p>
<pre>$ openssl pkcs12 -export -inkey newkey.pem \
           -in newcert.pem -out clientCertificate.p12</pre>
<p>As we can see, we use the private key <em>newkey.pem</em> and the CA signed certificate to create the client certificate.</p>
<p>Now that we have all the certificates created we need to use a tool to save our Certificate Authority that will be verified when someone asks for authorization with a certificate. I prefer to use the &#8220;<em>keytool</em>&#8220;. Verify that you have <em>keytool</em> command available before you begin:</p>
<p><strong>5. Create a keystore:</strong></p>
<pre>$ keytool -genkey -keystore truststore.jks</pre>
<p><strong>6. Add CA to keystore</strong></p>
<pre>$ keytool -import -trustcacerts -alias "my CA" \
                -file demoCA/cacert.pem -keystore truststore.jks</pre>
<p><strong>7. Configure Play! Framework:</strong></p>
<p>Add to the  <em>application.conf </em>file, the keystore configurations:</p>
<pre>play.netty.clientAuth=need
keystore.algorithm=jks
keystore.file=conf/truststore.jks
keystore.password=mykeystorepassword</pre>
<p><strong>Conclusions:</strong></p>
<p>Inside the keystore, there is the Certificate Authority that will be verified when the client tries to comunicate with the server, using a certificate signed by the CA. This is very helpful if you want to build a web application that is in the Internet, and you just want the people from inside the company to access to it. Off course, the disadvantage of this approach is that if your user steals the certificate, he also can access the application everywhere.</p>
<p><strong>References:</strong></p>
<ul>
<li><a href="http://www.playframework.org/documentation/1.2.3/configuration#play.netty.clientAuth">http://www.playframework.org/documentation/1.2.3/configuration#play.netty.clientAuth</a></li>
<li><a title="http://www.ipsec-howto.org/x595.html" href="http://www.ipsec-howto.org/x595.html">http://www.ipsec-howto.org/x595.html</a></li>
<li><a title="http://shib.kuleuven.be/docs/ssl_commands.shtml" href="http://shib.kuleuven.be/docs/ssl_commands.shtml">http://shib.kuleuven.be/docs/ssl_commands.shtml</a></li>
<li><a title="http://stackoverflow.com/questions/1666052/java-https-client-certificate-authentication" href="http://stackoverflow.com/questions/1666052/java-https-client-certificate-authentication">http://stackoverflow.com/questions/1666052/java-https-client-certificate-authentication</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://hugomonteiro.net/2011/09/30/client-certificates-and-play/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Access DB manager from the PlayFramework</title>
		<link>http://hugomonteiro.net/2011/06/26/access-db-manager-from-the-play-framework/</link>
		<comments>http://hugomonteiro.net/2011/06/26/access-db-manager-from-the-play-framework/#comments</comments>
		<pubDate>Sun, 26 Jun 2011 14:50:09 +0000</pubDate>
		<dc:creator>Hugo Monteiro</dc:creator>
				<category><![CDATA[play]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[dbmanager]]></category>
		<category><![CDATA[sql]]></category>
		<category><![CDATA[test]]></category>

		<guid isPermaLink="false">http://hugomonteiro.net/?p=387</guid>
		<description><![CDATA[With the new 1.2 version of play, now it&#8217;s possible to see all the tables in the database without needing an external database manager program. I have been developing in play, and I always feel the need of having a database in memory with test data being loaded each time I run the server. With [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignleft" title="playframework" src="http://www.realjenius.com/wp-content/uploads/2010/03/play.png" alt="The playframework logo" width="177" height="64" />With the new <strong>1.2 version</strong> of <a href="http://www.playframework.org/">play</a>, now it&#8217;s possible to see all the tables in the database without needing an external database manager program.</p>
<p>I have been developing in <a href="http://www.playframework.org/">play</a>, and I always feel the need of having a database in memory with test data being loaded each time I run the server. With this approach, I don&#8217;t need to have a SQL server running and I don&#8217;t need to be worried about changing my database model (for instance, conflict test data), so I just need to change my test data and run the <a href="http://www.playframework.org/">play</a> server again.</p>
<p>The new database manager that <a href="http://www.playframework.org/">playframework</a> uses is called <a href="http://www.h2database.com/">H2</a>. <a href="http://www.h2database.com/">H2</a> is a Java SQL database which allows to access in-memory/embedded/server databases. In my case, which I use a memory database and I have test data already, I just need to have a line in my Application.conf:</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">db=mem</div></div>
<p>The second thing is to do to access the <a href="http://www.h2database.com/">H2</a> database manager inside the <a href="http://www.playframework.org/">play</a> is access the <em><strong>http://localhost:9000/@db </strong></em>url (I am supposing that the dev server is running on your localhost). After accessing the database you just need to configure the <a href="http://www.h2database.com/">H2</a> login like the image:</p>
<p><a href="http://hugomonteiro.net/wp-content/uploads/2011/06/h2-server-login.png"><img class="aligncenter size-medium wp-image-388" title="h2-server-login" src="http://hugomonteiro.net/wp-content/uploads/2011/06/h2-server-login-300x212.png" alt="" width="300" height="212" /></a></p>
<p>Now you just need to press the connect button and voilá! <img src='http://hugomonteiro.net/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p><strong>Conclusions:</strong></p>
<ol>
<li>Run your playframework: <strong>play run myproject</strong> (with the &gt;=1.2 version of <a href="http://www.playframework.org">playframework</a>)</li>
<li>Access <strong><em>http://localhost:9000/@db</em></strong></li>
<li>Configure JDBC URL: <strong><em>jdbc:h2:mem:play </em></strong>(you can access other databases, for instance mysql)</li>
<li>Default authentication:<strong> username: sa / Password: (empty)</strong></li>
</ol>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://hugomonteiro.net/2011/06/26/access-db-manager-from-the-play-framework/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Deploying PlayFramework Apps in JBoss</title>
		<link>http://hugomonteiro.net/2010/04/01/deploying-playframework-apps-in-jboss/</link>
		<comments>http://hugomonteiro.net/2010/04/01/deploying-playframework-apps-in-jboss/#comments</comments>
		<pubDate>Thu, 01 Apr 2010 17:19:57 +0000</pubDate>
		<dc:creator>Hugo Monteiro</dc:creator>
				<category><![CDATA[Internet]]></category>
		<category><![CDATA[play]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[jboss]]></category>
		<category><![CDATA[web]]></category>

		<guid isPermaLink="false">http://hugomonteiro.net/?p=352</guid>
		<description><![CDATA[After you created your web application you need to create the WAR file that will insert the framework and other dependent libs inside the folder that you specify: play war myapp -o myapp.war Now to deploy on JBoss, you need to do some changes on your WAR file: Create a file called jboss-web.xml in the [...]]]></description>
			<content:encoded><![CDATA[<p>After you created your web application you need to create the WAR file that will insert the framework and other dependent libs inside the folder that you specify:</p>
<pre>play war myapp -o myapp.war
</pre>
<p>Now to deploy on <a href="http://www.jboss.com/">JBoss</a>, you need to do some changes on your WAR file:</p>
<ul>
<li>Create a file called<strong><em> <strong>jboss</strong>-web.xml </em></strong>in the myapp.war/WEB-INF/ directory container the  following:</li>
</ul>
<pre class="brush: xml;" >
&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;&nbsp;?&gt;
&lt;!DOCTYPE jboss-web PUBLIC "-//JBoss//DTD Web Application 2.4//EN" "http://www.jboss.org/j2ee/dtd/jboss-web_4_0.dtd"&gt;
<jboss-web>
<class-loading java2ClassLoadingCompliance="false">
<loader-repository>
com.example:archive=myapp.war
<loader-repository-config>java2ParentDelegation=false</loader-repository-config>
</loader-repository>
</class-loading>
</jboss-web>
</pre>
<ul>
<li>Download hibernate-validator and hibernate annotation using the compatibility matrix (<a title="Hibernate Compatibility Matrix" href="http://74.125.77.132/search?q=cache:Q9VmeUcio1MJ:https://www.hibernate.org/6.html+https://www.hibernate.org/6.html%23A3&amp;cd=1&amp;hl=nl&amp;ct=clnk&amp;gl=nl&amp;client=safari">Hibernate Compatibility Matrix</a>).  Play is using hibernate core 3.3.2 GA. Once you are done, place the  relevant jars in the myapp.war/WEB-INF/lib directory. You should end up with:
<ul>
<li>hibernate-annotations.jar</li>
<li>hibernate-entitymanager.jar</li>
<li>hibernate-validator.jar</li>
<li>hibernate-commons-annotations.jar</li>
<li>hibernate-search-3.1.1.GA.jar</li>
<li>hibernate3.jar (Do not overwrite this library, as Play! has a modified version of it)</li>
</ul>
</li>
<li>Now that we&#8217;re prepared for WAR, you need to move your application to the deployment folder of JBoss. The default folder for it is: <em>jboss_home/server/default/deploy </em>(jboss_home == folder of jboss). There are some things you need to be aware of:<em><br />
</em></p>
<ol>
<li>Use a superior java version in JBoss to avoid class version errors</li>
<li>Verify that the WAR folder has the necessary permissions. In my case I needed to make a &#8220;<em>chown -R jboss myapp.war</em>&#8221; where jboss is the user that controls the jboss application server</li>
<li>Do a &#8220;<em>tail -f jboss_home/server/default/log/server.log</em>&#8221; to see if your application is being deployed. You&#8217;ve an Administration Console in <em>http://yourserverip:8080</em></li>
<li>Don&#8217;t change your routes file at runtime<em>. Stop the war, change routes and then start the war (in the administration console I said before)<br />
</em></li>
</ol>
</li>
<li>Now you should have your application working. You can access to your app at: <em>http://yourserverip:8080/myapp.war</em></li>
<li><strong>This tutorial was tested in JBoss 5.0.1</strong><em><br />
</em></li>
</ul>
<p>Thanks to <a href="http://www.twitter.com/nicolasleroux">Nicolas Leroux</a> from <a href="http://lunatech.com">lunatech.com</a> for helping me to create this tutorial.</p>
]]></content:encoded>
			<wfw:commentRss>http://hugomonteiro.net/2010/04/01/deploying-playframework-apps-in-jboss/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Send file to user using views</title>
		<link>http://hugomonteiro.net/2010/03/16/send-a-file-to-user-using-a-view-with-play-framework/</link>
		<comments>http://hugomonteiro.net/2010/03/16/send-a-file-to-user-using-a-view-with-play-framework/#comments</comments>
		<pubDate>Tue, 16 Mar 2010 15:36:19 +0000</pubDate>
		<dc:creator>Hugo Monteiro</dc:creator>
				<category><![CDATA[Internet]]></category>
		<category><![CDATA[play]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[file]]></category>
		<category><![CDATA[mvc]]></category>
		<category><![CDATA[send]]></category>
		<category><![CDATA[web]]></category>

		<guid isPermaLink="false">http://hugomonteiro.net/?p=333</guid>
		<description><![CDATA[There are some simple steps to send a file to the user of your web application using the Play Framework: 1. After the controller is created (what I do is to copy the controller  &#8220;Application&#8221; and do a refactor rename to the name I want). Create a file named MyController (what I do is to [...]]]></description>
			<content:encoded><![CDATA[<p>There are some simple steps to send a file to the user of your web application using the <a href="http://www.playframework.org/">Play Framework</a>:</p>
<p>1. After the controller is created (what I do is to copy the controller  &#8220;Application&#8221; and do a refactor rename to the name I want).</p>
<ol>
<li>Create a file named MyController (what I do is to copy the controller  &#8220;Application&#8221; and do a rename to the name I want &#8211; in this case i chose the name MyController)</li>
<li>After this, you need to create a folder with the same name of the controller (in this case: MyController) &#8211; app/views/MyController</li>
<li>Now in the controller, you&#8217;ve to create an index method, where you&#8217;ll output data for the user, for instance:
<ol>
<li>
<pre>public static void index() {
    List users = User.all().fetch();
    render(users);
}</pre>
</li>
<li> Now you need to create a method that will create the file, or get the file somewhere:
<pre>public static void generateMyDocument() {
       File f = new File("myFile.xls");
       //now you've to edit the file, in this is case is an excel file,
       //so you can edit using a library like <a href="http://jexcelapi.sourceforge.net/">JExcelAPI</a></pre>
<pre>       //set the header with the size of the file
       response.setHeader("Content-Length", String.valueOf(f.length()));
       //set the content type, in this case is a microsoft excel
       response.contentType = "application/ms-excel";
       //send the file to the user
       renderBinary(f);
       //after I send the file, I want to return to the same page (index())
       index();
}</pre>
</li>
</ol>
</li>
<li>Now we need to create a view, inside that folder we just created (create an index.html file):
<ul>
<li>
<pre>&lt;a href="@{generateMyDocument()}"&gt;Download file&lt;/a&gt;</pre>
<p>We are calling the method from the controller. First we have the folder with the same name that will route directly to the method of the controller.Off course that we could do this:</li>
<pre>      &lt;a href="@{MyController.generateMyDocument()}"&gt;Download file&lt;/a&gt;</pre>
<p>And that&#8217;s it. The magic on the <a href="http://www.playframework.org">Play Framework</a> is done .</ul>
</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://hugomonteiro.net/2010/03/16/send-a-file-to-user-using-a-view-with-play-framework/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Security tips for a web developer</title>
		<link>http://hugomonteiro.net/2010/03/13/security-tips-for-a-web-developer-specially-using-the-playframework/</link>
		<comments>http://hugomonteiro.net/2010/03/13/security-tips-for-a-web-developer-specially-using-the-playframework/#comments</comments>
		<pubDate>Sat, 13 Mar 2010 11:24:15 +0000</pubDate>
		<dc:creator>Hugo Monteiro</dc:creator>
				<category><![CDATA[Internet]]></category>
		<category><![CDATA[play]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[cookies]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[session]]></category>
		<category><![CDATA[validation]]></category>

		<guid isPermaLink="false">http://hugomonteiro.net/?p=293</guid>
		<description><![CDATA[Every web application has two sides. The client side and the server side. Everything on the client side can be changed, and most of the security problems happens when you trust in the client. With a simple proxy (like webscarab) you can edit the fields that were validated using javascript. That&#8217;s why you always need [...]]]></description>
			<content:encoded><![CDATA[<p>Every web application has two sides. The client side and the server side. Everything on the client side can be changed, and most of the security problems happens when you trust in the client. With a simple proxy (like <a href="http://www.owasp.org/index.php/Category:OWASP_WebScarab_Project">webscarab</a>) you can edit the fields that were validated using javascript. That&#8217;s why you always need to validate the data on the server side. <a href="http://www.playframework.org/">Play Framework</a> has grown to be a great framework for this, giving advantages such as using annotations to control the type of data that came from the client side.</p>
<p>So, a great way to think out of box is to use those validation features inside the model, that every good MVC Framework has, and don&#8217;t trust to much on using hidden fields in the HTML that when changed can affect other users inside the web application. For instance, if you have an hidden field that has the id of the user, and if I change that, I can change others users data.</p>
<p><strong>So, in conclusion:<br />
</strong></p>
<ul>
<li>You can use cookies and sessions to know which user is authenticated (inside the model you can have the stuff he can do on the web application)</li>
<li>Don&#8217;t trust in the client side. Use always server and client validation</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://hugomonteiro.net/2010/03/13/security-tips-for-a-web-developer-specially-using-the-playframework/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Play Framework + Oracle = EASY!</title>
		<link>http://hugomonteiro.net/2010/01/28/oracle-play-framework-easy/</link>
		<comments>http://hugomonteiro.net/2010/01/28/oracle-play-framework-easy/#comments</comments>
		<pubDate>Thu, 28 Jan 2010 12:18:02 +0000</pubDate>
		<dc:creator>Hugo Monteiro</dc:creator>
				<category><![CDATA[Internet]]></category>
		<category><![CDATA[play]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[en]]></category>
		<category><![CDATA[oracle]]></category>
		<category><![CDATA[web]]></category>

		<guid isPermaLink="false">http://hugomonteiro.net/?p=277</guid>
		<description><![CDATA[To configure your oracle database using the play framework you need to follow the following steps: Choose the JAR with the drivers according to your oracle&#8217;s database version and put in the lib/ directory of your web application Configure your application.conf file,  located inside the conf/ directory In the JPA Configuration Section you have to [...]]]></description>
			<content:encoded><![CDATA[<p>To configure your oracle database using the <a href="http://www.playframework.org/">play framework</a> you need to follow the following steps:</p>
<ol>
<li>Choose the <a href="http://www.oracle.com/technology/software/tech/java/sqlj_jdbc/index.html">JAR</a> with the drivers according to your oracle&#8217;s database version and put in the <em>lib/</em> directory of your web application</li>
<li>Configure your application.conf file,  located inside the <em>conf/</em> directory
<ul>
<li>In the JPA Configuration Section you have to choose the <a href="http://docs.jboss.org/hibernate/core/3.3/reference/en/html/session-configuration.html#configuration-optional-dialects">JPA (Hibernate) dialect</a>. In my case I was working with oracle10g so i had to insert in the configuration file:
<ul>
<li>
<pre>jpa.dialect=org.hibernate.dialect.Oracle10gDialect</pre>
</li>
</ul>
</li>
<li>Now you just need to add the following lines, according to your database (including username and password).
<ul>
<li>
<pre>db.url=jdbc:oracle:thin:@yourdatabaseserver:1521:dbname
db.driver=oracle.jdbc.driver.OracleDriver
db.user=yourusername
db.pass=yourpassword</pre>
</li>
</ul>
</li>
</ul>
</li>
<li>Now you just need to restart the server. He adds the database drivers automatically to the classpath of the project.</li>
<li>If you want, you can generate <a href="http://www.netbeans.org">Netbeans</a> or <a href="http://www.eclipse.org">Eclipse</a> projects, so you can open this projects with everything configured.</li>
</ol>
<p>Really easy with no XMLs!</p>
]]></content:encoded>
			<wfw:commentRss>http://hugomonteiro.net/2010/01/28/oracle-play-framework-easy/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>[Play] Iterate over objects using jQuery</title>
		<link>http://hugomonteiro.net/2010/01/12/how-to-navigate-into-each-html-element-using-jquery/</link>
		<comments>http://hugomonteiro.net/2010/01/12/how-to-navigate-into-each-html-element-using-jquery/#comments</comments>
		<pubDate>Tue, 12 Jan 2010 14:13:49 +0000</pubDate>
		<dc:creator>Hugo Monteiro</dc:creator>
				<category><![CDATA[play]]></category>
		<category><![CDATA[en]]></category>
		<category><![CDATA[framework]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[web]]></category>

		<guid isPermaLink="false">http://hugomonteiro.net/?p=208</guid>
		<description><![CDATA[What if I want to navigate into each checkbox, radio of my html? You can do it pretty easily using jQuery.each function. In every checkbox element I want to send a post message to my Play Framework. ﻿﻿jQuery.each($(':checkbox'), function() { $﻿.post('@{myPlayMethod()}', { itemValue: $(this).val() }) });﻿ This code sends the html element value property to [...]]]></description>
			<content:encoded><![CDATA[<p>What if I want to navigate into each checkbox, radio of my html? You can do it pretty easily using <a href="http://docs.jquery.com/Utilities/jQuery.each">jQuery.each function</a>.</p>
<p>In every checkbox element I want to send a post message to my Play Framework.</p>
<pre>﻿﻿jQuery.each($(':checkbox'), function() {
    $﻿.post('@{myPlayMethod()}', { itemValue: $(this).val() })
});﻿</pre>
<p>This code sends the html element value property to method &#8220;<em>myPlayMethod(String itemValue)</em>&#8220;.</p>
]]></content:encoded>
			<wfw:commentRss>http://hugomonteiro.net/2010/01/12/how-to-navigate-into-each-html-element-using-jquery/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to divide your GUI from your processing code?</title>
		<link>http://hugomonteiro.net/2009/11/06/how-to-divide-your-gui-from-your-processing-code/</link>
		<comments>http://hugomonteiro.net/2009/11/06/how-to-divide-your-gui-from-your-processing-code/#comments</comments>
		<pubDate>Fri, 06 Nov 2009 14:53:43 +0000</pubDate>
		<dc:creator>Hugo Monteiro</dc:creator>
				<category><![CDATA[Software Development]]></category>
		<category><![CDATA[design]]></category>
		<category><![CDATA[design pattern]]></category>
		<category><![CDATA[en]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[software engineering]]></category>

		<guid isPermaLink="false">http://hugomonteiro.net/?p=157</guid>
		<description><![CDATA[Many students don't know how to organize their code. Abstractions and Interfaces makes a difference when developing Java applications. What if your code was divided? For instance, if you have created a network application with a GUI (Graphical User Interface). The first approach is to put the code all together because it's easier from the beginning. That's wrong because it's harder to find an error and you have to read a lot of garbage code like <em>textBox.setValue</em>...]]></description>
			<content:encoded><![CDATA[<p>Many students don&#8217;t know how to organize their code. Abstractions and Interfaces make a difference when developing Java applications. What if your code was divided? For instance, if you built a network application with a GUI (Graphical User Interface). The first approach is to put the code all together because it&#8217;s easier from the beginning. That&#8217;s wrong because it&#8217;s harder to find an error, and you have to read a lot of garbage code like <em>textBox.setValue</em>&#8230;</p>
<p>What about dividing this network application in two layers? One layer, with all the network code and the top layer with only the GUI? How is this possible? Using Java interfaces and the notion of events.</p>
<p>We can start by creating our event interface that will be waken up, when for instance we are receiving a message from the network:</p>
<pre>public interface EventNetworkInterface {
	void receiveMessage(String msg);
}</pre>
<p>Now it&#8217;s time to build our simplified network layer:</p>
<pre>
public class NetworkLayer {
	EventNetworkInterface gui = null;

	public NetworkLayer(EventNetworkInterface gui) {
		this.gui = gui;
	}

	public void receiveMessageNetwork() {
		//simulates receiving a message from the network
                String msg_received = "Hello World!";
		//wake up event in the GUI
		gui.receiveMessage(msg_received);
	}
}
</pre>
<p>Now with the network layer created you have to create the GUI:</p>
<pre>
public class GUI implements EventNetworkInterface {

	public static void main(String[] args) {
		new GUI();
	}

	private NetworkLayer nl;

	public GUI() {
		nl = new NetworkLayer(this);
		//issue a receiveMessage event:
		nl.receiveMessageNetwork();
	}

	@Override
	public void receiveMessage(String msg) {
		System.out.println("I sent the message: " + msg);
	}

}
</pre>
<p>In the GUI constructor we are simulating a <em>receivedMessage</em> event after we build the network layer and send the GUI that implements the events that will be waken up when a <em>receiveMessage</em> (in this case) happens.</p>
<p>With this approach you can separate the design code, from the processing code and simplify when you are adding more features to the layers beneath you.</p>
<p>If you want to have multiple classes to execute the same events, see more about the <a href="http://en.wikipedia.org/wiki/Observer_pattern">observer pattern</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://hugomonteiro.net/2009/11/06/how-to-divide-your-gui-from-your-processing-code/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Singleton Design Pattern problems?</title>
		<link>http://hugomonteiro.net/2009/10/24/singleton-design-pattern-problems/</link>
		<comments>http://hugomonteiro.net/2009/10/24/singleton-design-pattern-problems/#comments</comments>
		<pubDate>Sat, 24 Oct 2009 12:46:23 +0000</pubDate>
		<dc:creator>Hugo Monteiro</dc:creator>
				<category><![CDATA[Software Development]]></category>
		<category><![CDATA[design]]></category>
		<category><![CDATA[design pattern]]></category>
		<category><![CDATA[en]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[software]]></category>

		<guid isPermaLink="false">http://hugomonteiro.net/?p=123</guid>
		<description><![CDATA[The Singleton Pattern ensures a class has only one instance that provides a global point to access it. This design pattern is perfect for maintaining a set of configurations or other variables always available at run-time in your software. public static Singleton getInstance() { if (uniqueInstance == null) { uniqueInstance = new Singleton(); } return [...]]]></description>
			<content:encoded><![CDATA[<p>The <a href="http://en.wikipedia.org/wiki/Singleton_pattern">Singleton Pattern</a> ensures a class has only one instance that provides a global point to access it. This design pattern is perfect for maintaining a set of configurations or other variables always available at run-time in your software.</p>
<pre>public static Singleton getInstance() {
    if (uniqueInstance == null) {
       uniqueInstance = new Singleton();
    }
    return uniqueInstance;
}</pre>
<p>In this code snippet, if you have a multithreaded application that executes the same class, some concurrency problems can occur. For instance if the two threads accesses to the condition at the same time, creates two different Singleton instances. How can you fix this problem? Newer virtual machines (like JVM 1.5) ensures this when you create the Singleton instance in a static variable outside of any method. The JVM guarantees that the instance will be created before any thread accesses the static uniqueInstance variable. The solution for this is:</p>
<pre>public class Singleton {
    private static Singleton uniqueInstance = new Singleton ();

    private Singleton() {}

    public static Singleton getInstance () {
       return uniqueInstance;
    }
}</pre>
]]></content:encoded>
			<wfw:commentRss>http://hugomonteiro.net/2009/10/24/singleton-design-pattern-problems/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

