Magazine
 
JSF Application
 

2-inputname.jsp:

<%@ taglib uri=”http://java.sun.com/jsf/
html” prefix=”h” %>
<%@ taglib uri=”http://java.sun.com/jsf/
core” prefix=”f” %>
<f:loadBundle
basename=”javajazzup.messages”
var=”message”/>
<f:view>
<html>
<head><title>enter your name page</
title></head>
<body>
<h:form>
<h1><h:outputText
value=”#{message.inputname_header}”/></
h1>
<h:outputText
value=”#{message.prompt}”/>
<h:inputText
value=”#{StoreNameBean.personName}” />
<h:commandButton
action=”result”
value=”#{message.button_text}” />
</h:form>
</body>
</html>
</f:view>

Description:

<%@ taglib uri=”http://java.sun.com/jsf/
html” prefix=”h” %>
<%@ taglib uri=”http://java.sun.com/jsf/
core” prefix=”f” %>

“taglib” directive is used to include JSF tag libraries. First line tells where to find JSF html tags that defines html elements and second line tells where to find JSF core tags. A page that contains JSF tags is represented by a tree of components. The root of this tree is UIViewRoot. This root is represented by view tag. So it is necessary to include all component tags (tags representing UI components) within view tag.

 

<f:loadBundle basename=”
javajazzup.messages” var=”message”/>

This line loads our properties file (resource bundle) that holds messages to be displayed in the JSP page. Actually this file is a collection of “param=value” pair. The name of this file is “messages.properties” in this application which is saved in /WEB-INF/classes/ javajazzup folder. We will explain more about this in subsequent section.

<h:form> tag is used to create html <form> using JSF tag. Typically JSP page includes a form, which is submitted when a button is clicked. Form components must be used within <h:form> and </h:form>

<h:outputText
value=”#{message.inputname_header}”/>

This tag displays text on the page defined in the value attribute by looking into the resource bundle i.e. properties file (messages.properties). It looks the value for inputname_header parameter in “message.properties” file and set the value of it to value attribute. Finally this tag prints this value. So in this example this line prints “Java Jazz Up”.

<h:outputText value=”#{message.prompt}”/ >

In this line the value of “prompt” param is looked in “messages.properties” file and this tag prints this value. So in this example this line prints “Enter Your Name:”

<h:inputText value=”#{StoreNameBean.personName}” />

inputText tag is used to create input text box component. The value attribute is connected with the managed bean attribute. Here StoreNameBean is the name of Bean and personName is the name of attribute of bean. After pressing the submit button, bean gets the value filled in the input text box. This bean is nothing but a Java Bean that contains attributes and setter and getter methods to

Oct 2007 | Java Jazz Up | 57
previous
index
next
 
Pages: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29,

30
, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53 , 54, 55, 56, 57,

58
, 59, 60, 61, 62, 63 , 64, 65 , 66 , 67 , 68 , 69 , 70, 71, 72, 73, 74, 75, 76, 77, 78,   Download PDF