Examples: Java Server Faces
Hello Boss
My First JSF application, contains a home page, then you have to type a Emmanuel as user : helloBoss2-jsf.zipOnce installed on your localhost (port 8080), you can access it using this link: localhost:8080/helloboss2.0/
The interesting files are:
src/helloworld/helloBean.java
The bean responsible for the verification of usename (and no password yet).web/hello.xhtml
: contains the definition of the form and its links to the managed beansweb/response.xhtml
: This content is displayed once the user has been successfully logged in the system.
MyFaces and Tomahawk
This example can be downloaded in one big zip file: myFacesExample2.0.zip.Once installed and deployed on your localhost, it should be accessible under the following URL localhost:8080/myFaces2.0/ The following files are interesting:
build.xml
: the ant fileweb/WEB-INF/web.xml
: the web application description fileweb/menu.xhtml
: Contains the menu structure (contains jsfcommandLinks
, noa
links).web/hello.xhtml
: The first Helloworld.web/helloBoss.xhtml
: The form where a user writes his/her name.web/helloBoss2.xhtml
: The page displaying hello with the user"e;s name.src/mylib/HelloBean.java
: The corresponding Java Bean. It stores the name of the user.src/mylib/Messages.properties
: Contains a property file for all the texts that need to be displayed in the application. The content is loaded in a resource bundle used in the XHTMLs.web/list.xhtml
: displays a table using paging.src/mylib/DataBean.java
: Java Bean that creates an returns a list of Modulessrc/mylib/Module.java
: Java Bean that contains only one module. It is not a managed bean and will be used inside aDataBean
I18n
The complete example can be downloaded as a zip file: login-i18n2.0.zipOnce deployed on your server, you can test it at the following URL: localhost:8080/logini18n2.0/ The interesting files are:
web/hello.xhtml
: Contains the form for login, and the buttons to change the language.web/response.xhtml
: Contains the message to be sent to the logged user. This message is intenationalized and we have the possiblity to change the language.src/mylib/LanguageChangedActionEvent.java
: This ActionListener is used to update the locale when a button has been clicked.src/mylib/HelloBean.java
Tests the username.src/mylib/Messages.properties
: Default resource bundle;src/mylib/Messages_de.properties
Resource bundle for german;src/mylib/Messages_fr.properties
Resource bundle for french.
Facelets
Download the zip of the examples : facelets2.0.zipThe following files are the most interesting ones in this project. Once installed, this project is available for testing at the following URL:http://localhost:8080/facelets2.0/
- web/WEB-INF/web.xml
- web/template.xhtml
- web/index.xhtml
- web/menu.xhtml
- web/awt.xhtml
- web/webProg.xhtml
- web/softSec.xhtml this file contains logic JSTL tags (loop and conditional branching).
- src/mylib/Professors.java contains the definition of a session bean: professors containing a list of all the names of the professors for the course Software Security.
- web/resources/components/mylib/input2.xhtml (custom component)
Ajax
Small program
In the following program I included in the page softSec.xhtml some ajax tags.Download the project in one zip file: ajax2.0.zip
Here are the more important files:
- web/softSec.xhtml the XHTML file containing the ajax components.
- src/mylib/Professors.java The java Bean refered to from the ajax commands.
IBM Example
Durring the course, I also presented an Ajax project developed by David Geary for IBM. You can simply download it from the IBM page: developerworks by IBM.comOther Examples
Those examples were not seen in course. They are nevertheless interesting, (even if written in JSF1.2).Converters Validators
validator-jsf.zipThe most interesting files are:
- faces-config.xml The configuration file, where the converters and validators can be defined;
- home.jsp the example JSP file for the use of the converters and validators;
- User.java
- Telephon.java
- TelephonConverter.java
Components
mycomponent.zipThis example is the one used for the slides for the course. It corresponds to a new component in JSF 1.2.
Here are the most interesting files
- web/prototype.jspThe prototype file
- web/welcome.jsp
- web/WEB-INF/faces-config.xml
- MyComponent.java
- MyComponentRenderer.java
- MyComponentTag.java
- mycomponentlib.tld
The prototype can be seen here: http://localhost:8080/JSF1.2-component-example/prototype.jsp
Related Pages
Contact
Prof. Dr. Emmanuel Benoist
Berner Fachhochschule - TI
Quellgasse 21
CH-2501 Biel/Bienne
Switzerland
Mail: emmanuel.benoist (at) bfh.ch
Berner Fachhochschule - TI
Quellgasse 21
CH-2501 Biel/Bienne
Switzerland
Mail: emmanuel.benoist (at) bfh.ch
Social Networks
Follow
me
on
Linkedin, Scholar
& Research gate