All of the source code for this posting can be downloaded from:
http://dchooge.myweb.uga.edu/ExampleFiles.zipThis example is extremely basic and simply allows the user to enter text on one page then submit this information for display on another. However, even this simple example shows how information can be passed from one page to another as well as the invocation of Java functions from JSF pages.
For this example I'll be extending the blank-shale application starting with the welcome page. Overall, the shale application is comprised of two pages:
- welcome.jsp - This is an edited version of the welcome page present in shale-blank. It now accepts user into and saves this information to StringBean.java. A new commandButton has also been added that actually submits the entered information to the Bean and the passes control to the "next" view. I'll go into the navigation options later but for now its enough to simply note that this option is configured in faces-config.xml
- showString.jsp - This new page simply displays the string entered on welcome.jsp and saved into StringBean.java
As a further note the prompts present on both welcome.jsp and showString.jsp are pulled from Bundle.properties
Shale requires that each JSF page be backed by an AbstractViewController. In the case of the welcome.jsp page this is simply the edited form of the WelcomeBean.java file present in the original shale-blank application. By the same token showString.jsp is backed by ShowStringViewController.java. There are several key functions included in these two files that are currently unused but will find use later as the application is developed more:
- prerender() - The function called just before the page this Java file is attached to is rendered. This function is often used to set up database connections needed on the page or to execute functions who's outcome is displayed on the JSF page in question.
- preprocess() - This function is extremely similar to prerender() however in this case it is called just prior to any other function calls on the page.
The two AbstractViewControllers are then declared in faces-config.xml and tied to the page through the tag on the welcome page or the tag on the showString.jsp page.
Finally, the object that will store the user entered value is created by StringBean.java. Once again this Bean is declared in faces-config.xml file. The user entered value is actually saved to this Bean through the the inputText declaration:
It is the commandButton declared on the welcome.jsp page that passes control from one JSF page to another. Namely, it checks the section of faces-config.xml and passes to the specified.
Finally, the user entered text shows up on the showString.jsp page through the outputText tag:
As a final note it is the getters and setters present in StringBean.java that are actually used to both store and recall the values entered by the user.