Because I am constantly busy working on something, I have never had time to actually put everything in words and pictures. But, since you got here, then you must have already seen some part of my work - and this is the way I’m talking.I'm 23, born in Romania, student at UPG Romania in software development field. I started from 0, mostly with basic stuff, and I’m evolving every day to an expert. I'm focused on freelancing projects, from small websites, to really heavy stuff. I know that I look and act differently from most developers, but this is why you will love to work with me! Constantin has posted 42 posts at DZone. You can read more from them at their website. View Full User Profile

Trivial login form in JSF 2.0

  • submit to reddit

This tip is an example of how you can create a trivial login form in JSF 2.0 . The credentials are hardcoded as final variables – in real application, you need will compare the entered values agains a database.

. . .
public class User implements Serializable {

   private static final long serialVersionUID = 1L;
   private final String userName = "User";
   private final String userPassword = "12345";
   private String name;
   private String password;

   public String getName() {
      return name;
   public void setName(String name) { = name;

   public String getPassword() {
      return password;

   public void setPassword(String password) {
      this.password = password;
   public String login() {
         return "welcome";
   } else {
         return "index";

The login page should look something as below:

  . . .
       User : <h:inputText value="#{}" />
       Password : <h:inputSecret value="#{user.password}" />
       <h:commandButton action="#{user.login}" value="Submit" />
   . . .

If the userName and userPassword corresponds with the name and password entered, you will be redirected to the welcome.xhtml page. Otherwise, you will remain on the login form page.



Published at DZone with permission of its author, Constantin Alin.

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)



Radu Alex replied on Fri, 2011/07/01 - 3:14am

Geez, what this got to do with login or security??
You can read about Java EE security here:
Until couple of month ago I thought DZone is not about trivial examples. You can rarely find any quality articles those days...
Your article might be good for absolute beginners (with a different title of course as you might confuse people with wrong info), not for professionals as this site was supposed to be.
I'm really considering to stop reading article feeds from DZone!
No offense...

Charlie Mordant replied on Fri, 2011/07/01 - 8:20am

Totally agree with Alex

Slim Ouertani replied on Sun, 2011/07/03 - 10:50am

very poor and bad article! :(

Sirikant Noori replied on Sun, 2012/01/15 - 12:02pm

Huh. Please step back and read how security in java webapp works.Remember: This is not security! If some other beginner read those articles they will never get the point of how it is done correctly.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.