One suite of JSF components to rule them all

Sun Microsystems and ICESoft put a joined effort to back one single JSF component suite. It looks like that Sun realised that re-use and cooperation is another key of a successful business so they are trying to spent less resources on things that are already available in the community by providing some level of support and funding instead of starting the same suite from the scratch.

Sun abandoned further development and support of WoodStock components set which was the primary set of components in the NetBeans IDE visual web development project. And instead they put some effort together with ICESoft to provides a migration path from WoodStock suite to ICESoft component suite.

Although I like WoodStock compoents suite but the move is much more promising than development of the woodstock project in long term as there are more man power behind the ICESoft component set as from now that what was behind the WoodStock project.

ICESoft which is a long term provider and developer of JSF components has a NetBeans module which let developers simply use the ICEFaces components in their projects. New version of the module support working on projects with both ICEFaces and WoodStock components.

There is a comparison matrix between between the two component suite and promising roadmap which you can consult.

 

Four open source Java application servers compared

I was looking at feeds that my email client fetched during the day and I find am interesting one which lead me to an article written by Jonathan Campbell. Article can be found at http://www.javaworld.com/javaworld/jw-12-2007/jw-12-appservers.html

Jonathan compared 3 different application server/ servlet container by thier support of Java EE 5 and some other factors. article explained about each feature that he compared application servers based on it. Jonathan did not included GlassFish in his review of "open source Java application servers" and only included 3 application servers/ Servlet containers including Tomcat, Jboss and Geronimo. :-), So I thought I should include some facts here in order to make the comparison fair to all parties.

Including Glassfish into Jonathan matrix will give us the following table: *Notice*

Feature

JBoss 4.2

Geronimo 2

Tomcat 6

GlassFish 2

Java EE 5 compliance

Partial

Yes

No

Yes

EJB 3.0 capable

Yes

Yes

Available

Yes

JSP 2.1 and 2.5 capable

Yes

Yes

Yes

Yes

JavaServer Faces 1.2 support

Yes

Yes

Available

Yes

Custom plug-in support

Yes

Yes

No

?

Business-rules engine support

Available

Available

Available

Available

Hibernate 3.x support

Yes

Available

Available

Yes, based on below description

JBoss Seam support

Yes

Yes

Available

Yes

Clustering support

Yes

Yes

Partial

Yes

Eclipse IDE connector support

Yes

Yes

Yes

Yes

 

Following descriptions further explain some of what Glassfish can provides in relation of the above table

  • GlassFish fully support Java EE 5 with all its related JSRs like JSP 2.1 (JSR 245), Servlet 2.5(154), EJB 3.0(JSR 245), etc.
  • GlassFish support clustering and cluster management out of the box, a cluster can be configured from both CLI and Administration console.
  • GlassFish administration console allows you to configure your load balancer :-), for example you can configure a Sun Java Web Server which works as load balancer to add or add/ remove an instance from its list of servers, either manually or automatically if a new node joined the cluster or removed from the cluster
  • GlassFish allows you to manage resources for entire cluster at once instead of applying them for each instance, for example you can deploy a web application into a cluster of 10 instances instead of deploying it seperately for each instance.
  • GlassFish has a very wide array documentation both from Sun Microsystems (for free) and from GlassFish community.
  • GlassFish installation is as easy as executing 2 commands.
  • Deploying applications into GlassFish or even an entire cluster of glassfish instances is just 2 clicks away.
  • Quality of GlassFish components is out of any question, Metro is well known for supporting new WS-* standards, EJB support uses Toplink Essentials, MQ server is Sun open sourced MQ, etc.
  • GlassFish has very good interoperability with some other open source projects like, OpenESB and OpenSSO which allows you to have what you need to kick start your J2EE application without looking at any additional configuration.
  • Certainly performance is something which everyone should have in mind before considering other feaures, take a look at http://www.spec.org/jAppServer2004/results/res2007q3/jAppServer2004-20070703-00073.html and http://weblogs.java.net/blog/sdo/archive/2007/07/sjsas_91_glassf.html to find out more about how much capable GlassFish is.
  • GlassFish has connectors for both Eclipse and Netbeans, although other mentioned servers have a connector in Netbeans and Eclipse.
  • Seam support is available from GlassFish 1 upward.
  • Business rule engine support is available from OpenESB project integration.
  • About hibernate support, I cannot understand whether Jonathan means to use Hibernate as a persistence provider or plainly as an ORM, by the way both of this ?features? are available for GlassFish users.
  • GlassFish has an Update center, which allows you to update your application server from a remote repository.
  • GlassFish runs on all mentioned platforms, from Windows to AIX (Glasdfish 2 update 1 runs on AIX) and there is no restriction for you to run it on your platform of choice.

Mentioned items are in relation to what orginal article tried to compare. GlassFish can be used by a ROR developer by its integration with first class ROR IDE (Netbeans 6), It can serve you VOIP and SIP requirement by means of sailfin,etc. Any user with any kind of requirement will find GlassFish a suitable application server.

Although Jonathan did not mentioned GlassFish directly, but he gives his opinion by writing:In my experience commercial application servers have more bugs than the open source servers compared in this article, and they are more difficult to install. Deployment can also be an issue — at least with the recent version of Sun’s Java Application Server. The article co
uld be more complete if Jonathan included GlassFish in his comparsion chart and at then end he could write that GlassFish has problematic deployment procedure

 

An statement which looks odd to me is: In my experience commercial application servers have more bugs than the open source servers compared in this article, and they are more difficult to install., Althogh it will be a complex procedure to setup a Cluser of Websphere (as a commercial application servers ) using websphere XD, Object Grid, and other available packages that faciliate enterprise scale deployment of Websphere, but WebSphere has a decent performance and reliability which is very hard to deny.

Notice: Some parts of this table taken from Jonathan Campbell article published by javaworld and is available at http://www.javaworld.com/javaworld/jw-12-2007/jw-12-appservers.html

Develop web application with netbeans ,seam and Glassfish

In this two part series I will try to show you how easily you can  build applications using NetBeans 5.5 based on  seam , facelets , jsf and new EJB 3 standard.

I will not discuss any of framework in details as you can find detailed information about each of them in their homepage and some other articles.
I want just show , How you can use NetBeans with some leading frameworks to build your web based applications. I will not discuss NetBeans specific tasks in details .
I will more focus on leveraging this stuff together using NetBeans IDE.

What you will need to follow  this series :

  • NetBeans enterprise edition 5.5 , you will need Glassfish or JBoss to continue with this series. check and make sure that your NetBeans has application server bundled otherwise get a copy of glassfish from its website.
  • seam 1.0.1 GA  or newer.

seam distribution contain Facelets too , but i strongly suggest you get Facelets distribution separately and take a look at its samples and very good documentation. indeed both Facelets and seam has very good documentation.

In this entry I will introduce each of this frameworks in very brief  to make the series stand alone , and i will show you how to setup the development environment and we will go with first part which is developing seam layer codes.

JBoss seam is created to leverage maximum possible feature of Java EE 5 standards like JSF and EJB3.
seam , seamlessly integrate EJB3 as a backend with JSF as presentation , meanwhile provide management of long running process
by using JBPM . and give you ability to focus on your business logic rather than silly data providing stuff. By leveraging Facelets helps you to do even more with seam and JSF.

To name its features I can say:

  • Lesser XML, More Annotation. (please do not blame me for naming annotation and XML in one line :-))
  • it let you go with your business logic rather thinking and resolving some common issue like user conversation state.
  • seam has a more flexible context model , it has 8 context , by means of this context you can manage your application more effective. for example a business process live in business process context .
  • Accessing each component in entire seam context with one unique name.
  • Managing workplaces and conversations .
  • It easily will let you develop Portlet by providing a Portlet context . we will discuss this item in latter parts

With many more features.

But about JSF , JSF is  a web framework , it is  Standard and  Developed under JSR 127.
Some of JSF features are as follow:

  •  User interface framework
  •  Server-side UI components
  •  Event model , something like desktop applications event model , but very reduced.
  •  Component state
  •  Renderers , Render Kits , for example ADF faces has a telnet render which make it possible to render a ADF faces application for a  telnet client.
  •  Validation
  •  Type conversion
  •  Internationalization

about Facelets , we will discuss more in next articles , but for now you should know that Facelets bring some view related enhancement and features to JSF community .
To name some of features :

  • Facelets make it possible to develop your entire web pages using your favorite page designer like Dream weaver or Microsoft FrontPage. to achieve this feature it introduce a new attribute, jsfc ,that make it possible to change each html element  to a JSF equal component. it is similar to Tapestry ‘s jwcid attribute. So you can use all binding and event handling stuff of JSF and availability and ease of use of html WYSIWYG.
  • Facelets provide a template-ing  features like Velocity’s for JSF . it allows you to test JSF views out of container.
  • Some decoration features like what tile bring to struts community and SiteMesh ,generally, to all java based web application.

lets start the job of creating simplest sample 😉 .

I assume that you download seam and extract it in seam_home Also your NetBeans 5.5 is running and an application server capable of  containing ejb3 (Glassfish) is configured with your IDE.

for sake of simplicity we make one   Library in our NetBeans IDE to make our job easier. as you know each library could contain some jar files, etc…

Create a library name it seam and add the following jar files to it , the first
seam_homejboss-seam.jar
seam_homejboss-seam-ui.jar
seam_homehibernate-all.jar
seam_homethirdparty-all.jar

add seam library  to Registeration-EJBModule and Registeration-WebModule

Switch to runtime view (CTRL+5).Extend database node  , if you have no database created in your embedded derby  then create a database and create a table with following  characteristics
Table Name: users
Fields :

username

varcahr(255) , primary key

password

varchar(255) , not null

name

varcahr(255) , not null

after you create this table , create a new enterprise application project by going to , file>new project>enterprise application
name it Registeration. make sure that you have selected the Java EE 5 as j2ee version.

go to project view (CTRL+1) And select Registeration-ejbModule , right click on it and select CMP entity bean from database…
Now you should be able to select the JDBC connection that you have made in above step and give it a package name.
click next and select users table from left column and add it to right column.
click finish.
That’s it , you have your CMP ready to go.

  • what we need to add to the CMP bean class in addition to its created structure
  • another constructor with all the CMP  fields.
  • some annotation for getters , to help us in validation

final shape of users CMP will be like :

 


package cmps;

import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;

import org.hibernate.validator.Length;
import org.hibernate.validator.NotNull;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Scope;
/**
 *
 * @author Masoud Kalali
 */
@Entity
@Name("user")
@Scope(org.jboss.seam.ScopeType.SESSION)
@Table(name="users")
public class Users implements Serializable{
   private static final long serialVersionUID = 1881413500711441951L;
    private String username;

    private String password;

    private String name;

    /** Creates a new instance of Users */
    public Users() {
    }


    public  Users(String name, String password, String username)
 {
this.name = name;
this.password = password;
this.username = username;
}

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = "username", nullable = false)
     @Length(min=5, max=15)
    public String getUsername() {
        return this.username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    @Column(name = "password", nullable = false)
     @Length(min=5, max=15)
    public String getPassword() {
        return this.password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    @Column(name = "name", nullable = false)
     @Length(min=5, max=15)
    public String getName() {
        return this.name;
    }

    public void setName(String name) {
        this.name = name;
    }

}

 

we are finished with our POJO EJB 🙂 , now lets go and handle web layer stuff , from now we are working with seam view layer and JSF , I will talk about Facelets later in other articles of this series.

as I said in sample scenario we have just one action , so we can use a  managed bean or plain java object or whatever that is useable here as action listener or use a stateless session bean (using session bean is what JBoss offer) so we will use a stateless session bean to implement our action listener , it will also helps you to see how an stateless session bean is implemented in java EE 5.
so create a session bean by using , file > new > session bean , now you can select session bean type to be stateless , and change the package name to be sbeans
click finish  , editor will open up and show you the stateless seasion bean class.   
change the class body , in a way that final class looks like :

import cmps.Users;
import java.util.List;

import javax.ejb.Stateless;
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import org.hibernate.validator.Valid;
import org.jboss.seam.annotations.Factory;


import org.jboss.seam.annotations.IfInvalid;
import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Outcome;
import org.jboss.seam.annotations.datamodel.DataModel;
import org.jboss.seam.core.FacesMessages;
import org.jboss.seam.ejb.SeamInterceptor;

@Stateless
@Name("")
public class ActionBean implements sbeans.ActionLocal
{

   @IfInvalid(outcome=Outcome.REDISPLAY)
   public String ()
   {
      List existing = em.createQuery("select username from User where username=:username")
         .setParameter("username", user.getUsername())
         .getResultList();
      if (existing.size()==0)
      {
         em.persist(user);
         return "success";
      }
      else
      {
         FacesMessages.instance().add("User #{user.username} already exists");
         return "success";
      }
   }

}

we will need to add same method signature to our session bean local interface , so add the method signature to ActionLocal class. it will looks like :

package sbeans;


/**
 * This is the business interface for Action enterprise bean.
 */
public interface ActionLocal {
      public String ();
}

now we are finished with the action , you may ask what are those annotation stuff in the session bean , so I should ask you to take a look at seam reference or wait until next part of this series. I should say that it is a very same version of seam sample that is implemented again in NetBeans IDE.
we are finished with EJBModule for now , lets take a look at what we will have in web module. first of all you need to add JSF framework to web module to do this , right click on web module and select properties , go to frameworks node and add JSF framework to the project. In web module we just have 2 JSF pages , one to , one to show the that s/he ed . Create following JSF files ,

register.jsp

same as seam sample register.jsp , used for registering purpose

registered.jsp

same as seam sample registered.jsp , used for showing the user that he/she is ed

we need to add some navigation case to our faces-config.xml , so extend web module note and under configuration files open the faces-config.xml we should add 4 navigation case to it , so right click inside the editor ,which show content of faces-config.xml, and select add navigation rule. a dialog will open , just fill the dialog as following table show

Rule From View

/register.jsp

Now right click in the editor and add 4 new navigation case , these cases will handle navigating from one view to another.

From View

From Outcome

To view

/register.jsp

success

registered.jsp

lets code with the register.jsp , open the register.jsp in your NetBeans editor change the content to :

<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
<%@ taglib prefix="s" uri="http://jboss.com/products/seam/taglib"%>
<html>
<head>
<title> New User</title>
</head>
<body>
<f:view>
<h:form>
<table border="0">
              <s:validateAll>
<tr>
<td>Username</td>
<td><h:inputText id="username" value="#{user.username}" required="true" /></td>
<td>      <h:message for="username"/>       </td>
</tr>
<tr>
<td>Real Name</td>
<td><h:inputText  id="name" value="#{user.name}" required="true" /></td>
<td>      <h:message for="name"/>       </td>
</tr>
<tr>
<td>Password</td>
<td><h:inputSecret id="password" value="#{user.password}"  required="true" /></td>
<td>      <h:message for="password"/>       </td>
</tr>
          </s:validateAll>
</table>
<h:messages globalOnly="true"/>
<h:commandButton type="submit" value="" action="#{.}"/>
</h:form>
</f:view>
</body>
</html>

No we need to create the registered.jsp which show that our user is registered. open the file in your editor and change its content to looks like :

<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
<html>
<head>
<title>Successfully ed New User</title>
</head>
<body>
<f:view>
Welcome, <h:outputText value="#{user.name}"/>,
you are successfully ed as <h:outputText value="#{user.username}"/>.
</f:view>
</body>
</html>

Now we are almost finished with JSf files , there are some changes that we should make in web.xml and faces-config.xml.first open web.xml and add the following lines to it.make sure the you add them directly inside <web-app> node.

 <context-param>
		<description>
		</description>
		<param-name>org.jboss.seam.core.init.jndiPattern</param-name>
		<param-value>java:comp/env/registration/#{ejbName}/local</param-value>
</context-param>

<listener>
	<listener-class>org.jboss.seam.servlet.SeamListener</listener-class>
</listener>

<ejb-local-ref>
	<ejb-ref-name>registration/RegisterActionBean/local</ejb-ref-name>
	<ejb-ref-type>Session</ejb-ref-type>
	<local>sbeans.RegisterActionLocal</local>
<	ejb-link>RegisterActionBean</ejb-link>
</ejb-local-ref>

Now open faces-config.xml and add the following lines to it.

<lifecycle> <phase-listener>org.jboss.seam.jsf.SeamPhaseListener</phase-listener> </lifecycle>

That’s it , you are finished creating your first seam sample in netbeans , lets execute the application and see the result. press f6 and wait until your browser opens , navigate to http://localhost:8080/Registration-WebModule/faces/register.jsp enter some information and then press register button.

You can check whether it applied or not by switching to runtime view and checking your Users table data . you can find complete explanation of jsp/java codes in Seam tutorial chapter 1 at : http://docs.jboss.com/seam/1.0.0.GA/reference/en/html/tutorial.html