Full WebApplication JSF EJB JPA JAAS

69

Posted on January 2, 2012 by

Share it now!

Hello, how are you?

This post will be the biggest so far in my blog! We will see a full web application. It will be done will the newest technologies (until today), but I will give some hints to show how to adapt this post to older technologies.

In the end of this post you will find the source code to download. You can use it as you wish. Just go to the last page and do the download. \o/

If you downloaded the code and did not understand something, in this post I will explain every detail found in the code. Just read the subject inside this post that you want.

I will list bellow the technologies that I will use in this post:

  • JSF 2.0 Mojarra – With ManagedBeans as RequestScope and SessionScope.
  • Message Internationalization – File that will have all the messages of our system; it will be easier to translate you pages.
  • Default CSS file that will be imported as a library.
  • EJB 3 – Our DAOs and Façades will be @Stateless.
  • Generic DAO – A generic DAO that will have the CRUD actions to make our life easier.
  • JPA 2 – To map our classes in the DB
  • JAAS – To control the login and the user access to the pages.
  • MVC – I will use this pattern with small modifications.
  • Postgres as database, but I will show how to set up your app to MySQL also.

I will not use TDD – JUnit to test our View/Model/Classes, but in the following link you can see a technique to use the JUnit to test your ManagedBeans: JUnit with HSQLDB, JPA and Hibernate.

Tools that we will use:

This post will have several pages; this first page is just to show the technical details of the post today.

I will not code to interface my model/DAO, just to save space. Remember that you should always code to interfaces (Design Pattern – Strategy).

Before you go to the next pages be sure that you installed the JBoss Tools and the JBoss 7 in this exactly order.

Response to Full WebApplication JSF EJB JPA JAAS

  1. uddy

    Great tuto but I’ve this errors can you help me.

    Thanks.!!

    15:33:23,897 INFO [org.jboss.modules] JBoss Modules version 1.1.1.GA
    15:33:24,186 INFO [org.jboss.msc] JBoss MSC version 1.0.2.GA
    15:33:24,256 INFO [org.jboss.as] JBAS015899: JBoss AS 7.1.1.Final “Brontes” starting
    15:33:25,084 ERROR [org.jboss.as.server] JBAS015956: Caught exception during boot: org.jboss.as.controller.persistence.ConfigurationPersistenceException: JBAS014676: Failed to parse configuration
    at org.jboss.as.controller.persistence.XmlConfigurationPersister.load(XmlConfigurationPersister.java:141) [jboss-as-controller-7.1.1.Final.jar:7.1.1.Final]
    at org.jboss.as.server.ServerService.boot(ServerService.java:266) [jboss-as-server-7.1.1.Final.jar:7.1.1.Final]
    at org.jboss.as.controller.AbstractControllerService$1.run(AbstractControllerService.java:155) [jboss-as-controller-7.1.1.Final.jar:7.1.1.Final]
    at java.lang.Thread.run(Thread.java:662) [rt.jar:1.6.0_26]
    Caused by: javax.xml.stream.XMLStreamException: com.ctc.wstx.exc.WstxParsingException: Duplicate attribute ‘use-java-context’.
    at [row,col {unknown-source}]: [105,154]
    at org.jboss.as.connector.subsystems.datasources.DataSourcesExtension$DataSourceSubsystemParser.readElement(DataSourcesExtension.java:784)
    at org.jboss.as.connector.subsystems.datasources.DataSourcesExtension$DataSourceSubsystemParser.readElement(DataSourcesExtension.java:333)
    at org.jboss.staxmapper.XMLMapperImpl.processNested(XMLMapperImpl.java:110) [staxmapper-1.1.0.Final.jar:1.1.0.Final]
    at org.jboss.staxmapper.XMLExtendedStreamReaderImpl.handleAny(XMLExtendedStreamReaderImpl.java:69) [staxmapper-1.1.0.Final.jar:1.1.0.Final]
    at org.jboss.as.server.parsing.StandaloneXml.parseServerProfile(StandaloneXml.java:894) [jboss-as-server-7.1.1.Final.jar:7.1.1.Final]
    at org.jboss.as.server.parsing.StandaloneXml.readServerElement_1_1(StandaloneXml.java:330) [jboss-as-server-7.1.1.Final.jar:7.1.1.Final]
    at org.jboss.as.server.parsing.StandaloneXml.readElement(StandaloneXml.java:127) [jboss-as-server-7.1.1.Final.jar:7.1.1.Final]
    at org.jboss.as.server.parsing.StandaloneXml.readElement(StandaloneXml.java:100) [jboss-as-server-7.1.1.Final.jar:7.1.1.Final]
    at org.jboss.staxmapper.XMLMapperImpl.processNested(XMLMapperImpl.java:110) [staxmapper-1.1.0.Final.jar:1.1.0.Final]
    at org.jboss.staxmapper.XMLMapperImpl.parseDocument(XMLMapperImpl.java:69) [staxmapper-1.1.0.Final.jar:1.1.0.Final]
    at org.jboss.as.controller.persistence.XmlConfigurationPersister.load(XmlConfigurationPersister.java:133) [jboss-as-controller-7.1.1.Final.jar:7.1.1.Final]
    … 3 more
    Caused by: com.ctc.wstx.exc.WstxParsingException: Duplicate attribute ‘use-java-context’.
    at [row,col {unknown-source}]: [105,154]
    at com.ctc.wstx.sr.StreamScanner.constructWfcException(StreamScanner.java:606)
    at com.ctc.wstx.sr.StreamScanner.throwParseError(StreamScanner.java:479)
    at com.ctc.wstx.sr.StreamScanner.throwParseError(StreamScanner.java:464)
    at com.ctc.wstx.sr.AttributeCollector.throwDupAttr(AttributeCollector.java:1143)
    at com.ctc.wstx.sr.AttributeCollector.resolveNamespaces(AttributeCollector.java:997)
    at com.ctc.wstx.sr.InputElementStack.resolveAndValidateElement(InputElementStack.java:498)
    at com.ctc.wstx.sr.BasicStreamReader.handleStartElem(BasicStreamReader.java:2942)
    at com.ctc.wstx.sr.BasicStreamReader.nextFromTree(BasicStreamReader.java:2802)
    at com.ctc.wstx.sr.BasicStreamReader.next(BasicStreamReader.java:1050)
    at com.ctc.wstx.sr.BasicStreamReader.nextTag(BasicStreamReader.java:1125)
    at org.jboss.staxmapper.XMLExtendedStreamReaderImpl.nextTag(XMLExtendedStreamReaderImpl.java:152) [staxmapper-1.1.0.Final.jar:1.1.0.Final]
    at org.jboss.as.connector.subsystems.datasources.DsParser.parseDataSources(DsParser.java:185)
    at org.jboss.as.connector.subsystems.datasources.DsParser.parse(DsParser.java:165)
    at org.jboss.as.connector.subsystems.datasources.DataSourcesExtension$DataSourceSubsystemParser.readElement(DataSourcesExtension.java:776)
    … 13 more

    15:33:25,114 FATAL [org.jboss.as.server] JBAS015957: Server boot has failed in an unrecoverable manner; exiting. See previous messages for details.
    15:33:25,137 INFO [org.jboss.as] JBAS015950: JBoss AS 7.1.1.Final “Brontes” stopped in 14ms

    • uaihebert Post author

      Hello uddy,

      It looks like you edited a xml with an error. Check the edited xml.

      Thanks for passing by. I am sorry for the late response, I was very busy this last month.

  2. WarKar

    Hello,

    You’ve created great tutorial, but I have problem with the last step – deploy CrudEAR project. This is the console output:


    20:57:07,839 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-8) MSC00001: Failed to start service jboss.deployment.subunit."CrudEAR.ear"."CrudJSF.war".INSTALL: org.jboss.msc.service.StartException in service jboss.deployment.subunit."CrudEAR.ear"."CrudJSF.war".INSTALL: Failed to process phase INSTALL of subdeployment "CrudJSF.war" of deployment "CrudEAR.ear"
    at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:121) [jboss-as-server-7.0.2.Final.jar:7.0.2.Final]
    at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1824) [jboss-msc-1.0.1.GA.jar:1.0.1.GA]
    at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1759) [jboss-msc-1.0.1.GA.jar:1.0.1.GA]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) [:1.7.0_45]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) [:1.7.0_45]
    at java.lang.Thread.run(Unknown Source) [:1.7.0_45]
    Caused by: org.jboss.as.server.deployment.DeploymentUnitProcessingException: No component found for type 'com.facade.UserFacade' with name null
    at org.jboss.as.ejb3.deployment.processors.EjbInjectionSource.getResourceValue(EjbInjectionSource.java:68)
    at org.jboss.as.ee.component.deployers.ModuleJndiBindingProcessor.addJndiBinding(ModuleJndiBindingProcessor.java:200)
    at org.jboss.as.ee.component.deployers.ModuleJndiBindingProcessor$1.handle(ModuleJndiBindingProcessor.java:168)
    at org.jboss.as.ee.component.ClassDescriptionTraversal.run(ClassDescriptionTraversal.java:52)
    at org.jboss.as.ee.component.deployers.ModuleJndiBindingProcessor.processClassConfigurations(ModuleJndiBindingProcessor.java:140)
    at org.jboss.as.ee.component.deployers.ModuleJndiBindingProcessor.deploy(ModuleJndiBindingProcessor.java:133)
    at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:115) [jboss-as-server-7.0.2.Final.jar:7.0.2.Final]
    ... 5 more

    Could you help me please, and explain what I did wrong?
    Kind regards,
    Karolina

  3. Pingback: Full Web App JSF – EJB – Hibernate Tutorial | snippetjournal

  4. Stefanie

    Hi,

    you’ve done a great job with this tutorial! It was a hell of a help for me starting with this topic!
    Nevertheless I found out that I had a problem with caching data:
    When creating a group and assining it to a user the information was stored in the database but not in cache. That results in wrong actions when trying to delete the group (it was not encountered that there is a user having this group). Restarting the application solved the problem as the cache was fresh but I wanted the cache to be refreshed as soon as I do any modifying action like insert, update or delete.

    Therefore I added the following code to my abstract class GenericDao (just used the update method – same has to be applied for save and delete method):

    @Override
    public E update(final E entity) {
    em.merge(entity);
    refresh(entity);
    return entity;
    }

    @Override
    public void refresh(E entity) {
    em.getEntityManagerFactory().getCache().evict(this.entityClass, entity);
    }

    What do you think about this solution? Maybe it is a help for anybody who is looking for the same problem I was :-)

    Greetings,
    Stefi

    • uaihebert Post author

      Stefanie, good morning.

      Thank you for the feedback.

      I cannot tell you if this is the best solution for the problem because I would need to understand every detail of what is going on.

      I appreciate your time in leaving the solution here to help others with the same kind of problem.

      Thank you!

  5. Ali

    Hello,

    Very nice tutorial! Thank You.
    I would ask as a beginner, I want to use Glassfish instead of JBoss. Is it possible and where must I make changes ?

    Regards,
    Ali

    • uaihebert Post author

      Hello Ali,

      Yes, you can use it with Glassfish but I do not have here the files that you should change.

      Sorry about that.

      Thanks for passing by and the support.

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 *