|
Lets start working on forms with the help of HTML tag lib of the JSF. Take an example for the registration form. We will have only name, password, retype password and description field in the form. One submit button is also used to submit the form to the backend. The following is the code for the Registration password.
<%@page contentType="text/html"%> <%@page pageEncoding="UTF-8"%>
<%@taglib prefix="f" uri="http://java.sun.com/jsf/core"%> <%@taglib prefix="h" uri="http://java.sun.com/jsf/html"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%-- This file is an entry point for JavaServer Faces application. --%>
<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <h1 align="center"> Registration Page</h1> </head> <body>
<f:view>
<h:form id="form1"> <table align="center"> <tr> <td>Name:</td> <td><h:inputText id="name" label="Name" value="#{RegistrationBean.name}"/></td> </tr> <tr> <td>Password:</td> <td><h:inputSecret id="password" label="Password" value="#{RegistrationBean.password}"/></td> </tr> <tr> <td>Retype Password:</td> <td><h:inputSecret id="password1" label="Retype Password" value="#{RegistrationBean.password1}"/></td> </tr> <tr> <td>Description</td> <td><h:inputTextarea id="description" rows="10" cols="30" value="#{RegistrationBean.description}"/></td> </tr> <tr> <td colspan="2" align="center"><h:commandButton id="submit" action="success" value="Submit" /></td> </tr> </table>
</h:form> </f:view> </body> </html>
|
Output:-
The following form will be displayed when we run the registration.jsp file.
.jpg) |