JSF-EJB

Getting Started with JSF2-EJB3

How to Create a simple Java EE 6 Application with JSF 2, EJB3  in Eclipse and JBOSS As 7.1

Prerequisites

Before performing this project, you need to meet the following prerequisites about the projectEJB https://achrefo.wordpress.com/ejb-with-jboss-in-eclipse-luna/

Create Project Dynamic Web Project

Start by creating a new Dynamic Web Project, selecting as Target Runtime your JBoss AS 7 distribution. Click Next.

1

Generete web.xml and Click Finish.

2.1add JSF to our Project :

2.2

Select JSF and click OK.3

Next, add the single Web page named product.xhtml

4

Select the template strict and click Finish

5

add taglig JSF : press ctrl+space to show the HTML tag proposals.

6add Product

addproduct

list Product

listproduct

Now let’s add the manager JSF Bean which acts as a layer between the Web page and the EJB:

Since JSF 2.0 you can register your Managed Beans via annotations, this means that is not necessary anymore to use the faces-config.xml to define your beans.

Create class named ProductMB :

-add @ManagedBean  must import javax.faces.beasn and add name must be a the same name in product.xhtml

-add @RequestScoped  must import javax.faces.beasn

12In our class we need to creat field IProductLocal in the interface of the project EJB

12

to fix this issus, we need to add the prject EJB in the propriety of JSFProject.

14.1

Create two method addProduct and getListProducts

MB

Generate Getters and Setters getterandsetter

To run the project we neeed to create new EAR Application Project to deploy both the EJB Project and the JSFProject.

Create new Prpject

EARSelect EJB and JSF Project.

EAR2

Run the Project EAR as Jboss Server :

runproject

viewCreate simple CSS to our project :

css2create file style.css in the folder webContent.

css3add the css in the file html.

css4FullPublish the Project: you should see the following :

css5
Fine, your project is completed and should look like this in your Project Explorer window:

pEnjoy it 🙂

Leave a comment