Full Web Application with Tomcat JSF Primefaces JPA Hibernate

96

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. Vinh

    Hello Hebert,
    This’s a great tutorial. Can you please keep it-up-date with latest version of PrimeFaces 5 + JSF 2.2 + Tomcat 8?
    And I’m looking for a practical tutorial on implementing pagination in a JSF Page for my project.
    Thank you very much for a great tutorial.

    • uaihebert Post author

      Hello Vinh,

      I cannot do it right now. This post is huge and it is not easy to edit it.

      I am planning on creating a new version of this post, but it will not be until the end of this year.

      Thanks for passing by.

  2. huynv

    dear sir,
    you can teach me build webapp jsf primeface with Hibernate ?
    i need your help .
    i follow your sample but have problem when make entity relationship user ,role ,permission

    I’ m very grateful for your help

    • uaihebert Post author

      Hello huynv, how are you?

      You can download the sample here and see the code.

      I know that the code of this post works.

      Thanks for passing by.

  3. Kyon

    Nice work! Thank you for share it.

    I have a question.. What should i do if i wanna make the create person with that autocomplete combo? So, once i want to create a person, i have to choose 1 dog already created.

    • uaihebert Post author

      Hello Kyon,

      thanks for the support.

      You could use the Primefaces component named autocomplete. [=

      Thanks for passing by.

  4. 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.

  5. 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.

  6. 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?

  7. 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 *