...
- Right-click on WebContent and create a new Folder with the name pages
- Right-click on pages folder and create a JSP called login.jsp. Select Finish.
- Similarly create another JSP page called welcome.jsp.
- Now we have to include the Tag Library Descriptors (TLD) in our application. Geronimo comes packaged with the required TLD's, which can be found in:
No Format borderStyle solid title Location of TLD <GERONIMO_HOME>\repository\org\apache\myfaces\core\myfaces-impl\1.2.3\myfaces-impl-1.2.3.jar\META-INF\myfaces-html.tld and <GERONIMO_HOME>\repository\org\apache\myfaces\core\myfaces-impl\1.2.3\myfaces-impl-1.2.3.jar\META-INF\myfaces_core.tld
- To add these two TLD's in the application, in Eclipse under the Project Explorer right-click on WEB-INF. Create a folder called tld. Copy myfaces-html.tld and myfaces_core.tld to this folder.
- The next step is to populate login.jsp and welcome.jsp with data
Code Block ActionScript ActionScript borderStyle solid title login.jsp <%@ taglib uri="/WEB-INF/tld/myfaces-html.tld" prefix="h" %> <%@ taglib uri="/WEB-INF/tld/myfaces_core.tld" prefix="f" %> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>Welcome to Apache Geronimo</title> </head> <body> <f:view> <h1><h:outputText value="Welcome to Apache Geronimo" /></h1> <h:form> <h:message for="firstName" style="color: red;" /> <h:message for="lastName" style="color: red;" /> <br> <h:outputText value="Enter your first name" /> <br> <h:inputText id="firstName" value="#{firstName.name}" required="true"> <f:validateLength minimum="4" maximum="10" /> </h:inputText> <br> <h:outputText value="Enter your last name" /> <br> <h:inputText id="lastName" value="#{lastName.LName}" required="true"> <f:validateLength minimum="3" maximum="10" /> </h:inputText> <br> <h:commandButton id="submit" action="validated" value="Enter" /> </h:form> </f:view> </body> </html>
Lets now try to understand what each line of code represents.Code Block ActionScript ActionScript borderStyle solid title welcome.jsp <%@ taglib uri="/WEB-INF/tld/myfaces-html.tld" prefix="h"%> <%@ taglib uri="/WEB-INF/tld/myfaces_core.tld" prefix="f"%> <%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>Welcome</title> </head> <body> <f:view> <h3><h:outputText value="You have successfully logged in:, " /> <h:outputText value="#{firstName.name} " /> <h:outputText value="#{lastName.LName}" /> <h:outputText value="!" /></h3> </f:view> </body> </html>
- The first two lines in login.jsp defines two tag libraries
These two sets of tags are defined by JSF. First one with the namespace "h" is used to generate html views. Second one with the namespace "f" handles the core functionalities of JSF like type conversions, validations and listeners for input from user.Code Block ActionScript ActionScript borderStyle solid title Code Snippet from login.jsp <%@ taglib uri="/WEB-INF/tld/myfaces-html.tld" prefix="h" %> and <%@ taglib uri="/WEB-INF/tld/myfaces_core.tld" prefix="f" %>
- The next few lines contains the usual html tags
Code Block ActionScript ActionScript borderStyle solid title Code Snippet from login.jsp <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>Welcome to Apache Geronimo</title> </head> <body>
- <f:view> -- This tag represents the start of JSF code.
Represents the input tag. id="firstName" and value="firstName.name" comes from the Managed Bean.Code Block ActionScript ActionScript borderStyle solid title Code Snippet from login.jsp <h:inputText id="firstName" value="#{firstName.name}" required="true">
- Using the Faces Configuration Editor, select firstName bean under Managed Bean tab. The Managed Bean Name is firstName. See the figure below.
This completes the implementation of View (V) in the application. The other tags <f:validateLength> and <h:commandButton> will be explained in the next section.
...