Full Web Application with Tomcat JSF Primefaces JPA Hibernate

90

Posted on June 21, 2012 by

Share it now!

Hello, how are you?

We are happy for the 100k visitors. To celebrate this mark in this blog we created this post that will show how to create a full web application using the following tools: Tomcat7, JSF2 (Facelets and Libraries) with Primefaces (with AutoComplete), JPA / Hibernate (with a relationship NxN), Login with Filter.

If you want to see a full web application with JSF + EJB + JPA + JBoss 7 click here.

To run the code of this post you will need the artifacts bellow (all jar file you will find in the last page of this post):

You can use the any database you want, you will need the specific driver of the database and to edit the URL connection at the persistence.xml.

At the end of this post you will find the source code with all needed libraries to download.

What you will see today in this post:

  • Page 02: Entity classes of the model. A relationship NxN (@ManyToMany), NamedQueries with JoinFetch, Enum as attribute.
  • Page 03: Generic DAO, application transaction methods, generic methods to populate query parameters.
  • Page 04: Façades an transactions, using the method findReferenceOnly, care using the entityManager.merge() method.
  • Page 05: Filters.
  • Page 06: ManagedBeans. How to inject a ManagedBean inside another ManagedBean, observations about @ViewScoped.
  • Page 07: JSFMessageUtil.
  • Page 08: Configurations file: log4j.properties, messages.properties.
  • Page 09: xhtml pages, Facelets.
  • Page 10: Primefaces AutoComplete, JSF Converter with “forClass”.
  • Page 11: Easiest way to use CSS/javascript/images with JSF.
  • Page 12: “web.xml” configurations.
  • Page 13: Increasing the security of your application.
  • Page 14: Running the application.

The application that you will find in here will have a Dog and Person CRUD (Create, Read, Update, and Delete); only the ADMIN will have access to the Dog CRUD. Before you run this application you should create a database named “JSFCrudDB”.

Response to Full Web Application with Tomcat JSF Primefaces JPA Hibernate

1 3 4 5
  1. Joel Mestres

    hello again, in your facade you make a new instance of DAO, besides you begin transaction on facade… both things are not good choice, aren’t them?
    I got understood that you have to manage transaction on DAO’s … and facade is just a conector between to layers… what do you think? thanks for yor answer!

    • uaihebert Post author

      Hello Joel.

      If you want it, you could create the transaction in the Facade as well, but you will have to sync in the DAO with the current transaction.

      I just used it in the DAO because this is a simple project, but if a transaction must go on between DAOS it would be better let the Facade handle the transaction.

      Thanks for passing by.

  2. Joel Mestres

    hi thansk for great full example. How can I change db provider for this? I try changing parameters in persistence.xml but result is “unable to find default provider” thanks for your help!

    • uaihebert Post author

      Hello Joel, how are you?

      In the pages of this posts it is displayed where you should change to have a different db provider for the project.

      Thanks for passing by.

  3. Hanan Ahmed

    Thanks for great tutorial, i had a small question here is the only purpose for hibernate in your tutorial is to generate the schema in other words as you are already use JPA 2 can i do without hibernate and use EclipseLink to generate my schema?

  4. Chris Georgoulis

    Hello Hebert,

    Very nice and detailed tutorial. It gave me a lot of nice ideas to improve my own web apps.
    I just have one comment:

    The Persons-Dogs are a @ManyToMany relationships. I see that when removing either dogs or persons you do not remove the other side of the relationship.

    For example a Person has many dogs. Shouldnt before you remove the person, search all the dogs(dogList) and remove the person from them(so basically updating them) – then finally remove the person himself? Shouldnt this be done in order for the bi-directional relationship to be synchronized?

    Thank you in advance,
    Chris.

    • uaihebert Post author

      Hello Chris, good afternoon.

      Indeed your should remove the reference of the entities. I found some other problems in the codes above, like, I forgot to add the mappedBy in the relationship also… -_-”

      Thanks for the feedback. Right now I cannot edit it, but I will do it later.

      I am sorry for the late response, I am very busy these days.

1 3 4 5

Leave a Reply

Your email address will not be published. Required fields are marked *


*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Current day month ye@r *