background image

The style and styleClass Attributes

<< The immediate Attribute | Using Text Components >>
<< The immediate Attribute | Using Text Components >>

The style and styleClass Attributes

Unlike nearly every other JavaServer Faces tag attribute, the rendered attribute is restricted to
using rvalue expressions. As explained in
"Unified Expression Language" on page 146
, rvalue
expressions can only read data; they cannot write the data back to the data source. Therefore,
expressions used with rendered attributes can use the arithmetic operators and literals that
rvalue expressions can use but lvalue expressions cannot use. For example, the expression in the
preceding example uses the > operator.
The style and styleClass Attributes
The style and styleClass attributes allow you to specify Cascading Style Sheets (CSS) styles
for the rendered output of your component tags.
"Displaying Error Messages with the message
and messages Tags" on page 349
describes an example of using the style attribute to specify
styles directly in the attribute. A component tag can instead refer to a CSS stylesheet class. The
dataTable
tag on the bookcatalog.jsp page of the Duke's Bookstore application references the
style class list-background:
<h:dataTable id=
"books"
...
styleClass=
"list-background"
value=
"#{bookDBAO.books}"
var=
"book">
The stylesheet that defines this class is stylesheet.css, which is included in the application.
For more information on defining styles, please the see Cascading Style Sheets Specification at
http://www.w3.org/Style/CSS/
.
The value and binding Attributes
A tag representing a component defined by UIOutput or a subclass of UIOutput uses value and
binding
attributes to bind its component's value or instance respectively to an external data
source.
"Binding Component Values and Instances to External Data Sources" on page 364
explains how to use these attributes.
Adding a Form Component
A UIForm component class represents an input form, which includes child components that
contain data that is either presented to the user or submitted with the form.
Figure 11­1
shows a typical login form, in which a user enters a user name and password, and
submits the form by clicking the Login button.
Adding UI Components to a Page Using the HTML Component Tags
Chapter 11 · Using JavaServer Faces Technology in JSP Pages
329