h:outputLabel |
|
The outputLabel tag renders an HTML "label" element. It allows you to
customize the appearance of the label using CSS styles. The outputLabel
component is associated with another component via its "for" attribute.
The other component must be created before the outputLabel component when the
JSF page is rendered. Note the use of the panelGroup container in the example
below. The panelGroup component renders its children, allowing the outputLabel
component to locate the inputText component at render time.
JSF Example
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html">
<h:head />
<body>
<h:form>
<h:panelGroup>
<h:outputLabel id="usernameLabel" for="username"
value="#{messages.usernameLabel} " />
<h:inputText id="username" value="#{userBean.user.username}" />
</h:panelGroup>
</h:form>
</body>
</html>
This example was formatted by JSFToolbox for Dreamweaver.
com/mycompany/messages.properties
usernameLabel=Username
faces-config.xml
<?xml version="1.0" encoding="UTF-8"?>
<faces-config xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd"
version="2.0">
<application>
<resource-bundle>
<base-name>com.mycompany.messages</base-name>
<var>messages</var>
</resource-bundle>
</application>
</faces-config>
Rendered Output
|