Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

JSF2 - Helloworld annotations not working on Tomcat7  RSS feed

 
R Kintali
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Guys,

I wanted to build a simple hello world app with JSF 2.

Below is what I did for this.

1) created maven web app in eclipse
2) Added JSF2 maven dependency (2.2.4) and tomcat7 plugin in pom.xml
3) Updated web.xml config to redirect to a xhtml page based on url pattern
4) Created session scoped managed bean (with annotation) and a simple getter / setter in it.
5) Created xhtml that has binding to the message from the above managed bean.

I then built war with 'clean install tomcat7:run'. This created war file and the app is available at http://localhost:8080/jsf-prac

When I hit this URL, the annotation based managed bean is not initiated at all. Thus, the message from managed bean is not displayed on screen.

Please find the hello world web app here - https://github.com/rkintali/jsf-prac.git

Could you please advise why the managed bean is not initiated?

Upon googling, I noticed here that @ManagedBean of Mojarra 2.1.0 doesn't work on Tomcat. Hence used version 2.2.4, but still no luck. Do you have any idea?

Kind regards,
Guru
 
Tim Holloway
Bartender
Posts: 18709
71
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Apparently you are referencing a broken copy of JSF.

Here are the POM settings I'm using on a project that runs on Tomcat 7. They're fairly old (JSF 2.0, not 2.2) but for "HelloWorld", they should work:


The Managed Bean should be instantiated when it is first referenced (when the Faces Servlet intially constructs the page from the xhtml for that URL).
 
R Kintali
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

The dependencies in your POM are not present anymore in maven central repository.

Could you please share the working copy of hello world app (on Tomcat7) if you have?

Kind regards,
 
Tim Holloway
Bartender
Posts: 18709
71
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That is working on Tomcat 7. But you are correct, whatever Maven repository I pulled them from doesn't seem to have them anymore. They're cached in my local maven repo.

Instead of version 2.0.2-FCS, try simple version 2.0 and see if that doesn't build.
 
R Kintali
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Just figured out that it may work when this war is built and deployed to Tomcat server. However, I am using embedded tomcat with maven(tomcat7:run). The problem with this is that the dependant jar files are not placed in WEB-INF/lib as the war is not assembled and JSF2 scans this folder to process the annotations.

Is there any configuration that I need to add in pom.xml to make the JSF2 annotations resolved in Tomcat 7 embedded server?
 
R Kintali
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
tomcat7:run-war works but I don't want to use this as any changes in the source files won't be reflected immediately unless we re-build the war. Is there any alternative ?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!