<?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>Andy Gibson &#187; Netbeans</title>
	<atom:link href="http://www.andygibson.net/blog/tag/netbeans/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.andygibson.net/blog</link>
	<description>Open Source Projects &#38; Technical Writings</description>
	<lastBuildDate>Thu, 02 Feb 2012 14:33:32 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language></language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Create A New Project With Maven Archetypes</title>
		<link>http://www.andygibson.net/blog/tutorial/getting-started-with-maven-archetypes/</link>
		<comments>http://www.andygibson.net/blog/tutorial/getting-started-with-maven-archetypes/#comments</comments>
		<pubDate>Sun, 01 Aug 2010 16:50:12 +0000</pubDate>
		<dc:creator>Andy Gibson</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Apprentice]]></category>
		<category><![CDATA[Archetypes]]></category>
		<category><![CDATA[eclips]]></category>
		<category><![CDATA[Knappsack]]></category>
		<category><![CDATA[Maven]]></category>
		<category><![CDATA[Netbeans]]></category>

		<guid isPermaLink="false">http://www.andygibson.net/blog/?p=1076</guid>
		<description><![CDATA[Prerequisites Install Maven In this tutorial, we will create a new project using the Knappsack Archetypes and compile and deploy it. For this example, we will use the jee6-basic-archetype. Before you begin, you will need to have installed Maven, but you no longer need to manually install the Knappsack Archetypes as they are in the [...]]]></description>
			<content:encoded><![CDATA[<div class="prereq">
<ul>
<lh>Prerequisites</lh></p>
<li>Install Maven</li>
</ul>
</div>
<p>In this tutorial, we will create a new project using the Knappsack Archetypes and compile and deploy it. For this example, we will use the <code>jee6-basic-archetype</code>.  Before you begin, you will need to have installed Maven, but you no longer need to manually install the Knappsack Archetypes as they are in the Central Maven Repository now, so you just need to make sure your index is up to date.  These instructions will work for any Maven Archetype you have installed and creating new maven projects in general.<br />
<span id="more-1076"></span><br />
Maven archetypes can be thought of as templates that are installed into the Maven environment and can be used to generate new applications from scratch that are pre-configured for certain environments, whether it is Java EE 6, Wicket or Spring. We can create our project using either the command line or an IDE and both Eclipse and Netbeans both have support for Maven. Netbeans has it out of the box while Eclipse requires m2Eclipse to be installed. This tutorial covers all three methods of creating projects from Maven.</p>
<h1>New project from the Command Line</h1>
<ol>
<li>Start by opening up a command prompt and navigating to the directory your project will reside in</li>
<li>The easy way to create a project on the command line is to just type
<pre class="brush: plain;">
mvn archetype:generate
</pre>
<p>We will use the easier version where we don&#8217;t have to specify long command lines that include the group and archetype Ids and versions.
</li>
<li> You will be greeted with a long list of possible archetypes with a number next to them and a prompt at the bottom to enter the number of the archetype you want to use.
<pre class="brush: plain;">
4: local -&gt; jee6-minimal-archetype (Minimal Java EE application with a single page demo of CDI, JSF, JPA and Validation to ...
5: local -&gt; jee6-basic-archetype (Basic Java EE application with just configuration for CDI, JSF, JPA and a sample empty page.)
6: local -&gt; jee6-sandbox-archetype (Sandbox project for Java EE 6 with CDI, JSF, JPA and a sample model and test data to play ....
7: local -&gt; jee6-sandbox-demo-archetype (Complete demo example using CDI, JSF, JPA and validation showcasing a number of ...
8: remote -&gt; docbkx-quickstart-archetype (null)
9: remote -&gt; j2me-simple (Maven 2 Archetype for midlet application using j2me-maven-plugin)
10: remote -&gt; vaadin-archetype-clean (This archetype generates a simple Vaadin application as a Maven project...
...
...
...
...
Choose a number: 65:
</pre>
<p>Hint : Your locally installed ones should be near the start of the list. The default number (in this case 65) is the quickstart archetype to produce and empty maven project.
</li>
<li>Enter the number of the Knappsack archetype you want to use and press enter.</li>
<li>You will then be asked to enter a number of different properties for the project :
<pre class="brush: plain;">
Define value for property 'groupId': : com.yourcompany
Define value for property 'artifactId': : yourprojectname
Define value for property 'version': 1.0-SNAPSHOT:
Define value for property 'package': com.yourcompany:
Confirm properties configuration:
groupId: com.yourcompany
artifactId: yourprojectname
version: 1.0-SNAPSHOT
package: com.yourcompany
Y:
</pre>
<p>Here we assumed the version is the default SNAPSHOT version and that the default package is the same as the groupId value.
</li>
<li>Once complete, if you look in the directory you will see a new directory called <code>yourprojectname</code>. Move into this directory and if you have <code>JBOSS_HOME</code> set up you can deploy the project straight away.
<pre class="brush: plain;">
mvn clean package jboss:hard-deploy
</pre>
<p>Start up JBoss if it isn&#8217;t already and go to <a href="http://localhost:8080/yourprojectname/home.jsf">http://localhost:8080/yourprojectname/home.jsf</a>.
</li>
<li>You can now import this project into an IDE such as Eclipse or Netbeans as these IDEs recognize Maven projects</li>
</ol>
<p>Alternatively, you can use the command line to enter one long command, or as I do, put it in a script or batch file that I can edit in a text editor and run it from there. Here&#8217;s an example to get you started which you can copy and paste:</p>
<pre class="brush: plain;">
mvn archetype:generate -DarchetypeGroupId=org.fluttercode.knappsack -DarchetypeArtifactId=jee6-sandbox-demo-archetype -DinteractiveMode=false -DarchetypeVersion=1.0.4 -DgroupId=org.application -DartifactId=sandboxdemo -Dpackage=org.application
</pre>
<h1>Creating a project in an IDE</h1>
<p>Creating a Maven project in an IDE is much easier, although sometimes not by much. Typically, you choose to create a new project in the IDE and select maven as the type of project you want to create. </p>
<h2>Netbeans</h2>
<ol>
<li>Select <em>File->New Project</em> and in the first list, select <em>Maven</em> and on the right hand side, select <em>Maven Project</em> (<b>not</b> <em>Maven Web Application</em>). Click Next.</li>
<li>Here we will pick our archetype to create our application from. In the list, expand the <em>Archetypes from Local Repository</em> item in the list. If you don&#8217;t see the archetypes there, you might need to refresh the index in the IDE. Close the new project window to do this.
<ol>
<li>Select <em>Window->Other->Maven Repository Browser</em> to open the repository browser. </li>
<li>In the repository browser window, right click on the repository and select <em>Update Index</em>.</li>
</ol>
<p>Now you should be able to start the new project from scratch and see the missing archetypes.</p>
<div class="contentBox alignCenter">
<a href="http://www.andygibson.net/blog/wp-content/uploads/2010/07/netbeans_select_archetype.png" target="_blank"><img src="http://www.andygibson.net/blog/wp-content/uploads/2010/07/netbeans_select_archetype-300x182.png" alt="Netbeans Select Archetype Screenshot" title="Netbeans Select Archetype" width="300" height="182" /></a>
</div>
<p>Once you have selected the archetype, click finish to setup the project properties.
</li>
<li>The project properties are the group and archetype Id for the new project as well as the optional default package name.
<div class="contentBox alignCenter">
<a href="http://www.andygibson.net/blog/wp-content/uploads/2010/07/netbeans_project_properties.png"><img src="http://www.andygibson.net/blog/wp-content/uploads/2010/07/netbeans_project_properties-300x156.png" alt="netbeans project properties screenshot" title="netbeans project properties screenshots" width="300" height="156" /></a>
</div>
<p>You will also configure the project location here and click <em>Finish</em> when done.
</li>
<li>Once complete, Netbeans will create your project and open it up.  To run it, click <em>Run->Run Main Project</em> and it will prompt you for a Java EE 6 server to use. Select one and click ok. Remember that you need to change the datasource name in <code>persistence.xml</code> so it is not looking for the JBoss default datasource name. </li>
</ol>
<h2>Eclipse</h2>
<p>First make sure you have m2Eclipse installed and are running Eclipse under a JDK instead of a JRE. For more details see this  <a href="http://www.andygibson.net/tutorial/installing-and-configuring-eclipse/">Installing and configuring Eclipse tutorial</a>.</p>
<ol>
<li>In Eclipse, click on <em>File->New->Other..</em> to bring up the dialog for new projects and start typing &#8220;maven&#8221; in the search box</p>
<div class="contentBox alignCenter">
<a href="http://www.andygibson.net/blog/wp-content/uploads/2010/07/eclipse_new_maven_project.png"><img src="http://www.andygibson.net/blog/wp-content/uploads/2010/07/eclipse_new_maven_project-300x186.png" alt="Eclipse New Maven Project Screenshot" title="Eclipse New Maven Project Screenshot" width="300" height="186" /></a>
</div>
<p>Select the maven project item from the list and click <em>Next</em>.
</li>
<li> This page lets you determine where the project will reside. Leave the defaults, but make sure the &#8220;Create simple project&#8221; option is <b>un</b>checked and click <em>Next</em>.</li>
<li>Here we will pick our archetype which in this case is our Knappsack jee6 minimal archetype. Start typing &#8220;knappsack&#8221; in the list and you will see the list of available Knappsack archetypes. Again, it is possible that the IDE&#8217;s index of the local repository is not up to date and needs a refresh. You will need to cancel the project creation window to do this.
<ol>
<li>Select <em>Window->Show View->Other</em> and in the view selection , start typing &#8220;Maven&#8221; until you see the window &#8220;Maven Repositories&#8221;. Select this to open up the view.</li>
<li>In the Maven Repositories view, expand the <em>Local Repositories</em> item and right click click on the <em>Local Repository (pathname)</em> item and select <em>Rebuild Index</em>. Confirm that you want to rebuild the index and wait a few moments.</li>
<li>Restart the project creation and this time you should see the archetypes you are looking for.</li>
</ol>
<div class="contentBox alignCenter">
<a href="http://www.andygibson.net/blog/wp-content/uploads/2010/07/eclipse_select_knappsack.png"><img src="http://www.andygibson.net/blog/wp-content/uploads/2010/07/eclipse_select_knappsack-300x268.png" alt="Eclipse Select Archetype" title="Eclipse Select Archetype" width="300" height="268" /></a>
</div>
<p>Select the archetype you want to create and click <em>Next</em>.
</li>
<li>Now we need to enter the project configuration information, what our project is called, give it a group id, version and default package.
<div class="contentBox alignCenter">
<a href="http://www.andygibson.net/blog/wp-content/uploads/2010/07/eclipse_project_properties.png"><img src="http://www.andygibson.net/blog/wp-content/uploads/2010/07/eclipse_project_properties-300x268.png" alt="Eclipse new Maven Project Properties" title="Eclipse new Maven Project Properties" width="300" height="268" /></a>
</div>
<p>Once the above information is entered you can click <em>Finish</em> and Eclipse will work away at creating your project
</li>
<li>To run the project, the easiest way is to install a server in Eclipse (see <a href="http://www.fluttercode.com/tutorial/installing-servers-into-eclipse/">Tutorial on adding servers in Eclipse</a>) and add the new project to the server. Start the server and navigate to your main page to see it in action.
</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://www.andygibson.net/blog/tutorial/getting-started-with-maven-archetypes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Getting Started with CDI part 2 &#8211; Injection</title>
		<link>http://www.andygibson.net/blog/tutorial/getting-started-with-cdi-part-2-injection/</link>
		<comments>http://www.andygibson.net/blog/tutorial/getting-started-with-cdi-part-2-injection/#comments</comments>
		<pubDate>Tue, 22 Dec 2009 13:45:20 +0000</pubDate>
		<dc:creator>Andy Gibson</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[CDI]]></category>
		<category><![CDATA[EJB]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[JEE]]></category>
		<category><![CDATA[JSF]]></category>
		<category><![CDATA[Netbeans]]></category>
		<category><![CDATA[Weld]]></category>

		<guid isPermaLink="false">http://www.andygibson.net/blog/?p=706</guid>
		<description><![CDATA[In part 1, we looked at creating a JEE 6 application with Netbeans using JSF and CDI running on Glassfish. Now we&#8217;ll take a closer look at using CDI for managing dependencies in a Java EE 6 environment. Read Part 1 Read Part 2 Read Part 3 Last Time Last time we looked at setting [...]]]></description>
			<content:encoded><![CDATA[<p>In <a href="http://www.andygibson.net/blog/index.php/tutorial/getting-started-with-jsf-2-0-and-cdi-in-jee-6-part-1/"> part 1</a>, we looked at creating a JEE 6 application with Netbeans using JSF and CDI running on Glassfish. Now we&#8217;ll take a closer look at using CDI for managing dependencies in a Java EE 6 environment.<br />
<span id="more-706"></span><br />
Read <a href="http://www.andygibson.net/blog/tutorial/getting-started-with-jsf-2-0-and-cdi-in-jee-6-part-1/">Part 1</a><br />
Read <a href="http://www.andygibson.net/blog/tutorial/getting-started-with-cdi-part-2-injection/">Part 2</a><br />
Read <a href="http://www.andygibson.net/blog/tutorial/getting-started-with-jsf-2-0-and-cdi-part-3/">Part 3</a></p>
<h1>Last Time</h1>
<p>Last time we looked at setting up the development environment and creating our EE6 application in Netbeans and deploying it to Glassfish v3. This time, we&#8217;ll skip straight to writing code which can be put into either a new Netbeans project using the previous tutorial, or you can use the existing project and just add the new code.</p>
<h1>The &#8216;I&#8217; in CDI</h1>
<p>CDI is an API for injecting contexts and dependencies  which is the part we&#8217;ll turn our attention to now. In Seam and Spring dependencies worked mostly by naming beans and binding them to their injection points by their name. So far we have only referenced a managed bean by name from the JSF page when we defined the name for the bean using the <code>@Named</code> annotation. The primary role of the <code>@Named</code> annotation is to define the bean for the purpose of resolving EL statements within the application, usually through the JSF EL resolvers. Injection <i>could</i> be performed by using names, but this was not how injection in CDI was meant to work since CDI gives us a much richer way to express injection points and the beans to be injected into them.</p>
<p>Let&#8217;s look at an example which is somewhat contrived. We have a dao that returns a list of objects that need validating, and for invalid ones, we take a certain action.  Here&#8217;s the definition for the item.</p>
<pre class="brush: java;">
package eedemo;

public class Item {

    private int value;
    private int limit;

    @Override
    public String toString() {
        return super.toString() + String.format(&quot; [Value=%d, Limit=%d]&quot;, value,limit);
    }

    /*
    getters and setters omitted
    */
}
</pre>
<p>The <code>ItemDao</code> interface defines how we get the list of item objects. In this test application we anticipate using multiple implementations so we will code to interfaces. </p>
<pre class="brush: java;">
public interface ItemDao {

    List&lt;Item&gt; fetchItems();

}
</pre>
<p>The <code>ItemProcessor</code> is our main class that we will inject our beans into and execute the process from. For now, we will start with the Dao and look at how we will inject it into our processor bean.</p>
<pre class="brush: java;">
import java.util.List;
import javax.inject.Named;
import javax.enterprise.context.RequestScoped;

@Named(&quot;itemProcessor&quot;)
@RequestScoped
public class ItemProcessor {

    private ItemDao itemDao;

    public void execute() {
      List&lt;Item&gt;  items = itemDao.fetchItems();
      for (Item item : items) {
          System.out.println(&quot;Found item &quot;+item);
      }
    }
}
</pre>
<p>We&#8217;ll start with a simple Dao that just creates a list of items and returns a fixed list of items.</p>
<pre class="brush: java;">
public class DefaultItemDao implements ItemDao {

    public List&lt;Item&gt; fetchItems() {
        List&lt;Item&gt; results = new ArrayList&lt;Item&gt;();
        results.add(new Item(34, 7));
        results.add(new Item(4, 37));
        results.add(new Item(24, 19));
        results.add(new Item(89, 32));
        return results;
    }
}
</pre>
<p>In order to inject the <code>DefaultItemDao</code> into our <code>ItemProcessor</code> we add the <code>javax.inject.Inject</code> annotation to the <code>ItemDao</code> field to indicate that this field is an injection point.</p>
<pre class="brush: java;">
@Named(&quot;itemProcessor&quot;)
@RequestScoped
public class ItemProcessor {

    @Inject
    private ItemDao itemDao;

    ...
}
</pre>
<p>Finally, we need some way to call the <code>execute()</code< method on the <code>ItemProcessor</code>. We can run this in a SE environment, but for now we&#8217;ll keep it in a JSF page. We&#8217;ll add a new page with a button to call the execute method called <code>process.xhtml</code>.</p>
<pre class="brush: xml;">
&lt;?xml version='1.0' encoding='UTF-8' ?&gt;
&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;&gt;
&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot;
      xmlns:h=&quot;http://java.sun.com/jsf/html&quot;&gt;
    &lt;h:head&gt;
        &lt;title&gt;Item Processor&lt;/title&gt;
    &lt;/h:head&gt;
    &lt;h:body&gt;
        &lt;h:form&gt;
        &lt;h:commandButton action=&quot;#{itemProcessor.execute}&quot; value=&quot;Execute&quot;/&gt;&lt;br/&gt;
        &lt;/h:form&gt;
    &lt;/h:body&gt;
&lt;/html&gt;
</pre>
<p>If you open up the page at <a href="http://localhost:8080/ee6demo/faces/process.xhtml">http://localhost:8080/ee6demo/faces/process.xhtml</a> you will see just a button that when clicked lists the items from our default Dao implementation in the console.</p>
<pre class="brush: plain;">
INFO: Found item eedemo.Item@23cbc6 [Value=34, Limit=7]
INFO: Found item eedemo.Item@a40279 [Value=4, Limit=37]
INFO: Found item eedemo.Item@19e6292 [Value=24, Limit=19]
INFO: Found item eedemo.Item@1597bc4 [Value=89, Limit=32]
</pre>
<p>We created a class which implements the <code>ItemDao</code> interface and when the application was deployed our managed beans in the module were processed by the CDI implementation (again because of the <code>beans.xml</code> file in the module. Our <code>Inject</code> annotation specifies that we want to inject a managed bean into that field and the only thing we know about the bean to inject is that it must implement <code>ItemDao</code> or some subtype of that interface. In this case, the <code>DefaultItemDao</code> class fits the bill perfectly.</p>
<p>Let&#8217;s say we add another Dao class to our application which also implements the <code>ItemDao</code> interface, now the choice isn&#8217;t so clear as to which bean we want to inject.</p>
<pre class="brush: java;">
public class AnotherItemDao implements ItemDao {

    public List&lt;Item&gt; fetchItems() {
        List&lt;Item&gt; results = new ArrayList&lt;Item&gt;();
        results.add(new Item(99, 9));
        return results;
    }

}
</pre>
<p>We now have two classes the implement this interface and predictably, Weld gives us an ambiguous dependency error meaning that it cannot determine what bean to use for that injection point. Most, if not all of the errors that can occur with regards to CDI injection in Weld are reported at deployment time, even down to whether beans are missing a Serializable implementation.</p>
<pre class="brush: plain;">
Caused by: org.jboss.weld.DeploymentException: Injection point has ambiguous dependencies.
Injection point: field eedemo.ItemProcessor.itemDao; Qualifiers: [@javax.enterprise.inject.Default()]; 

Possible dependencies: [eedemo.AnotherItemDao, eedemo.DefaultItemDao]
</pre>
<p>We could make our <code>itemDao</code> field in the item processor a type that matches one of the implementation types (<code>AnotherItemDao</code> or  <code>DefaultItemDao</code>) since it would then match one and only one class type. However, then we would lose the benefits of coding to an interface and find it harder to change implementations without changing the field type. A better solution is to instead look at CDI Qualifiers.</p>
<h1>Qualifiers</h1>
<p>A CDI qualifier is an annotation that can be applied at the class level to indicate the kind of bean the class is, and also at the field level (among other places) to indicate what kind of bean needs to be injected at that point.</p>
<p>When CDI inspects an injection point to find a suitable bean to inject it takes not only the class type into account, but also any qualifiers. Without knowing it, we have already used one qualifier which is the default qualifier called <code>@Any</code>. Let&#8217;s create a <code>@Demo</code> qualifier which we can apply to our <code>DefaultItemDao</code> implementation and also to the injection point.</p>
<pre class="brush: java;">
package eedemo.qualifier;

import static java.lang.annotation.ElementType.TYPE;
import static java.lang.annotation.ElementType.FIELD;
import static java.lang.annotation.ElementType.PARAMETER;
import static java.lang.annotation.ElementType.METHOD;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import javax.inject.Qualifier;

@Retention(RetentionPolicy.RUNTIME)
@Target({FIELD,METHOD,PARAMETER,TYPE})
@Qualifier
public @interface Demo {

}
</pre>
<p>First, we&#8217;ll add this qualifier to our default dao implementation at the class level.</p>
<pre class="brush: java;">
@Demo
public class DefaultItemDao implements SomeDao {

    public List&lt;Item&gt; fetchItems() {
..
..
</pre>
<p>If you save and deploy this file now, you may notice that we don&#8217;t have any errors, and if you go to the web page and click the execute button, you can see that in the console, it displays the list of items from the <code>AnotherItemDao</code> dao (remember we annotated the <code>DefaultItemDao</code> implementation but not the injection point). By adding the <code>Demo</code> qualifier to the default dao implementation, we made the other implementation a more suitable match for the injection point as it matched on type and on qualifiers and the <code>DefaultItemDao</code> has a qualifier that is not on the injection point making it less suitable.</p>
<p>If we add the <code>Demo</code> annotation to the injection point and deploy it, when we click our button we use the default implementation again. This is because we are matching based on type and qualifiers and the <code>DefaultItemDao</code> is the only bean with both the correct type and the <code>Demo</code> annotation.</p>
<h1>Alternative Injection Methods</h1>
<p>There are multiple ways to define an injection point on the injected class. So far we have annotated the fields that will reference the injected object. You do not need to provide getters and setters for field injection. If we wish to create immutable managed beans with final fields, we can use injection in the constructor by annotating the constructor with the <code>Inject</code> annotation. We can then apply any annotations to constructor parameters to qualify beans for injection (of course, each parameter has a type that can assist in qualifying beans for injection). A bean may only have one constructor with injection points defined, but it may implement more than one constructor.</p>
<pre class="brush: java;">
@Named(&quot;itemProcessor&quot;)
@RequestScoped
public class ItemProcessor {

    private final ItemDao itemDao;

    @Inject
    public ItemProcessor(@Demo ItemDao itemDao) {
        this.itemDao = itemDao;
    }
}
</pre>
<p>We can also call an inialization method which can be passed the beans to be injected.</p>
<pre class="brush: java;">
@Named(&quot;itemProcessor&quot;)
@RequestScoped
public class ItemProcessor {

    private ItemDao itemDao;

    @Inject
    public void setItemDao(@Demo ItemDao itemDao) {
        this.itemDao = itemDao;
    }
}
</pre>
<p>While in the above case we used the setter method for initialization we can create any method and use it for initialization with as many beans as we want in the method call. We can also have multiple initialization methods in a bean. </p>
<pre class="brush: java;">
    @Inject
    public void initBeans(@Demo ItemDao itemDao,@SomeQualifier SomeType someBean) {
        this.itemDao = itemDao;
        this.bean = someBean;
    }
</pre>
<p>The same rules apply to bean matching regardless of how the injection point is defined, it will try and find the best match based on type and qualifiers and will fail on deployment if there are multiple matching beans or no matching beans for an injection point.</p>
<p>Let&#8217;s look at the other aspects of our application, we get a list of items, iterate through them and test each one and if it fails that test, we pass it on to an error handler. We&#8217;ll create an <code>ItemValidator</code> interface to determines whether an item is valid or not.</p>
<pre class="brush: java;">
public interface ItemValidator {
    boolean isValid(Item item);
}
</pre>
<p>We&#8217;ll expand our <code>ItemProcessor</code> class to incorporate the new feature.</p>
<pre class="brush: java;">
@Named(&quot;itemProcessor&quot;)
@RequestScoped
public class ItemProcessor {

    @Inject @Demo
    private ItemDao itemDao;

    @Inject
    private ItemValidator itemValidator;

    public void execute() {
      List&lt;Item&gt;  items = itemDao.fetchItems();
      for (Item item : items) {
          System.out.println(&quot;Item = &quot;+item+&quot; valid = &quot;+itemValidator.isValid(item));
      }
    }
}
</pre>
<p>Our first implementation will be <code>DefaultItemValidator</code> which will simply test the limit against the value.</p>
<pre class="brush: java;">
public class DefaultItemValidator implements ItemValidator {

    public boolean isValid(Item item) {
        return item.getValue() &lt; item.getLimit();
    }
}
</pre>
<p>If we save our changes, go to our web page and click our button, in the console you will see that our items are being validated and the only valid item is where the value is less than the limit.</p>
<pre class="brush: plain;">
INFO: Item = eedemo.Item@25dd89 [Value=34, Limit=7] valid = false
INFO: Item = eedemo.Item@1f37ca2 [Value=4, Limit=37] valid = true
INFO: Item = eedemo.Item@7b8d67 [Value=24, Limit=19] valid = false
INFO: Item = eedemo.Item@18075da [Value=89, Limit=32] valid = false
</pre>
<p>Now lets consider the scenario where we have a deployment to a different site that is more relaxed and considers an item invalid only if the value is more than twice the limit. We may want to have another bean that implements the validator interface for that logic.</p>
<pre class="brush: java;">
public class RelaxedItemValidator implements ItemValidator {

    public boolean isValid(Item item) {
        return item.getValue() &lt; (item.getLimit() * 2);
    }
}
</pre>
<p>Now we have an ambiguous dependency problem since we have two classes implementing the same interface. The only difference is based on deployment so for most deployments, we want to use the default, but for one deployment, we want to use the relaxed implementation. CDI offers the use of the <code>Alternative</code> annotation which lets you package multiple beans that match an injection point without ambiguity errors, and the bean to use is defined in the <code>beans.xml</code>. This means you can deploy both implementations in the same module with the only difference being the beans.xml definition which can change over different deployments. </p>
<pre class="brush: java;">

@Alternative
public class DefaultItemValidator implements ItemValidator {

    public boolean isValid(Item item) {
        return item.getValue() &lt; item.getLimit();
    }
}
</pre>
<p>and</p>
<pre class="brush: java;">
@Alternative
public class RelaxedItemValidator implements ItemValidator {

    public boolean isValid(Item item) {
        return item.getValue() &lt; (item.getLimit() * 2);
    }
}
</pre>
<p>If we deploy our application now, we will get an unsatisfied dependency error since we defined the two matching beans as alternative but we didn&#8217;t enable either of them in the <code>beans.xml</code> file.</p>
<pre class="brush: xml;">
&lt;beans
    xmlns=&quot;http://java.sun.com/xml/ns/javaee&quot;
    xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
    xsi:schemaLocation=&quot;

http://java.sun.com/xml/ns/javaee

http://java.sun.com/xml/ns/javaee/beans_1_0.xsd&quot;&gt;

    &lt;alternatives&gt;
        &lt;class&gt;eedemo.RelaxedItemValidator&lt;/class&gt;
    &lt;/alternatives&gt;
&lt;/beans&gt;
</pre>
<p>This tells CDI that for this deployment we want to use the <code>RelaxedItemValidator</code>. You can think of the alternative annotation as effectively disabling the bean making it unavailable for injection, but allowing the implementation to be packaged with the other beans. Adding it as an alternative in the <code>beans.xml</code> file effectively enables the bean making it available for injection. By moving this type of metadata to the <code>beans.xml</code> file, we can bundle different versions of the file with different deployments.</p>
<h1>Handling Invalid Items</h1>
<p>Continuing the example, invalid items are sent to the <code>ItemErrorHandler</code> as they are discovered.</p>
<pre name="code" class="java">
public interface ItemErrorHandler {
    void handleItem(Item item);
}
</pre>
<p>Let&#8217;s start by implementing a fake handler that saves the item details to a file. We want to open the file before we start handling items, leave it open for the duration of the process as we add content to the file, and then close the file when we are done with our processing. We could manually add <code>initProcess()</code> and <code>finishProcess()</code> methods to the error reporter bean, but then we couldn&#8217;t code to the interface since the caller would need to know about those class specific methods. We could add those same methods to the <code>ItemErrorReporter</code> interface but then we would have to unnecessarily implement those methods in every class that implements that interface. Instead, we can use some of the lifecycle annotations from the Managed Bean spec to call methods on the bean at certain points in the bean lifecycle. A <code>PostConstruct</code> annotated method is called when the bean has been constructed and any dependencies the bean has have been injected. Likewise, a <code>PreDestroy</code> annotated method is called just before the bean is disposed of by the container.</p>
<pre class="brush: java;">
public class FileErrorReporter implements ItemErrorHandler {

    @PostConstruct
    public void init() {
        System.out.println(&quot;Creating file error reporter&quot;);
    }

 @PreDestroy
    public void release() {
        System.out.println(&quot;Closing file error reporter&quot;);
    }

    public void handleItem(Item item) {
        System.out.println(&quot;Saving &quot;+item+&quot; to file&quot;);
    }
}
</pre>
<p>Our final change is to add the item error handling into our <code>ItemProcessor</code> bean.</p>
<pre class="brush: java;">
@Named(&quot;itemProcessor&quot;)
@RequestScoped
public class ItemProcessor {

    @Inject @Demo
    private ItemDao itemDao;

    @Inject
    private ItemValidator itemValidator;

    @Inject
    private ItemErrorHandler itemErrorHandler;

    public void execute() {
      List&lt;Item&gt;  items = itemDao.fetchItems();
      for (Item item : items) {
          if (!itemValidator.isValid(item)) {
              itemErrorHandler.handleItem(item);
          }
      }
    }
}
</pre>
<p>When we run this from our browser we see the following in the console ;</p>
<pre class="brush: plain;">
INFO: Creating file error reporter
INFO: Saving eedemo.Item@d8b01e [Value=34, Limit=7] to file
INFO: Saving eedemo.Item@12a5e8 [Value=89, Limit=32] to file
INFO: Closing file error reporter
</pre>
<h1>Next Time</h1>
<p>Different application deployments might use different rules for handling invalid items. such as rejecting the item, to sending notifications to individuals or just flagging them or listing them in an output file. In addition, we may want to do a combination of these (reject an order, send email to the sales rep, and list it in a file).<br />
One great way to handle this kind of multi-faceted problem is using events which we&#8217;ll look at next time.</p>
<p>Click to view <a href="http://www.andygibson.net/blog/tutorial/getting-started-with-jsf-2-0-and-cdi-part-3/">getting started with jsf 2.0 and CDI part 3</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.andygibson.net/blog/tutorial/getting-started-with-cdi-part-2-injection/feed/</wfw:commentRss>
		<slash:comments>29</slash:comments>
		</item>
		<item>
		<title>Getting Started with JSF 2.0 and CDI in JEE 6 part 1</title>
		<link>http://www.andygibson.net/blog/tutorial/getting-started-with-jsf-2-0-and-cdi-in-jee-6-part-1/</link>
		<comments>http://www.andygibson.net/blog/tutorial/getting-started-with-jsf-2-0-and-cdi-in-jee-6-part-1/#comments</comments>
		<pubDate>Wed, 16 Dec 2009 14:20:03 +0000</pubDate>
		<dc:creator>Andy Gibson</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[CDI]]></category>
		<category><![CDATA[EJB]]></category>
		<category><![CDATA[JEE]]></category>
		<category><![CDATA[JSF]]></category>
		<category><![CDATA[Netbeans]]></category>
		<category><![CDATA[Weld]]></category>

		<guid isPermaLink="false">http://www.andygibson.net/blog/?p=647</guid>
		<description><![CDATA[Here&#8217;s a quick tutorial on how easy it is to get started with JSF 2.0 and JSR 299, Java Contexts and Dependency Inject (CDI) using the latest release of Netbeans 6.8. Read Part 1 Read Part 2 Read Part 3 Getting Netbeans and JEE6 First download the latest version of Netbeans (at the time of [...]]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s a quick tutorial on how easy it is to get started with JSF 2.0 and JSR 299, Java Contexts and Dependency Inject (CDI) using the latest release of Netbeans 6.8.<br />
<span id="more-647"></span><br />
Read <a href="http://www.andygibson.net/blog/tutorial/getting-started-with-jsf-2-0-and-cdi-in-jee-6-part-1/">Part 1</a><br />
Read <a href="http://www.andygibson.net/blog/tutorial/getting-started-with-cdi-part-2-injection/">Part 2</a><br />
Read <a href="http://www.andygibson.net/blog/tutorial/getting-started-with-jsf-2-0-and-cdi-part-3/">Part 3</a></p>
<h1>Getting Netbeans and JEE6</h1>
<p>First download the latest version of Netbeans (at the time of writing 6.8 has just been released). Make sure the download version you choose includes Glassfish V3 and java web and EE. Once downloaded, install it and get it up and running and we can start writing the application.</p>
<h1>Starting the Project</h1>
<p>Once Netbeans is up and running, start a new web project by clicking New Project and select the Java Web category and select a Web Application project and click next.</p>
<p>Give the new project a name (I called mine ee6demo) and a directory and click next. On the server settings, Glassfish v3 should already be selected so select next. In this tab, make sure Java Server Faces is selected and stick with the defaults in the lower panel that appears when you select it.</p>
<p>You can now click finish and Netbeans will create the project and open it up for you in the IDE. On the left you can see the project explorer and in the main tab you can see a file called index.html. Without doing anything, open the Run menu in the main menu and select &#8220;Run Main Project&#8221;. After a moment of activity and console logging a web browser window should open up with the message &#8220;Hello From Facelets&#8221; which is exactly what we can see in the index.xhtml file. So far, we haven&#8217;t done anything and we already have a working web application shell.</p>
<p>Just take a moment and look at the tabs on the left hand side, you should see Project,Files, and Services. Click on the services tab and expand the Servers node and you should see the Glassfish server we are using with a little green arrow on it indicating that the server is running. For now, we don&#8217;t need this because we aren&#8217;t actually going to deploy to the server again, no restarts and no manual deployments, so go back to the projects tab on the left.</p>
<h1>Adding some code</h1>
<p>In the projects tab, expand the &#8220;Source Packages&#8221; node and right click and select New->Java Class. Give the class the name <code>MessageServerBean</code> and a package name (I used <code>eedemo</code>). We annotate the class with the <code>javax.inject.Named</code> annotation and a single method to return a string.</p>
<pre class="brush: java;">
package eedemo;

import javax.inject.Named;

@Named
public class MessageServerBean {

    public String getMessage() {
        return &quot;Hello World!&quot;;
    }
}
</pre>
<p>This a managed bean as defined by CDI which in Glassfish v3 is implemented using Weld from JBoss. One thing we need to do now is tell the server that this project is a module containing CDI beans. We add a file called <code>beans.xml</code> to the project in the WEB-INF folder. Right click on the WEB-INF folder in the project manager in the ee6Demo/Web Pages/folder and select New->XML Document. In the file name editor, just call it <code>beans</code>, <b>not</b> <code>beans.xml</code> as the IDE will add the xml extension for you and if you add the xml extension, the file will be called <code>beans.xml.xml</code> (I&#8217;ve often tripped myself up with that one!). Open the beans.xml file in the editor, and select all the text and delete it so it is an empty file.  You could alternatively just put <code><beans></beans></code>. (<b>Note</b> This file can be used to specify bean related information in xml so you aren&#8217;t limited to annotations)</p>
<p>The last change is to edit the <code>index.xhtml</code> and replace the &#8220;Hello From Facelets&#8221; with our own text.</p>
<pre class="brush: xml;">
        Message is : #{messageServerBean.message}&lt;br/&gt;
        Message Server Bean is : #{messageServerBean}
</pre>
<p>Save it and go to your browser and refresh the page (<code><a href="http://localhost:8080/ee6demo/">http://localhost:8080/ee6demo/</a></code>). </p>
<p>Message is : Hello World!<br />
Message Server Bean is : eedemo.MessageServerBean@xxxxxxx </p>
<p>You should now see the message from the bean displayed on the page. Now go back into your message bean and change the message to something else (I used <code>Hello From Weld!</code>), save the file and then refresh the browser. Your new message appears automatically since your application code has been hot deployed automatically by Netbeans . If you don&#8217;t see your changes just give it a second and refresh again.</p>
<p>From the second line in our page you can see that the class name is <code>eedemo.MessageServerBean</code> and the bean is just a pojo. Even though this is JEE, there is no complex class hierarchy wrapped in layers of transactions, interceptors and all that &#8216;Heavy&#8217; stuff you keep hearing about. </p>
<h1>What&#8217;s going on?</h1>
<p>When the application is deployed, the presence of a <code>beans.xml</code> file signals that this module contains CDI managed beans so the classes on the path are scanned for CDI annotations. Our bean was annotated with the <code>@Named</code> annotation and so this class was registered with Weld (under that name) (<b>edit</b> in a CDI module, all beans are registered with Weld, the named annotation is just used to match beans to injection points). When our JSF page was rendered, JSF tried to resolve the value of <code>messageServerBean</code> in the page using the registered expression resolvers in JSF. One of these is the Weld EL Resolver which has the MessageServerBean class registered under the name <code>messageServerBean</code>. We could have specified a name with the annotation, but since we didn&#8217;t it was registered under the default name of the class name with a lower case first name. The Weld resolver returns an instance of this bean in response to the request from JSF. Bean naming is only needed when using EL expressions and should not be used as the default mechanism for injection. CDI provides type safe injection by class type and stereotypes or qualifiers as we&#8217;ll see later.</p>
<h1>Upgrading to an EJB</h1>
<p>As we are using a JEE stack, we can easily deploy our bean as an EJB with some small changes thanks to EJB 3.1. Just open up the <code>MessageServerBean</code> and add the <code>javax.ejb.Stateless</code> annotation at the class level. Again, just save the file and go to your browser and refresh (no manual deploying, just save the file), and you should see something like :</p>
<p>Message is : Hello From Weld!<br />
Message Server Bean is : eedemo.__EJB31_Generated__MessageServerBean__Intf____Bean__@xxxxxxx </p>
<p>Amazingly, we turned our pojo bean into a fully featured EJB with just one annotation, we saved it, and refreshed our page and our changes appeared, we don&#8217;t have to create any weird project configurations, local interfaces or arcane deployment descriptors.  </p>
<h1>Different EJB types</h1>
<p>You can also try using the <code>@Stateful</code> annotation (don&#8217;t forget to implement the <code>java.io.Serializable</code> interface in the bean as it needs to be able to passivate (<b>edit</b> This isn&#8217;t necessary for it to be an EJB, but it is necessary if you want it to be session or conversation scoped)). Alternatively, you could try the new <code>@Singleton</code> annotation for singleton instances. If you do, you may notice that there is a <code>javax.ejb.Singleton</code> and <code>javax.inject.Singleton</code>. Why two Singleton annotations? A single annotation in CDI lets you define a singleton instance outside of EJB in case you are using CDI in a non-EJB environment. An EJB singleton will have all the features of an EJB such as transaction management so you have the choice depending on your needs and whether the environment is EJB or not.</p>
<p>In this first part, we have created a new JSF 2.0 application, made it CDI enabled and added a managed bean which we then referenced from the web page. In part 2, we&#8217;ll start looking at creating more complex beans and injecting them into and with other beans.</p>
<p>Click to view <a href="http://www.andygibson.net/blog/index.php/2009/12/22/getting-started-with-cdi-part-2-injection/">Part 2</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.andygibson.net/blog/tutorial/getting-started-with-jsf-2-0-and-cdi-in-jee-6-part-1/feed/</wfw:commentRss>
		<slash:comments>29</slash:comments>
		</item>
		<item>
		<title>Java EE 6 Is Here</title>
		<link>http://www.andygibson.net/blog/news/java-ee-6-is-here/</link>
		<comments>http://www.andygibson.net/blog/news/java-ee-6-is-here/#comments</comments>
		<pubDate>Fri, 11 Dec 2009 00:13:19 +0000</pubDate>
		<dc:creator>Andy Gibson</dc:creator>
				<category><![CDATA[News]]></category>
		<category><![CDATA[CDI]]></category>
		<category><![CDATA[EJB]]></category>
		<category><![CDATA[Glassfish]]></category>
		<category><![CDATA[JEE]]></category>
		<category><![CDATA[JPA]]></category>
		<category><![CDATA[JSF]]></category>
		<category><![CDATA[Netbeans]]></category>

		<guid isPermaLink="false">http://www.andygibson.net/blog/?p=689</guid>
		<description><![CDATA[Like Christmas come early, Sun announced the release of JEE 6. This release sees continued improvement in the JEE stack with the inclusion of JSR 299, Java Contexts and Dependency Injection (CDI), and EJB 3.1 as well as JSF 2.0, and JPA 2.0. JSF especially has seen changes as a result of practical user feedback [...]]]></description>
			<content:encoded><![CDATA[<p>Like Christmas come early, Sun <a href="http://www.sun.com/aboutsun/pr/2009-12/sunflash.20091210.1.xml">announced</a> the release of JEE 6. This release sees continued improvement in the JEE stack with the inclusion of JSR 299, Java Contexts and Dependency Injection (CDI), and EJB 3.1 as well as JSF 2.0, and JPA 2.0. JSF especially has seen changes as a result of practical user feedback and community add-ons such as Seam and JSF Ajax frameworks which have contributed back to the JCP.</p>
<p>Glassfish v3 which implements the full JEE 6 stack has also been released, with JBoss&#8217; Weld as the CDI implementation. Netbeans 6.8 has also been released with full JEE 6 project support including maven support for enterprise applications. Also of note is the hot deploy function of Glassfish which can deploy your app while maintaining session information.</p>
<p>Personally, I&#8217;m pleased. JEE 6 has really improved things for the java standards, and CDI has filled some gaps that previously required different additional pieces to completely fill. The ghosts of EJB 2.1 should now be permanently laid to rest, but should serve as a stark reminder. Having good frameworks to build standards based solutions is always good for the community.</p>
<p>I&#8217;ll try and get some tutorials on developing with CDI and JSF 2.0 with Netbeans and Glassfish out soon.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.andygibson.net/blog/news/java-ee-6-is-here/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Glassfish, Netbeans and JSF 2.0 Test Drive</title>
		<link>http://www.andygibson.net/blog/article/glassfish-netbeans-and-jsf-2-0-test-drive/</link>
		<comments>http://www.andygibson.net/blog/article/glassfish-netbeans-and-jsf-2-0-test-drive/#comments</comments>
		<pubDate>Tue, 03 Nov 2009 04:32:44 +0000</pubDate>
		<dc:creator>Andy Gibson</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[EJB]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[JPA]]></category>
		<category><![CDATA[JSF]]></category>
		<category><![CDATA[Maven]]></category>
		<category><![CDATA[Netbeans]]></category>
		<category><![CDATA[Seam]]></category>

		<guid isPermaLink="false">http://www.andygibson.net/blog/?p=611</guid>
		<description><![CDATA[I&#8217;ve spent some time in the last couple of weeks playing around with Glassfish, Netbeans 6.8 Beta (and milestone 2 before it) and JSF 2.0, and I have to say that this is turning out to be a really good set of development libraries and tools. (note This post relates to both the milestone 2 [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve spent some time in the last couple of weeks playing around with Glassfish, Netbeans 6.8 Beta (and milestone 2 before it) and JSF 2.0, and I have to say that this is turning out to be a really good set of development libraries and tools.<br />
<span id="more-611"></span></p>
<p>(<b>note</b> This post relates to both the milestone 2 and beta versions of Netbeans 6.8 which I have been tinkering with over the duration of this article being written.)</p>
<p>The <a href="http://www.netbeans.org/community/releases/68/">download for Netbeans 6.8 </a> comes with <a href="https://glassfish.dev.java.net/">Glassfish v3 </a> which implements JEE 6 including <a href="http://jcp.org/en/jsr/detail?id=314">JSF 2.0</a> and <a href="http://jcp.org/en/jsr/detail?id=317">JPA 2.0</a>.</p>
<p>Glassfish now has <b>really</b> fast hot deployment so you can change a line of code, save it, and it re-deploys instantly which in my opinion, this is a huge productivity booster. This isn&#8217;t limited to Netbeans, the eclipse plugins also provide this feature, and it works with pretty much any framework. I tried it with Wicket and Spring MVC and it was fantastic to get a wicket error where I had forgotten to add a component, so I go back to the java page code, add the component, refresh my browser and it works. Glassfish now has support for JEE 6 so you can make a pojo a local EJB just by adding the <code>@stateless</code> annotation to it. You can also deploy EJBs in war files as well without needing the whole EAR setup. One problem I did see was that when you used the EAR project setup with an EJB and War project, the hot deploy didn&#8217;t appear to work as well. Changes to the war file didn&#8217;t appear to redeploy, maybe because it is the EAR file that is deployed and not the war. However, still fantastic stuff.</p>
<p>Netbeans 6.8 beta was released in the last week or so. Feature-wise it is a great product with better tooling for JSF, including JSF 2.0, facelets support, and auto-completion for JSF backing beans in the JSF page. It also includes support for JEE 6, EJB 3.1, JPA 2.0 and development with Glassfish v3. It also improves upon the existing Maven support by providing for mavenized Ear projects. </p>
<p>While the features are impressive, Netbeans still seems hindered by performance issues and some minor bugs (although it is a milestone/beta release). Personally, I found this release no more sluggish that other releases although some people in the forums have had worse experiences. Netbeans strength has always been that it offers one standard solution without the plugin nightmares that eclipse has. While Netbeans has plugins they are more like installable features, they have a higher granularity than Eclipse plugins which is more like DLL hell. That said, I use Eclipse at work and it is always hard to shift from one keyboard mapping to another, and Eclipse does seem faster without the intermittent pauses. However, right now, Netbeans is a superior product in terms of features, especially for a JSF developer. I&#8217;d keep an eye out for the 6.8 final release to see how it comes out, and give 6.8 milestone 2 a go just to enjoy the experience if you are interested in using a standards based stack because thats obviously where the Netbeans folks are focused. </p>
<p>One big issue I have with Netbeans is the oddness of some of the key mappings. I think in nearly every application I use I press Alt+F and then C to close the currently edited document. Whether is it in MS Office, Borland Delphi, Eclipse, Firefox, while in the file menu, the C key always closes the currently open document you are editing. In Netbeans, it closes the currently edited project which means suddenly my project disappears when I want to close an edited file. Another is the use of Ctrl+Space for invoking auto completion which in Netbeans sends focus to the project manager or something like that. Sure, I can change the keymappings, such as to the Eclipse profile, but then I&#8217;m using some arbitrary weird key mapping which isn&#8217;t Netbeans and it isn&#8217;t completely the same as Eclipse. It is probably this way for legacy reasons, but some of these key presses are de facto standards.</p>
<p>Lastly, we come to JSF 2.0 which was forged from JSF 1.2 and the litany of complaints about it. The JSR group looked at the solutions out in the wild that already work around those problems (many of which were written by people in that very group) and incorporates those fixes in a standard JSF API type of way. Primarily we have the dropping of JSP as the default view in exchange for the Facelets / JSF templating solution. This also lent itself very well to easier component creation including no-code components. There is now zero configuration required except for the servlet in <code>web.xml</code> and managed beans can now be defined using annotations. Navigation which also used to be in the <code>faces-config.xml</code> is also more convention of configuration. Another big request was the inclusion of AJAX awareness in the JSF lifecycle . It provides the bare minimum features that 3rd party developers can build upon using the standard API instead of their own AJAX solutions. There is better support for GET requests and page parameters as well as invoking actions on page requests which is a feature often used in Seam.<br />
There is also some performance boosts with regards to re-working state saving and the resource access mechanisms have been improved a great deal.</p>
<p>Also noteworthy is the inclusion of <a href="http://www.seamframework.org/Weld">Weld CR 1</a> which is the reference implementation of <a href="http://jcp.org/en/jsr/detail?id=299"> JSR 299 &#8211; Java Contexts and Dependency Injection </a> from JBoss. Admittedly, I haven&#8217;t really gotten round to taking a look at it, but from what I have seen and read so far, it looks like it fills some gaps in the JEE 6 platform and is up to par with the new found simplicity and strength that JEE 6 is promoting right now.</p>
<p>Overall, this is a pretty exciting set of tools and framworks and well worth a look if you are interested in adopting a standards based stack. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.andygibson.net/blog/article/glassfish-netbeans-and-jsf-2-0-test-drive/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

