This example application can be run here. It illustrates two JSF techniques:
The handling for both is entirely in index.xhtml.
To give an example where both techniques are useful, suppose you had a web application that required user login. You would typically have an login page with an <h:inputText> widget for entering the user name and an <h:inputSecret> for entering the password. Both of these fields should be filled out by the user before clicking on a command button to proceed to a new page. Failure to do so should result in the same page being display again, but this time with error messages indicating what the user failed to do correctly.
But then consider how you deal with an application that is just using login for the purpose of associating information gathered from a user with that user. For example, an e-busines may want to record information about user's preferences, so it requires a login to identify the user. How does the e-business deal with new users? It asks them to register if they have not already done so.
If the login web page has required user name and password fields and has a command button for registration, you don't want the users seeing the login page again if they clicked on the registration button without filling in the user name or password. Clicking on the registration button should be an alternative that does not require filling in user name or password.
The RequiredInput Application is defined by the following files:
Java classes:
JSF pages: