How to start to develop your EJB3-JSF in your project

From IHEWiki

Jump to: navigation, search





Contents

Interesting preambule

If you have followed the last sections : " How to install an existing Gazelle Web application, and work safely on it ? " or "How to create a new Gazelle Web application ? ", you can now start to develop your code in your project. Your project will use Hibernate, Seam and the RichFaces.

You need to develop with precautions and follow instructions in this coming section. It is very important to write the Java5 EE annotations at the right location. Also, developers haven't the ability to write their own methods of accessing the database. It is necessary to use the abstraction layer already existing in Gazelle projects. This abstraction layer is managed by the Java5 EE annotations, more informations about annotations further, in examples.


Here is the implementation rule : A model class (EJB object, aka entity, POJO), is managed by the action classes (Business layer, aka ManagerBeans). This business layer will work to provide asked informations to the view (Presentation layer).


  • All EJB (model and action) will be contained in the EJB Modules which generate JAR archive to include in the EAR : (example SampleTF-ejb, Users-ejb or Systems-ejb)
  • All JSF (webpages) will be contained in the UI Modules which generate WAR archive to include in the EAR : (example SampleTF-ui)

To remind you the architecture of a Gazelle application, this page has been written for you.


How to start to develop your EJB3-JSF in your project ?

You have to perform these 3 steps to develop your application in order.

  • 1.Model : Create an entity
  • 2.Action : Create the EJB3 corresponding to the Business Layer
  • 3.View : Create your JSF webpages corresponding to the Presentation Layer


/!\ Detailed code (EJB3/JSF) is not described in this documentation because of code updates. So, we will refer in this section to freshly examples, available on the forge in our reference project. Thanks for understanding



1.Model : Create an entity

First, you have to develop a model class. It will be your entity : an object using an associated table in the database. During the JBoss deployment, the EJB3 code will create a table in your database, with the correct attributes and properties. An entity have to be declared in a EJB module (and not Web).

Step #1.a

You have to familiar yourself with the business requirements

Step #1.b

You have to design on a paper your database/table schema according to requirements

Step #1.c

Create a new java file in your path /ejbModule/net/ihe/gazelle/<module>/model

Step #1.d

To develop your model java class, you have to take a look on our reference code, this is the code syntax to use, and you have to observe it because this code is Gazelle friendly. This example of model class is on the Forge :

  • project : /SampleGazelle/SampleTF-ejb
  • path : /ejbModule/net/ihe/gazelle/tf/model/Domain.java

Attributes, tables properties are defined in the model class, using Java5 EE annotations (@table, @Column, @ManyToMany...)


2.Action : create the EJB corresponding to the Business Layer

This is one or several Bean Managers to manage your POJO. A Bean Manager contains all methods you need, to work on the datas before providing them to JSF.


Step #2.a

Create a new java file in your path /ejbModule/net/ihe/gazelle/<module>/action/

Step #2.b

To develop your action java class, you have to take a look on our reference code, this is the code syntax to use, and you have to observe it because this code is Gazelle friendly. This example of action class is on the Forge :

  • project : /SampleGazelle/SampleTF-ejb
  • path : /ejbModule/net/ihe/gazelle/tf/action/DomainManager.java

Step #2.c

You need to add here some interfaces. This is necessary because it allows to a server or a client to access and persist your EJB. Interfaces are available on the Forge :

  • path : /ejbModule/net/ihe/gazelle/tf/action/DomainManagerLocal.java
  • path : /ejbModule/net/ihe/gazelle/tf/action/DomainManagerRemote.java

Step #2.d

Create these two interfaces (java file) in your path /ejbModule/net/ihe/gazelle/<module>/action, corresponding to your EJB. Use the following syntax : "<object>ManagerLocal.java" and "<object>ManagerRemote.java"


3.View : Create your JSF webpages corresponding to the Presentation Layer

This is the JSF part, which will be our way to create our HTML pages. The JSF allow to retrieve our POJOs and to call action methods from the Business layer. File extension of these JSF is .xhtml.


Step #3.a

Create a new xhtml file in your path /WebContent/


Step #3.b

To develop your JSF, you have to take a look on our reference code, this is the code syntax to use, and you have to observe it because this code is Gazelle friendly. This JSF example is on the Forge :

  • project : /SampleGazelle/SampleTF-ejb
  • path : /WebContent/listDomains.xhtml

This last example will display a page with the list of the different Domains.

You could also take a look on following JSF which will edit your domain POJO :

  • path : /WebContent/editDomain.xhtml


4.Deploy and test the application in local development environment

Step #4.a

Deploy your project in JBoss Application Server. For that step, open a console, and from the workspace/<application_name>-ear directory, launch the ant commands in a console :

  • ant help
  • then follow instructions explaining how execute the targets clean, then all


Note : Ant has be installed (If it's not installed, see section Prerequisites - Developement Tools)

Step #4.b

Check that your table has been created in your database. Read the JBoss deployment logs.


Step #4.c

To populate this table, you will need create a sql importing file (import.sql), and to check it in into your archive to deploy (using the build.xml). Build.xml example is available on our reference project, and you have to do the same.


Step #4.d

Test your development in local environment, upon successfully tested, check in your codes.

Note: You may want to use debugger during testing. To use debugger, make sure start Jboss application server from IDE.

Step #4.e

Cooperate with other developer to solve the issue if the code does not work.


5.Deploy the application in production environment

Step #5.a

The administrator will check out all the codes from forge.


Step #5.b

Deploy your project in JBoss Application Server. For that step, open a console, and from the workspace/<application_name>-ear directory, launch the ant commands in a console :

  • ant help
  • then follow instructions explaining how execute the targets clean, then all


Note : Ant has be installed (If it's not installed, see section Prerequisites - Developement Tools)

Step #5.c

Check that your table has been created in your database. Read the JBoss deployment logs.


Using this document and the reference project SampleGazelle, you should have now basis to start your development of EJB3 and JSF. If not, please contact us to update this section.



Back to the Gazelle Developers Guide homepage.


Personal tools