<?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>Paulo Canedo &#187; NetBeans English</title>
	<atom:link href="http://www.paulocanedo.com.br/category/netbeans_eng/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.paulocanedo.com.br</link>
	<description>Blog pessoal - TI, Java, NetBeans e Programação em geral</description>
	<lastBuildDate>Wed, 26 May 2010 16:30:10 +0000</lastBuildDate>
	<language>pt-BR</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
		<item>
		<title>Creating a CRUD with JSF and Ajax using NetBeans 6.5 Beta</title>
		<link>http://www.paulocanedo.com.br/2008/09/05/creating-a-crud-with-jsf-and-ajax-using-netbeans-65-beta/</link>
		<comments>http://www.paulocanedo.com.br/2008/09/05/creating-a-crud-with-jsf-and-ajax-using-netbeans-65-beta/#comments</comments>
		<pubDate>Fri, 05 Sep 2008 03:29:24 +0000</pubDate>
		<dc:creator>Paulo Canedo</dc:creator>
				<category><![CDATA[English]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[NetBeans English]]></category>
		<category><![CDATA[CRUD]]></category>
		<category><![CDATA[derby]]></category>
		<category><![CDATA[JPA]]></category>
		<category><![CDATA[JSF]]></category>
		<category><![CDATA[NetBeans 6.5]]></category>
		<category><![CDATA[NetBeans pt_BR]]></category>
		<category><![CDATA[Topink]]></category>

		<guid isPermaLink="false">http://localhost/wordpress/?p=32</guid>
		<description><![CDATA[Pre-requisite: NetBeans 6.5 Beta, or most recent version with the &#8220;Java Web and EE&#8221; or &#8220;All&#8221; pack. The glassfish version 2 or 3 must be installed. On this tutorial we will see how to create a CRUD application (Create, Read, Update and Delete) using the NetBeans IDE 6.5 Beta. The main features demonstred in this [...]]]></description>
				<content:encoded><![CDATA[<p>Pre-requisite: NetBeans 6.5 Beta, or most recent version with the &#8220;Java Web and EE&#8221; or &#8220;All&#8221; pack. The glassfish version 2 or 3 must be installed.</p>
<p>On this tutorial we will see how to create a CRUD application (Create, Read, Update and Delete) using the NetBeans IDE 6.5 Beta. The main features demonstred in this tutorial are: work with a web project using glassfish and Java Server Faces; create a Persistence Unit; create an Entity Class; automaticaly generate jsf pages from an Entity Class.</p>
<p>Let&#8217;s start, first of all go to the Services Tab (Ctrl+5), open Databases node and follow the steps bellow:</p>
<ol>
<li>Click with right button in Java DB on Start Server (Picture 1)</li>
<li>Click again with right button in Java DB and now click on Create Database&#8230;</li>
<li>In the next window fill all fields according to Picture 2</li>
</ol>
<div class="wp-caption alignnone" style="width: 301px"><img style="border: 0pt none;" title="Picture 1 - Starting Java DB server" src="http://www.paulocanedo.com.br/images/nb65beta-crud/nb65beta_start_javadb.gif" border="0" alt="" width="291" height="399" /><p class="wp-caption-text">Picture 1 - Starting Java DB server</p></div>
<div class="wp-caption alignnone" style="width: 554px"><img style="border: 0pt none;" title="Picture 2 - Creating a new database in Java DB" src="http://www.paulocanedo.com.br/images/nb65beta-crud/nb65beta_create_db.gif" border="0" alt="" width="544" height="206" /><p class="wp-caption-text">Picture 2 - Creating a new database in Java DB</p></div>
<p>After the database creation, so let&#8217;s go to our NetBeans project:</p>
<ol>
<li>Create a new web project (File-&gt;New project) in Java Web category, then choose the option Web Application (Picture 3)</li>
<li>in the next window fill all the fields according with Picture 4</li>
<li>Define the web server (recommended glassfish v2 or v3) and the context path (Picture 5)</li>
<li>Click next and select the framework: JavaServer Faces (Picture 6)</li>
</ol>
<div class="wp-caption alignnone" style="width: 729px"><img style="border: 0pt none;" title="Picture 3 - Creating a new web project" src="http://www.paulocanedo.com.br/images/nb65beta-crud/nb65beta_new_project_web.gif" border="0" alt="" width="719" height="468" /><p class="wp-caption-text">Picture 3 - Creating a new web project</p></div>
<div class="wp-caption alignnone" style="width: 731px"><img style="border: 0pt none;" title="Picture 4 - Defining project name and project local" src="http://www.paulocanedo.com.br/images/nb65beta-crud/nb65beta_name_and_location.gif" border="0" alt="" width="721" height="470" /><p class="wp-caption-text">Picture 4 - Defining project name and project local</p></div>
<div class="wp-caption alignnone" style="width: 731px"><img style="border: 0pt none;" title="Picture 5 - Suggestions to choose the web server and your configurations" src="http://www.paulocanedo.com.br/images/nb65beta-crud/nb65beta_server_and_settings.gif" border="0" alt="" width="721" height="470" /><p class="wp-caption-text">Picture 5 - Suggestions to choose the web server and your configurations</p></div>
<div class="wp-caption alignnone" style="width: 701px"><img style="border: 0pt none;" title="Picture 6 - Adding the framework Java Server Faces to your project" src="http://www.paulocanedo.com.br/images/nb65beta-crud/nb65beta_frameworks.gif" border="0" alt="" width="691" height="387" /><p class="wp-caption-text">Picture 6 - Adding the framework Java Server Faces to your project</p></div>
<p>Now your project is created, to test if your project is working correctly with the web server, click with rigth button in project tab (Ctrl+1) and click Run.<br />
Well, the next step is create a new Persistence Unit, an Entity Class, the JPA (Java Persistence API) controllers:</p>
<ol>
<li>Click in File-&gt;New File, select the Persistence category, so choose the option Persistence Unit and click next</li>
<li>Click at the combobox arrow and select New Data Source &#8230;</li>
<li>Type a name to jndi (eg: dsExemploJsf or dsSampleJsf), at Database Connection select the connection with the database that you created in the begin of this tutorial, click ok</li>
<li>In Provider and Database window fill all fields according with Picture 8 and then click finish</li>
<li>Again click File-&gt;New File, in Persistence category, select Entity Class and click next</li>
<li>In the next window fill all fields according with Picture 9 and click finish</li>
</ol>
<div class="wp-caption alignnone" style="width: 731px"><img style="border: 0pt none;" title="Picture 7 - New Persistence Unit" src="http://www.paulocanedo.com.br/images/nb65beta-crud/nb65beta_new_persistence_unit.gif" border="0" alt="" width="721" height="470" /><p class="wp-caption-text">Picture 7 - New Persistence Unit</p></div>
<p><em></em></p>
<div class="wp-caption alignnone" style="width: 786px"><img style="border: 0pt none;" title="Picture 8 - Provider and Database" src="http://www.paulocanedo.com.br/images/nb65beta-crud/nb65beta_provider_and_database.gif" border="0" alt="" width="776" height="470" /><p class="wp-caption-text">Picture 8 - Provider and Database</p></div>
<p><em></em></p>
<div class="wp-caption alignnone" style="width: 731px"><img style="border: 0pt none;" title="Picture 9 - Creating a new Entity class" src="http://www.paulocanedo.com.br/images/nb65beta-crud/nb65beta_new_entity_class.gif" border="0" alt="" width="721" height="470" /><p class="wp-caption-text">Picture 9 - Creating a new Entity class</p></div>
<p>After generating the Livro.java (or Book.java) NetBeans shold automatically open it, let&#8217;s edit this file that way:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="java" style="font-family:monospace;">@Id
@GeneratedValue<span style="color: #009900;">&#40;</span>strategy <span style="color: #339933;">=</span> GenerationType.<span style="color: #006633;">AUTO</span><span style="color: #009900;">&#41;</span>
<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">Long</span> id<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> isbn<span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> title<span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> author<span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">Integer</span> numberOfPages<span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">Double</span> weight<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">Long</span> getId<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #000000; font-weight: bold;">return</span> id<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Then put the cursor position at line imediatlly after:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setId<span style="color: #009900;">&#40;</span><span style="color: #003399;">Long</span> id<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">id</span> <span style="color: #339933;">=</span> id<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>then press simultaneously: alt+insert, select Getter and Setter&#8230; then select all fields and click ok.</p>
<p>After creation of the Entity Class, let&#8217;s go to more one netbeans wizard wich will generate all necessary code to work with JPA and JSF files, so click in File-&gt;New File, in Persistence category, choose the option: JSF Pages From Entity Classes, and follow steps:</p>
<ol>
<li>Choose Livro&#8217;s (or Book&#8217;s) Entity Classe (Picture 10)</li>
<li>Choose the packages where will be generated the files for JPA and JSF manipulation (Picture 11), here note that the option &#8220;Ajax-enable generated pages&#8221; is displayed, this option allows generated code to use Ajax technology, remember that this is only available from version 6.5 beta or the most recent version.</li>
</ol>
<div class="wp-caption alignnone" style="width: 801px"><img style="border: 0pt none;" title="Picture 10 - Select Entity Classes" src="http://www.paulocanedo.com.br/images/nb65beta-crud/nb65beta_new_jsf_from_entity_class.gif" border="0" alt="" width="791" height="515" /><p class="wp-caption-text">Picture 10 - Select Entity Classes</p></div>
<div class="wp-caption alignnone" style="width: 801px"><img style="border: 0pt none;" title="Picture 11 - Select packages to JPA and JSF" src="http://www.paulocanedo.com.br/images/nb65beta-crud/nb65beta_new_jsf_from_entity_class2.gif" border="0" alt="" width="791" height="515" /><p class="wp-caption-text">Picture 11 - Select packages to JPA and JSF</p></div>
<p>Now we have all necessary code, to test our project result, build the project (type Shift+11, clean and build project) click with right button in project name by Projects tab (Ctrl+1), after click &#8220;Undeploy and Deploy&#8221; to remove the web project of server (if there is) and deploy version that you already finished building (Picture 12).</p>
<p>If there are no errors message at Output tab (Ctrl+4), you can run the project using F6 key and see your CRUD working wonderful. (Pictures 13 and 14)</p>
<div class="wp-caption alignnone" style="width: 308px"><img style="border: 0pt none;" title="Picture 12 - Project Undeploy and Deploy" src="http://www.paulocanedo.com.br/images/nb65beta-crud/nb65beta_undeploy_deploy.gif" border="0" alt="" width="298" height="466" /><p class="wp-caption-text">Picture 12 - Project Undeploy and Deploy</p></div>
<div class="wp-caption alignnone" style="width: 683px"><img style="border: 0pt none;" title="Picture 13 - CRUD finished, inserting a new registry" src="http://www.paulocanedo.com.br/images/nb65beta-crud/nb65beta_new_livro.gif" border="0" alt="" width="673" height="521" /><p class="wp-caption-text">Picture 13 - CRUD finished, inserting a new registry</p></div>
<div class="wp-caption alignnone" style="width: 683px"><img style="border: 0pt none;" title="Picture 14 - CRUD finished, registries overview after insert confirmation" src="http://www.paulocanedo.com.br/images/nb65beta-crud/nb65beta_livro_created.gif" border="0" alt="" width="673" height="521" /><p class="wp-caption-text">Picture 14 - CRUD finished, registries overview after insert confirmation</p></div>
<p><strong>Conclusion: </strong> It&#8217;s not recommendable the use of this wizard to generate CRUD by NetBeans for people who don&#8217;t have experience with Java Server Faces to do their production work day by day. The importance of this NetBeans feature for this public is that they have access to development step by step about the creation of a CRUD using these wonderful Java frameworks. The learning on this activity is quite satisfactory. For those who already have experience just a look at the creation process and results will teach what to do. For those who want something practical, without much detail, and that is quite fast to do, this guide is quite helpful.</p>
<p>Revised by Ana Lyvia Liveira.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.paulocanedo.com.br/2008/09/05/creating-a-crud-with-jsf-and-ajax-using-netbeans-65-beta/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>
