JBoss.orgCommunity Documentation
Copyright ©
Abstract
Read this book for a comprehensive guide to getting started and working with RichFaces 4. It includes details of the architecture, the framework's use in different applications, and skinning implementations.
The RichFaces framework is a rich component library for JavaServer Faces (JSF). The framework extends the JSF framework's Ajax capabilities with advanced features for enterprise web application development.
RichFaces leverages several parts of the JSF 2 framework including lifecycle, validation, conversion facilities, and management of static and dynamic resources. The RichFaces framework includes components with built-in Ajax support and a customizable look-and-feel that can be incorporated into JSF applications.
RichFaces provides a number of advantages for enterprise web application development:
Create complex application views using out-of-the-box components. The RichFaces user interface (UI) library (rich
) contains components for adding rich interactive features to JSF applications. It extends the RichFaces framework to include a large set of Ajax-enabled components that come with extensive skinning support. Additionally, the RichFaces framework is designed to be used seamlessly with other 3d-party libraries on the same page, so you have more options for developing applications.
Write your own customized rich components with built-in Ajax support. The Component Development Kit (CDK), used for the RichFaces UI library creation, includes a code-generation facility and a templating facility using XHTML (extended hyper-text markup language) syntax.
Generate binary resources on the fly. Extensions to JSF 2 resource-handling facilities can generate images, sounds, Microsoft Excel spreadsheets, and more during run-time.
Create a modern rich user-interface with skinning technology. RichFaces provides a skinning feature that allows you to define and manage different color schemes and other parameters of the look and feel. It is possible to access the skin parameters from page code during run-time. RichFaces comes packaged with a number of skins to get you started, but you can also easily create your own customized skins too.
Follow the instructions in this chapter to configure the RichFaces framework and get started with application development.
If you have existing projects that use a previous version of RichFaces, refer to the RichFaces Migration Guide.
The minimum technical requirements needed to get started with RichFaces are outlined below.
Java Development Kit (JDK) 1.5 or higher
An application server compliant with Java Platform, Enterprise Edition 5 (JEE5), such as JBoss Application Server 6 or Apache Tomcat 6.
A compliant web browser, such as Firefox 3.5 or Internet Explorer 7
RichFaces applications can be developed using a range of tools, including integrated development environments (IDEs). This chapter covers only two such environments in detail:
JBoss Tools, as described in Section 2.4, “Creating a project with JBoss Tools”.
Maven, as described in Section 2.5, “Creating a project with Maven”.
Other environments, such as Idea or NetBeans, could also be used for RichFaces development, but are not detailed in this book.
Follow the instructions in this section to set up the RichFaces framework and begin building applications.
Download RichFaces archive
Download RichFaces from the JBoss RichFaces Downloads area at http://www.jboss.org/richfaces/download.html. The binary files (available in .bin.zip
or .bin.tar.gz
archives) contain the following:
compiled, ready-to-use Java Archives (JAR files) of the RichFaces libraries
library source JAR files
documentation, including Java documentation and JavaScript documentation
archetypes
example source code
Compiling from source
Instead of using the pre-compiled binaries, you can compile the source files yourself. Refer to Section 3.6, “Compiling from source code” for further instructions.
Unzip archive
Create a new directory named RichFaces
, then unzip the archive containing the binaries there.
Follow the procedure in this section to create a new RichFaces application with JBoss Tools Ensure you are using the latest version of JBoss Tools.
Create a new project
Create a new project based on the JSF 2 environment using the RichFaces 4 template. In JBoss Tools, select → → from the menu. Name the project, select JSF 2 from the JSF Environment drop-down box, and click the button to create the project.
If necessary, update the JSF 2 JAR files to the latest versions.
Add the RichFaces libraries to the project
Add richfaces-core-api.jar
, richfaces-core-impl.jar
, richfaces-components-api.jar
, and richfaces-components-ui.jar
into your project. Copy them from the location where you unzipped the RichFaces archive to the WebContent/WEB-INF/lib/
directory of your project in JBoss Tools.
Reference the tag libraries
The RichFaces tag libraries need to be referenced on each XHTML page in your project:
<ui:composition xmlns:a4j="http://richfaces.org/a4j"
xmlns:rich="http://richfaces.org/rich">
...
</ui:composition>
You are now ready to begin constructing your RichFaces applications. RichFaces components can be dragged and dropped into your application's XHTML pages from the RichFaces palette in JBoss Tools.
Apache Maven is a build automation and project management tool for Java projects. Follow the instructions in this section to create a Maven project for RichFaces.
Maven can be downloaded and installed from Apache's website at http://maven.apache.org/download.html. Due to the use of dependency importing, Maven version 2.0.9 or above is required.
Once Maven has been installed, no further configuration is required to begin building Maven projects.
A Maven archetype is a template for creating projects. Maven uses an archetype to generate a directory structure and files for a particular project, as well as creating pom.xml
files that contain build instructions.
The RichFaces Component Development Kit includes a Maven archetype named richfaces-archetype-simpleapp
for generating the basic structure and requirements for a RichFaces application project. Maven can obtain the archetype from the JBoss repository at https://repository.jboss.org/nexus/content/groups/public/. The archetype is also included with the RichFaces source code in the archetypes
directory. Follow the procedure in this section to generate a new Maven-based RichFaces project using the archetype.
Add required repository
The details for the JBoss repository need to be added to Maven so it can access the archetype. Add a profile in the
file under the maven_installation_folder
/conf/settings.xml<profiles>
element:
<profiles>
...
<profile>
<id>jboss-public-repository</id>
<repositories>
<repository>
<id>jboss-public-repository-group</id>
<name>JBoss Public Maven Repository Group</name>
<url>https://repository.jboss.org/nexus/content/groups/public/</url>
<layout>default</layout>
<releases>
<enabled>true</enabled>
<updatePolicy>never</updatePolicy>
</releases>
<snapshots>
<enabled>true</enabled>
<updatePolicy>never</updatePolicy>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>jboss-public-repository-group</id>
<name>JBoss Public Maven Repository Group</name>
<url>https://repository.jboss.org/nexus/content/groups/public/</url>
<layout>default</layout>
<releases>
<enabled>true</enabled>
<updatePolicy>never</updatePolicy>
</releases>
<snapshots>
<enabled>true</enabled>
<updatePolicy>never</updatePolicy>
</snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
The profile then needs to be activated in the <activeProfiles>
element:
<activeProfiles>
<activeProfile>jboss-public-repository</activeProfile>
</activeProfiles>
For further details, refer to the JBoss RichFaces Wiki.
Generate the project from the archetype
The project can now be generated with the richfaces-archetype-simpleapp
archetype. Create a new directory for your project, then run the following Maven command in the directory:
mvn archetype:generate -DarchetypeGroupId=org.richfaces.archetypes -DarchetypeArtifactId=richfaces-archetype-simpleapp -DarchetypeVersion=4.0.0-SNAPSHOT -DgroupId=org.docs.richfaces
-DartifactId=new_project
The following parameters can be used to customize your project:
-DgroupId
Defines the package for the Managed Beans
-DartifactId
Defines the name of the project
The command generates a new RichFaces project with the following structure:
new_project
├──pom.xml
├──readme.txt
└──src
└──main
├──java
│ └──org
│ └──docs
│ └──richfaces
│ └──RichBean.java
└──webapp
├──index.xhtml
├──templates
│ └──template.xhtml
└──WEB-INF
├──faces-config.xml
└──web.xml
Add test dependencies (optional)
Your root directory of your project contains a project descriptor file, pom.xml
. If you wish to include modules for test-driven JSF development, add any dependencies for the tests to the pom.xml
file. For full details on how to use the jsf-test project, refer to http://community.jboss.org/wiki/TestDrivenJSFDevelopment.
Build the project
Build the project from the command line by entering the mvn install
command.
The BUILD SUCCESSFUL
message indicates the project has been assembled and is ready to import into an IDE (integrated development environment), such as JBoss Tools.
Import the project into an IDE
To import the project into Eclipse and JBoss Tools, use the JBoss Maven Integration plug-ins. These plug-ins work with plug-ins from the M2Eclipse project to import Maven projects.
Install the plug-ins
Choose
→ from the Eclipse menu.Select the JBoss Tools update site to use, then open the Maven Support group and select the JBoss Maven Integration and JBoss Maven JSF Configurator plug-ins.
Follow the prompts to install the integration plug-ins. The installation will automatically include the transitive dependencies Maven Integration for Eclipse and Maven Integration for WTP. Both of these dependencies are from the M2Eclipse project.
Restart Eclipse to finish the installation.
Open the importing wizard
With the plug-ins installed, open the importing wizard by choosing
→ from the menu.Select the project
Select pom.xml
file for your project.
The ability to prepare the project for Eclipse and export it using Maven is deprecated in RichFaces 4.0. The process does not support JBoss integration-specific features, such as JSF Facets.
Your project is now ready to use. Once components and functionality have been added, you can run the application on a server and access it through a web browser at the address http://localhost:8080/
.
jsf-app
/
RichFaces can be added to existing JSF 2 projects by adding the new RichFaces libraries. Refer to Step 2 and Step 3 in Section 2.4, “Creating a project with JBoss Tools” for details.
In RichFaces 4, it is not necessary to add any extra settings to the web.xml
or config.xml
settings files to use the framework.
Read this chapter for technical details on the RichFaces framework.
RichFaces has been developed with an open architecture to be compatible with a wide variety of environments.
RichFaces 4 requires either of the following server technologies:
An application server compliant with Java Platform, Enterprise Edition 5 or 6 (JEE5 or JEE6), such as JBoss Application Server 6.
A major servlet container, such as Jetty 6 or Apache Tomcat 6.
Clients accessing RichFaces applications require a web browser. Richfaces supports the following web browsers:
Developing applications with the RichFaces framework requires the Java Development Kit (JDK), an implementation of JavaServer Faces (JSF), and a development environment.
RichFaces supports the following JDK versions:
JDK 1.5 and higher
RichFaces supports the following JSF implementations and frameworks:
MyFaces 2 and higher
Seam 3 and higher
Mojara 2 and higher
RichFaces can be developed using most Java development environments. The following are recommended, and used for examples in this guide:
JBoss Tools 3.1 and higher
Maven 2.0.9 and higher (2.2.1 recommended)
The important elements of the RichFaces framework are as follows:
Ajax Action Components
Ajax Containers
Ajax Output
Skins and Theming
RichFaces Ajax Extensions
Read this section for details on each element.
The RichFaces framework includes several Ajax Action Components and Submitting Bahaviors: <a4j:commandButton>
, <a4j:commandLink>
, <a4j:poll>
, <a4j:ajax>
, and more. Use Ajax Action Components to send Ajax requests from the client side.
AjaxContainer
is an interface that marks part of the JSF tree that is decoded during an Ajax request. It only marks the JSF tree if the component or behavior sending the request does not explicitly specify an alternative. AjaxRegion
is an implementation of this interface.
AjaxContainer
is an interface that marks part of the JSF tree that will be updated and rendered on the client for every Ajax request. It only marks the JSF tree if the component or behavior sending the request does not explicitly turn off automatic updates.
RichFaces includes extensive support for application skinning. Skinning is a high-level extension to traditional CSS (Cascading Style Sheets) which allows the color scheme and appearance of an application to be easily managed. The skins simplify look-and-feel design by allowing multiple elements of the interface to be handled as manageable features, which have associated color palettes and styling. Application skins can additionally be changed on the fly during run-time, allowing user experiences to be personalized and customized.
For full details on skinning and how to create skins for the components in your application, refer to Chapter 6, Skinning and theming.
RichFaces 4 features full JSF 2 integration and uses standard web application technologies such as JavaScript, XML (Extensible Markup Language), and XHTML (Extensible Hypertext Markup Language).
JavaServer Faces 2 evaluates Ajax options, such as execute
and render
, while rendering a page. This allows any parameters to be sent directly from the client side.
RichFaces evaluates the options when the current request is sent. This increases both the security of the data and the convenience for evaluating parameters.
For example, binding Ajax options to Java Bean properties in RichFaces allows you to evaluate the options dynamically for the current request, such as defining additional zones to render. Parameters changed manually on the client side will not influence the request processing. With JSF 2, the options have evaluated during the previous page rendering would need to be used.
The following restrictions apply to applications implementing the RichFaces framework:
As with most Ajax frameworks, you should not attempt to append or delete elements on a page using RichFaces Ajax, but should instead replace them. As such, elements that are rendered conditionally should not be targeted in the render
attributes for Ajax controls. For successful updates, an element with the same identifier as in the response must exist on the page. If it is necessary to append code to a page, include a placeholder for it (an empty element).
JSF 2 does not allow resources such as JavaScript or Cascading Style Sheets (CSS) to be added if the element requiring the resource is not initially present in the JSF tree. As such, components added to the tree via Ajax must have any required resources already loaded. In RichFaces, any components added to the JSF tree should have components with corresponding resources included on the main page initially. To facilitate this, components can use the rendered="false"
setting to not be rendered on the page.
Switching RichFaces skins via Ajax during runtime should be avoided, as this requires all the stylesheets to be reloaded.
The source code for the RichFaces framework can be compiled manually rather than using the pre-compiled binaries.
Acquiring the source code
JBoss RichFaces Downloads area
Download the RichFaces distribution as described in Section 2.3, “Setting up RichFaces”. The distribution bundles contain the full RichFaces source code.
Anonymous SVN repository
Alternatively, the source files can be checked out from the anonymous SVN repository at http://anonsvn.jboss.org/repos/richfaces/branches/4.0.X/ using the following command:
svn co http://anonsvn.jboss.org/repos/richfaces/branches/4.0.X/
Unzip archive
If using the downloaded distribution, create a new directory named RichFaces
, then unzip the archive containing the source code there.
Configure Maven for RichFaces
To compile the RichFaces source code, Maven requires access to the JBoss repositories. Refer to Step 1 of the procedure in Section 2.5.2, “Using the RichFaces project archetype” to configure the required repositories.
Compile using Maven
In the root directory of the unzipped source code, enter the following command to compile and build the RichFaces framework:
mvn clean install
Add any of the following options after the command to customize the build:
-P release,docs
Maven additionally builds the documentation and release artifacts.
-D skipTests=true
Maven skips the unit and functional tests, which completes the build faster.
-D checkstyle.skip=true
Maven skips the scans for checking style, which completes the build faster.
-D skip-source
Maven does not produce any source jar
files from the build.
-D skip-enforce
Maven does not check for the correct JDK version, Maven version, and SNAPSHOT
plug-in, and forces the build.
-D jsf-profile=implementation
Maven tests builds and tests against the specified JSF implementation. The implementation
value can be any of the following:
jsf_ri
: The latest release of JSF RI (Mojarra). This is the default implemenation.
jsf_ri_javax
: The latest release of javax.faces.
jsf_ri_snapshot
: The latest snapshot version of JSF RI (Mojarra).
myfaces
: The latest release of MyFaces.
myfaces
: The latest snapshot version of MyFaces.
Access compiled binaries
The compiled libraries are located in the following sub-directories of the root RichFaces directory:
/ui/dist/richfaces-components-api/target/richfaces-components-api-
version
-SNAPSHOT.jar
/ui/dist/richfaces-components-ui/target/richfaces-components-ui-
version
-SNAPSHOT.jar
/core/api/target/richfaces-core-api-
version
-SNAPSHOT.jar
/core/impl/target/richfaces-core-impl-
version
-SNAPSHOT.jar
You can now add the compiled libraries to your project as described in Step 2 of Section 2.4, “Creating a project with JBoss Tools”.
Read this chapter for the basic concepts of using RichFaces in conjunction with Ajax and JavaServer Faces.
Many of the tags in the a4j
and rich
tag libraries are capable of sending Ajax requests from a JavaServer Faces (JSF) page.
The <a4j:commandButton>
and <a4j:commandLink>
tags are used to send an Ajax request on the click
JavaScript event.
The <a4j:poll>
tag is used to send an Ajax request periodically using a timer.
The <a4j:ajax>
tag allows you to add Ajax functionality to standard JSF components and send Ajax request on a chosen JavaScript event, such as keyup
or mouseover
, for example.
Most components in the rich
tag library have built-in Ajax support. Refer to the RichFaces Component Reference for details on the use of each component.
Use the execute
attribute to specify which parts of the JSF tree to process during an Ajax request. The execute
attribute can point to an id
identifier of a specific component to process. Components can also be identified through the use of Expression Language (EL).
Alternatively, the execute
attribute accepts the following keywords:
@all
Every component is processed.
@none
No components are processed.
@this
The requesting component with the execute
attribute is processed.
@form
The form that contains the requesting component is processed.
@region
The region that contains the requesting component is processed. Use the <a4j:region>
component as a wrapper element to specify regions.
Some components make use of additional keywords. These are detailed under the relevant component entry in the RichFaces Component Reference.
Use the render
attribute to specify which components to render for an Ajax update. The render
attribute can point to an id
identifier of a specific component to update. Components can also be identified through the use of Expression Language (EL).
Alternatively, the render
attribute accepts the following keywords:
@all
Every component is updated.
@none
No components are updated.
@this
The requesting component with the execute
attribute is updated.
@form
The form that contains the requesting component is updated.
@region
The region that contains the requesting component is updated. Use the <a4j:region>
component as a wrapper element to specify regions.
Some components make use of additional keywords. These are detailed under the relevant component entry in the RichFaces Component Reference.
Use the <a4j:outputPanel>
component with the ajaxRendered="true"
setting to always update a section irrespective of the requesting component's render
attribute. The <rich:message>
and <rich:messages>
components are based on the <a4j:outputPanel>
component, and as such will also always be updated. To override this behavior, use the limitRender="true"
setting on the requesting component.
The RichFaces framework is made up of two tag libraries: the a4j
library and the rich
library. The a4j
tag library represents Ajax4jsf, which provides page-level Ajax support with core Ajax components. This allows developers to make use of custom Ajax behavior with existing components. The rich
tag library provides Ajax support at the component level instead, and includes ready-made, self-contained components. These components don't require additional configuration in order to send requests or update.
For details on the use of the various components, refer to RichFaces Component Reference.
Read this chapter for details on some of the advanced features and configuration possibilities for the RichFaces framework.
JavaServer Faces (JSF) is the Java-based web application framework upon which the RichFaces framework has been built. RichFaces is now integrated with JSF 2, which features several improvements to the framework.
The standard display technology used by JSF 1 was JavaServer Pages (JSP). With JSF 2, the standard display technology has been changed to Facelets, which is a more powerful and more efficient View Declaration Language (VLD) than JSP.
RichFaces allows standard handlers to be defined for processing different application exceptions. Custom JavaScript can be executed when these exceptions occur.
JSF provides a global onError
handler on the client. The handler provides the relevant error code and other associated data. The RichFaces Ajax components provide the error
attribute if extra functionality needs to be defined.
Additional processing is available through a number of components, such as the following:
The <a4j:status>
component has an additional error state.
The <a4j:queue>
component can be used to process errors.
Read this chapter for a guide to skinning and theming RichFaces applications, including how to implement themes, and details on customizing and extending skins.
Application skins are used with the RichFaces framework to change the appearance of an application through setting the colors and decoration of controls and components. Typically the appearance of web applications is handled through the CSS (Cascading Style Sheet) files associated with the application, but skinning allows the settings in a CSS file to be abstracted and easily edited. Skins consist of a small, generalized set of font and color parameters that can be applied to multiple different styles. This avoids repetitive coding and duplication in CSS files. CSS files are not completely replaced: skins work as a high-level extension to standard CSS.
Each skin has a set of skin-parameters
, which are used to define the theme palette and other elements of the user interface. These parameters work together with regular CSS declarations, and can be referred to from within CSS using JavaServer Faces Expression Language (EL).
The skinning feature of RichFaces also allows skins to be changed at runtime, so users can personalize an application's appearance on the fly.
RichFaces includes a number of predefined skins. These skins can be used in RichFaces web applications by specifying the skin name in the org.richfaces.skin
context parameter in the web.xml
settings file. The predefined skins are as follows:
DEFAULT
plain
, which contains no skin parameters and is intended for embedding RichFaces components into existing projects with their own styles.
emeraldTown
blueSky
wine
japanCherry
ruby
classic
deepMarine
To add one of these skins to your application, add the org.richfaces.SKIN
context parameter to the web.xml
configuration file:
<context-param>
<param-name>org.richfaces.skin</param-name>
<param-value>skin_name
</param-value>
</context-param>
RichFaces skins are implemented using the following three-level scheme:
Stylesheets are provided for each component. CSS style parameters map to skin parameters defined in the skin property file. This mapping is accomplished through the use of ECSS files. Refer to Section 6.3.2, “ECSS files” for details on ECSS files.
Skin property files map skin parameters to constant styles. Skin properties are defined in skin.properties
files. Refer to Section 6.3.1, “Skin parameter tables” for a listing of the skin parameters used in a typical skin.
Individual components can use the styleClass
attribute to redefine specific elements. These components then use the styles defined in a CSS file instead of the standard look for components as defined by the ECSS stylesheets.
Table 6.1, “Parameter settings for the blueSky skin” lists the default values for the parameter settings in the blueSky
skin. These values are all listed in the blueSky.skin.properties
file, which can be customized and extended as described in Section 6.4, “Customizing skins”.
Table 6.1. Parameter settings for the blueSky
skin
Parameter name | Default value |
---|---|
headerBackgroundColor | #BED6F8 |
headerGradientColor | #F2F7FF |
headTextColor | #000000 |
headerWeightFont | bold |
generalBackgroundColor | #FFFFFF |
generalTextColor | #000000 |
generalSizeFont | 11px |
generalFamilyFont | Arial, Verdana, sans-serif |
controlTextColor | #000000 |
controlBackgroundColor | #FFFFFF |
additionalBackgroundColor | #ECF4FE |
shadowBackgroundColor | #000000 |
shadowOpacity | 1 |
panelBorderColor | #BED6F8 |
subBorderColor | #FFFFFF |
calendarWeekBackgroundColor | #F5F5F5 |
calendarHolidaysBackgroundColor | #FFEBDA |
calendarHolidaysTextColor | #FF7800 |
calendarCurrentBackgroundColor | #FF7800 |
calendarCurrentTextColor | #FFEBDA |
calendarSpecBackgroundColor | #E4F5E2 |
calendarSpecTextColor | #000000 |
editorBackgroundColor | #F1F1F1 |
editBackgroundColor | #FEFFDA |
errorColor | #FF0000 |
gradientType | plain |
tabBackgroundColor | #C6DEFF |
tabDisabledTextColor | #8DB7F3 |
tableHeaderBackgroundColor | #D6E6FB |
tableSubHeaderBackgroundColor | #ECF4FE |
tableBorderWidth | 1px |
tableHeaderTextColor | #0B356C |
trimColor | #D6E6FB |
tipBackgroundColor | #FAE6B0 |
tipBorderColor | #E5973E |
selectControlColor | #E79A00 |
generalLinkColor | #0078D0 |
hoverLinkColor | #0090FF |
visitedLinkColor | #0090FF |
headerSizeFont | 11px |
headerFamilyFont | Arial, Verdana, sans-serif |
tabSizeFont | 11px |
tabFamilyFont | Arial, Verdana, sans-serif |
buttonSizeFont | 11px |
buttonFamilyFont | Arial, Verdana, sans-serif |
tableBackgroundColor | #FFFFFF |
tableFooterBackgroundColor | #CCCCCC |
tableSubfooterBackgroundColor | #F1F1F1 |
tableBorderColor | #C0C0C0 |
warningColor | #FFE6E6 |
warningBackgroundColor | #FF0000 |
RichFaces uses ECSS files to add extra functionality to the skinning process. ECSS files are CSS files which use Expression Language (EL) to connect styles with skin properties.
Example 6.1. ECSS style mappings
The ECSS code for the <rich:panel>
component contains styles for the panel and its body:
.rf-p{
background-color:'#{richSkin.generalBackgroundColor}';
color:'#{richSkin.panelBorderColor}';
border-width:1px;
border-style:solid;
padding:1px;
}
.rf-p-b{
font-size:'#{richSkin.generalSizeFont}';
color:'#{richSkin.generalTextColor}';
font-family:'#{richSkin.generalFamilyFont}';
padding:10px;
}
.rf-p
defines the panel styles
The background-color CSS property maps to the generalBackgroundColor
skin parameter.
The color CSS property maps to the panelBorderColor
skin parameter.
.rf-p-b
defines the panel body styles
The font-family CSS property maps to the generalFamilyFont
skin parameter.
The font-size CSS property maps to the generalSizeFont
skin parameter.
The color CSS property maps to the generalTextColor
skin parameter.
Skins in RichFaces can be customized on each of the three levels:
Application interfaces can be modified by altering the values of skin parameters in the skin itself. Edit the constant values defined in the skin.properties
file to change the style of every component mapped to that skin property.
Mappings and other style attributes listed in a component's ECSS file can be edited. Edit the ECSS file to change the styles of all components of that type.
Individual components can use the styleClass
attribute to use a unique style class. Add the new style class to the application CSS and reference it from an individual component with the styleClass
attribute.
Example 6.2. Simple skinning example
Using any component, such as a panel, without specifying a styleClass
will use the default skin parameters for that component.
<rich:panel>This is a panel without a header</rich:panel>
When rendered for display, the panel consists of two HTML elements: a wrapper <div>
element and a <div>
element for the body of the panel. The wrapper element for a panel without a specified styleClass
is rendered as follows:
<div id="..." class="rf-p">
<div id="..." class="rf-p-b">
This is a panel without a header
</div>
</div>
To customize the panel appearance according to the three-level scheme, adjust the styles according to the following approach:
Change the definitions for the generalBackgroundColor
or panelBorderColor
parameters in the skin. This will cause all panels in the application to change to the new settings.
Redefine the rf-p
class in the application CSS. This will also cause all panels in the application to change to the new settings, though the skin itself has not been altered. Any properties not mapped to skin parameters should be redefined in this way.
Specify a different styleClass
attribute to style the individual component. If a styleClass
attribute is used, the specified style class is applied to the component, which could extend or override the default styles.
<rich:panel styleClass="customClass">...</rich:panel>
The customClass
style is added to the CSS, and is applied to the component when it is rendered for display:
<div class="rf-p customClass">
...
</div>
Create the skin file
The name of the skin file should follow the format
and is placed in either the new_skin_name
.skin.propertiesMETA-INF/skins/
directory or the classpath directory of your project.
Define the skin constants
Define all the skin constants
Add skin parameter constants and values to the file. All the skin parameters listed in Table 6.1, “Parameter settings for the blueSky skin” should be included in the skin file, with settings relevant to your new skin.
Example 6.3. blueSky.skin.properties
file
Open the blueSky.skin.properties
file from the /META-INF/skins
directory in the richfaces-impl-version
.jar package. The file lists all the skin parameter constants shown in Table 6.1, “Parameter settings for the blueSky skin”.
You can use the blueSky.skin.properties
file as a template for your new skin.
Extend a base skin
Instead of redefining an entire new skin, your skin can use an existing skin as a base on which to build new parameters. Specify a base skin by using the baseSkin
parameter in the skin file, as shown in Example 6.4, “Using a base skin”.
Example 6.4. Using a base skin
This example takes the blueSky
skin as a base and only changes the generalSizeFont
parameter.
baseSkin=blueSky generalSizeFont=12pt
Reference the skin definition
Add a skin definition <context-param>
to the web.xml
settings file of your application:
<context-param>
<param-name>org.richfaces.skin</param-name>
<param-value>
new_skin_name </param-value>
</context-param>
To allow users to change skins at runtime, use a managed bean to access the skin.
Create the skin bean
The skin bean is a simple interface to manage the skin:
public class SkinBean {
private String skin;
public String getSkin() {
return skin;
}
public void setSkin(String skin) {
this.skin = skin;
}
}
Reference the skin bean
Add the @ManagedBean
and @SessionScoped
references to the class.
Alternatively, use EL (Expression Language) to reference the skin bean from the web.xml
settings file.
<context-param>
<param-name>org.richfaces.skin</param-name>
<param-value>#{skinBean.skin}</param-value>
</context-param>
Set initial skin
The application needs an initial skin to display before the user chooses an alternative skin. Specify the skin in your class with @ManagedProperty
.
@ManagedProperty(value="blueSky")
private String skin;
Alternatively, specify the initial skin in the web.xml
configuration file.
<managed-bean>
<managed-bean-name>skinBean</managed-bean-name>
<managed-bean-class>SkinBean</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
<managed-property>
<property-name>skin</property-name>
<value>blueSky</value>
</managed-property>
</managed-bean>
Standard HTML controls used alongside RichFaces components are also themed to create a cohesive user interface.
The skinning style properties are automatically applied to controls based on their element names and attribute types. If the HTML elements are referenced in the standard skin stylesheets, the controls will be styled according to the mapped skin properties.
Standard HTML controls are skinned in this way by default. To override this behavior, set the org.richfaces.enableControlSkinning
context parameter in the web.xml
configuration file to false
:
<context-param>
<param-name>org.richfaces.enableControlSkinning</param-name>
<param-value>false</param-value>
</context-param>
The skinning style properties can be determined through a separate CSS class. This method is not available by default, but is enabled through the org.richfaces.enableControlSkinningClasses
context parameter in the web.xml
configuration file:
<context-param>
<param-name>org.richfaces.enableControlSkinningClasses</param-name>
<param-value>true</param-value>
</context-param>
When enabled, a stylesheet with predefined classes offers a special CSS class named rfs-ctn
. Reference the rfs-ctn
class from any container element (such as a <div>
element) to skin all the standard HTML controls in the container.
Standard HTML controls can also be specifically defined in the CSS. Refer to the /core/impl/src/main/resources/META-INF/resources/skinning_both.ecss
file in the richfaces-ui.jar package for examples of specially-defined CSS classes with skin parameters for HTML controls.
Each of the RichFaces components are listed below, along with their style classes and skin parameters. For further details on each component, refer to the relevant section in the RichFaces Component Reference.
Table A.1. Style classes (selectors) and corresponding skin parameters
Class (selector) | Skin Parameters | Mapped CSS properties |
---|---|---|
|
| color |
| No skin parameters. | |
| No skin parameters. | |
| No skin parameters. | |
| No skin parameters. | |
| No skin parameters. | |
| No skin parameters. | |
| No skin parameters. | |
| No skin parameters. | |
| No skin parameters. | |
| No skin parameters. | |
| No skin parameters. | |
| No skin parameters. | |
| No skin parameters. | |
| No skin parameters. | |
| No skin parameters. |
Table A.2. Style classes (selectors) and corresponding skin parameters
Class (selector) | Skin Parameters | Mapped CSS properties |
---|---|---|
|
| color |
| font-family | |
| font-size | |
|
| background-color |
|
| border-color |
| background-color | |
| No skin parameters. | |
|
| background-color |
| border-left-color | |
| No skin parameters. | |
| No skin parameters. | |
| No skin parameters. | |
| No skin parameters. | |
|
| background-color |
| border-color | |
| No skin parameters. | |
| No skin parameters. | |
| No skin parameters. |
Table A.3. Style classes (selectors) and corresponding skin parameters
Class (selector) | Skin Parameters | Mapped CSS properties |
---|---|---|
|
| border-color |
| No skin parameters. | |
|
| border-bottom-color |
| background-color | |
| font-size | |
| font-family | |
|
| border-bottom-color |
| background-color | |
| font-size | |
| font-family | |
|
| background-color |
| font-size | |
| font-family | |
| font-weight | |
| color | |
|
| border-right-color, border-bottom-color |
| background | |
| font-size | |
| font-family | |
|
| border-right-color, border-bottom-color |
| background | |
| font-size | |
| font-family | |
|
| background-color |
| font-size | |
| font-family | |
| font-weight | |
| color | |
|
| background |
| font-size | |
| font-family | |
| No skin parameters. | |
| No skin parameters. | |
|
| background-color |
| color | |
| border-color | |
| border-right-color, border-bottom-color | |
|
| border-color |
| border-right-color, border-bottom-color | |
| No skin parameters. | |
|
| border-bottom-color, border-right-color |
| background-color | |
| font-size | |
| font-family | |
| No skin parameters. | |
|
| background-color |
| color | |
|
| background-color |
| color | |
|
| background-color |
| color | |
|
| border-bottom-color, border-right-color |
| background-color | |
| font-size | |
| font-family | |
|
| background-color |
| color | |
| No skin parameters. | |
|
| font-size |
| font-family | |
|
| background-color |
| border-color | |
| border-right-color, border-bottom-color | |
|
| background-color, border-color |
| No skin parameters. | |
| No skin parameters. | |
| No skin parameters. | |
|
| background |
|
| background-color |
| No skin parameters. | |
|
| border-color |
| background | |
|
| background-color |
| color | |
|
| background |
| border-color | |
| border-right-color, border-bottom-color | |
|
| background |
| border-color | |
| border-right-color, border-bottom-color | |
| No skin parameters. | |
|
| border-color |
| border-right-color, border-bottom-color | |
|
| border-right-color, border-bottom-color |
| border-color | |
| background-color | |
|
| border-color |
| background | |
| font-size | |
| font-family | |
|
| font-size |
| font-family | |
| No skin parameters. | |
| No skin parameters. | |
|
| border-color |
| background | |
| font-size | |
| font-family | |
|
| background |
| border-top-color | |
|
| background |
| border-top-color | |
|
| border-right-color |
Table A.4. Style classes (selectors) and corresponding skin parameters
Class (selector) | Skin Parameters | Mapped CSS properties |
---|---|---|
|
| background-color |
| border-color | |
|
| background-color, border-color |
| No skin parameters. | |
| No skin parameters. | |
| No skin parameters. | |
|
| background-color |
| border-color | |
|
| color |
| font-family | |
| font-size | |
|
| background-color |
| border-color | |
|
| color |
| font-family | |
| font-size | |
|
| background-color |
| border-color | |
|
| color |
| font-family | |
| font-size | |
|
| background-color |
| border-color | |
|
| color |
| font-family | |
| font-size | |
|
| border-bottom-color |
| No skin parameters. | |
|
| color |
| font-family | |
| font-size | |
|
| color |
| font-family | |
| font-size | |
|
| color |
| font-family | |
| font-size | |
| No skin parameters. | |
| No skin parameters. |
Table A.5. Style classes (selectors) and corresponding skin parameters
Class (selector) | Skin Parameters | Mapped CSS properties |
---|---|---|
|
| background-color |
| border-bottom-color | |
| No skin parameters. | |
| No skin parameters. | |
| No skin parameters. | |
|
| background-color, border-bottom-color |
| color | |
| font-family | |
| font-size | |
| No skin parameters. | |
| No skin parameters. | |
|
| background-color |
| border-color | |
|
| background-color |
| border-color | |
| No skin parameters. | |
| No skin parameters. | |
| No skin parameters. | |
| No skin parameters. |
Table A.6. Style classes (selectors) and corresponding skin parameters
Class (selector) | Skin Parameters | Mapped CSS properties |
---|---|---|
|
| background-color |
| border-bottom-color | |
| No skin parameters. | |
| No skin parameters. | |
| No skin parameters. | |
|
| background |
| color | |
| font-family | |
| font-size | |
|
| border-color |
|
| border-color |
| No skin parameters. | |
| No skin parameters. | |
| No skin parameters. | |
|
| background-color |
| border-color | |
|
| background-color |
| border-color | |
| No skin parameters. | |
| No skin parameters. | |
|
| background-color |
| border-color | |
| No skin parameters. | |
| No skin parameters. | |
| No skin parameters. | |
| No skin parameters. | |
| No skin parameters. |
Table A.7. Style classes (selectors) and corresponding skin parameters
Class (selector) | Skin Parameters | Mapped CSS properties |
---|---|---|
| No skin parameters. | |
|
| background-color |
| border-bottom-color | |
| No skin parameters. | |
|
| font-size |
| font-family | |
| color | |
| border-left-color | |
|
| font-size |
| font-family | |
| color | |
| border-right-color | |
|
| font-size |
| font-family | |
| color | |
| No skin parameters. | |
| No skin parameters. | |
| No skin parameters. | |
| No skin parameters. | |
| No skin parameters. | |
| No skin parameters. | |
| No skin parameters. | |
| No skin parameters. | |
|
| font-size |
| font-family | |
| color | |
| border | |
| background-color |
Table A.8. Style classes (selectors) and corresponding skin parameters
Class (selector) | Skin Parameters | Mapped CSS properties |
---|---|---|
|
| border-color |
|
| font-size |
| font-family | |
| color | |
| background-color | |
|
| background-color |
| border-left-color | |
| No skin parameters. | |
| No skin parameters. |
Table A.9. Style classes (selectors) and corresponding skin parameters
Class (selector) | Skin Parameters | Mapped CSS properties |
---|---|---|
| No skin parameters. | |
|
| border-color |
|
| background-color |
| No skin parameters. | |
|
| color |
| font-size | |
| font-family | |
|
| border-color |
| No skin parameters. | |
|
| background-color |
| border-left-color | |
| No skin parameters. | |
| No skin parameters. | |
| No skin parameters. | |
| No skin parameters. | |
| No skin parameters. |
Table A.10. Style classes (selectors) and corresponding skin parameters
Class (selector) | Skin Parameters | Mapped CSS properties |
---|---|---|
|
| background-color |
| color | |
|
| background-color, border-color |
| color | |
| font-size | |
| font-weight | |
| font-family | |
|
| color |
| font-size | |
| font-family |
Table A.11. Style classes (selectors) and corresponding skin parameters
Class (selector) | Skin Parameters | Mapped CSS properties |
---|---|---|
|
| border-color |
| background | |
|
| border-bottom-color |
| background-color | |
| color | |
| font-weight | |
| font-family | |
| font-size | |
| No skin parameters. | |
|
| color |
| No skin parameters. | |
|
| border-bottom-color |
| color | |
| font-family | |
| font-size | |
| No skin parameters. | |
| No skin parameters. | |
| No skin parameters. | |
| No skin parameters. | |
| No skin parameters. |
Table A.12. Style classes (selectors) and corresponding skin parameters
Class (selector) | Skin Parameters | Mapped CSS properties |
---|---|---|
|
| color |
| background | |
|
| background-color, border-color |
| color | |
| font-weight | |
| font-family | |
| font-size | |
| No skin parameters. | |
| No skin parameters. | |
|
| color |
| font-family | |
| font-size | |
| No skin parameters. | |
| No skin parameters. | |
| No skin parameters. | |
| No skin parameters. | |
| No skin parameters. |
Table A.13. Style classes (selectors) and corresponding skin parameters
Class (selector) | Skin Parameters | Mapped CSS properties |
---|---|---|
| No skin parameters. | |
| No skin parameters. | |
|
| border |
| background | |
|
| background |
|
| color |
| font-weight | |
| font-family | |
| font-size | |
|
| color |
| font-family | |
| font-size | |
|
| background |
| No skin parameters. | |
| No skin parameters. |
Table A.14. Style classes (selectors) and corresponding skin parameters
Class (selector) | Skin Parameters | Mapped CSS properties |
---|---|---|
|
| border |
| background-color | |
| color | |
|
| background-color |
| No skin parameters. | |
|
| color |
|
| background-color |
| border-color | |
| No skin parameters. | |
|
| border-bottom |
|
| font-family |
| font-size | |
| No skin parameters. | |
|
| background |
| border | |
| font-family | |
| font-size | |
|
| background |
| border | |
| font-family | |
|
| background |
| border | |
|
| background |
| border | |
| font-family | |
| font-size |
Table A.15. Style classes (selectors) and corresponding skin parameters
Class (selector) | Skin Parameters | Mapped CSS properties |
---|---|---|
|
| background-color |
| border-left-width, border-top-width | |
| border-left-color, border-top-color | |
| No skin parameters. | |
| No skin parameters. | |
| No skin parameters. | |
|
| background-color |
| border-bottom-width, border-right-width | |
| border-bottom-color, border-right-color | |
| color | |
| font-family | |
| font-size | |
|
| border-bottom-width, border-right-width |
| border-bottom-color, border-right-color | |
| color | |
| font-family | |
| font-size | |
| No skin parameters. | |
| No skin parameters. | |
|
| background-color |
| border-bottom-width, border-right-width | |
| border-bottom-color, border-right-color | |
| color | |
| font-family | |
| font-size | |
| No skin parameters. | |
| No skin parameters. | |
|
| background-color |
| border-bottom-width, border-right-width | |
| border-bottom-color, border-right-color | |
| color | |
| font-family | |
| font-size | |
| No skin parameters. | |
| No skin parameters. | |
|
| background-color |
| border-bottom-width, border-right-width | |
| border-bottom-color, border-right-color | |
| color | |
| font-family | |
| font-size | |
| No skin parameters. | |
| No skin parameters. | |
|
| background-color |
| border-bottom-width, border-right-width | |
| border-bottom-color, border-right-color | |
| color | |
| font-family | |
| font-size |
Table A.16. Style classes (selectors) and corresponding skin parameters
Class (selector) | Skin Parameters | Mapped CSS properties |
---|---|---|
| No skin parameters. | |
| No skin parameters. | |
| No skin parameters. | |
|
| background-color |
| border-bottom-width, border-right-width | |
| border-bottom-color, border-right-color | |
| color | |
| font-family | |
| font-size | |
| No skin parameters. | |
| No skin parameters. | |
| No skin parameters. | |
|
| background-color |
| border-bottom-width, border-right-width | |
| border-bottom-color, border-right-color | |
| color | |
| font-family | |
| font-size | |
| No skin parameters. | |
| No skin parameters. | |
|
| background-color |
| border-bottom-width, border-right-width | |
| border-bottom-color, border-right-color | |
| color | |
| font-family | |
| font-size | |
| No skin parameters. | |
| No skin parameters. | |
|
| background-color |
| border-bottom-width, border-right-width | |
| border-bottom-color, border-right-color | |
| color | |
| font-family | |
| font-size | |
| No skin parameters. | |
| No skin parameters. | |
|
| background-color |
| border-bottom-width, border-right-width | |
| border-bottom-color, border-right-color | |
| color | |
| font-family | |
| font-size |
Table A.17. Style classes (selectors) and corresponding skin parameters
Class (selector) | Skin Parameters | Mapped CSS properties |
---|---|---|
|
| border |
| background-color | |
| No skin parameters. | |
|
| border-bottom |
| border-right | |
|
| font-family |
| font-size | |
|
| border-bottom |
| color | |
| font-family | |
| font-size | |
| color | |
| No skin parameters. | |
|
| border-bottom |
| border-right | |
|
| font-family |
| font-size | |
| color | |
|
| border-top |
| background-color | |
|
| border-top |
| background-color | |
| No skin parameters. | |
|
| border-bottom |
| border-right | |
|
| font-family |
| font-size | |
| color | |
|
| border-right |
| No skin parameters. | |
| No skin parameters. | |
|
| border-right |
| No skin parameters. | |
| No skin parameters. | |
| No skin parameters. | |
|
| border-left |
|
| border |
| background-color | |
| No skin parameters. | |
| No skin parameters. |
Table A.18. Style classes (selectors) and corresponding skin parameters
Class (selector) | Skin Parameters | Mapped CSS properties |
---|---|---|
|
| background-color |
| border-left-width, border-top-width | |
| border-left-color, border-top-color | |
| No skin parameters. | |
| No skin parameters. | |
|
| border-bottom-width, border-right-width |
| border-bottom-color, border-right-color | |
| color | |
| font-family | |
| font-size | |
|
| border-bottom-width, border-right-width |
| border-bottom-color, border-right-color | |
| color | |
| font-family | |
| font-size | |
|
| border-bottom-width |
| border-bottom-color | |
| No skin parameters. | |
| No skin parameters. | |
| No skin parameters. | |
|
| background-color |
| border-bottom-width, border-right-width | |
| border-bottom-color, border-right-color | |
| color | |
| font-family | |
| font-size | |
| No skin parameters. | |
| No skin parameters. | |
|
| background-color |
| border-bottom-width, border-right-width | |
| border-bottom-color, border-right-color | |
| color | |
| font-family | |
| font-size |
Table A.19. Style classes (selectors) and corresponding skin parameters
Class (selector) | Skin Parameters | Mapped CSS properties |
---|---|---|
|
| color |
| font-family | |
| font-size | |
|
| color |
| font-family | |
| font-size | |
|
| color |
| font-family | |
| font-size | |
|
| color |
| font-family | |
| font-size |
Table A.20. Style classes (selectors) and corresponding skin parameters
Class (selector) | Skin Parameters | Mapped CSS properties |
---|---|---|
|
| font-family |
| font-size | |
| background | |
|
| color |
| font-family | |
| font-size | |
| border-color | |
| background-color | |
| No skin parameters. | |
| No skin parameters. | |
| No skin parameters. | |
| No skin parameters. | |
| No skin parameters. | |
| No skin parameters. | |
|
| color |
| font-family | |
| font-size | |
| border-color | |
| background-color | |
|
| border-color |
| background | |
|
| color |
|
| color |
Table A.21. Style classes (selectors) and corresponding skin parameters
Class (selector) | Skin Parameters | Mapped CSS properties |
---|---|---|
|
| font-family |
| font-size | |
| No skin parameters. | |
| No skin parameters. | |
|
| background |
|
| background |
| No skin parameters. | |
| No skin parameters. | |
| No skin parameters. | |
| No skin parameters. | |
| No skin parameters. | |
| No skin parameters. | |
| No skin parameters. | |
| No skin parameters. | |
| No skin parameters. | |
| No skin parameters. |
Table A.22. Style classes (selectors) and corresponding skin parameters
Class (selector) | Skin Parameters | Mapped CSS properties |
---|---|---|
|
| font-family |
|
| color |
|
| font-family |
| No skin parameters. | |
| No skin parameters. | |
|
| border-color |
| background-color | |
|
| border-color |
| No skin parameters. | |
|
| font-family |
| font-size | |
|
| border-color |
| background-color | |
| No skin parameters. | |
|
| color |
|
| color |
| No skin parameters. | |
| No skin parameters. | |
|
| border-top-color |
| No skin parameters. |
Table A.23. Style classes (selectors) and corresponding skin parameters
Class (selector) | Skin Parameters | Mapped CSS properties |
---|---|---|
| No skin parameters. | |
|
| border-top-color |
| No skin parameters. | |
| No skin parameters. | |
| No skin parameters. | |
| No skin parameters. | |
|
| border-top-color |
| color | |
| No skin parameters. | |
|
| background-color |
| No skin parameters. | |
|
| color |
| No skin parameters. | |
| No skin parameters. | |
|
| font-size |
| font-family | |
|
| border-top-color |
| No skin parameters. | |
| No skin parameters. | |
|
| color |
|
| background |
|
| color |
| No skin parameters. | |
| No skin parameters. | |
|
| font-size |
| font-family | |
| No skin parameters. | |
|
| border-color |
| color | |
| No skin parameters. | |
|
| color |
| No skin parameters. | |
|
| color |
| No skin parameters. | |
| No skin parameters. | |
|
| font-size |
| font-family | |
|
| border-color |
| No skin parameters. | |
| No skin parameters. | |
|
| color |
| background-color | |
|
| color |
| background-color | |
| No skin parameters. | |
| No skin parameters. | |
|
| font-size |
| font-family | |
| No skin parameters. |
Table A.24. Style classes (selectors) and corresponding skin parameters
Class (selector) | Skin Parameters | Mapped CSS properties |
---|---|---|
|
| border-color |
| color | |
| background-color | |
| font-family | |
| font-size | |
| font-weight | |
| No skin parameters. | |
| No skin parameters. | |
| No skin parameters. | |
| No skin parameters. |
Table A.25. Style classes (selectors) and corresponding skin parameters
Class (selector) | Skin Parameters | Mapped CSS properties |
---|---|---|
|
| font-family |
| font-size | |
|
| color |
|
| color |
|
| color |
|
| color |
|
| color |
| No skin parameters. |
Table A.26. Style classes (selectors) and corresponding skin parameters
Class (selector) | Skin Parameters | Mapped CSS properties |
---|---|---|
|
| font-family |
| font-size | |
|
| color |
|
| color |
|
| color |
|
| color |
|
| color |
| No skin parameters. |
Table A.27. Style classes (selectors) and corresponding skin parameters
Class (selector) | Skin Parameters | Mapped CSS properties |
---|---|---|
| No skin parameters. | |
|
| border-color |
| background-color | |
|
| color |
| font-family | |
| font-size |
Table A.28. Style classes (selectors) and corresponding skin parameters
Class (selector) | Skin Parameters | Mapped CSS properties |
---|---|---|
| No skin parameters. | |
| No skin parameters. | |
| No skin parameters. | |
|
| border-color |
| font-family | |
| font-size |
Style classes (selectors)
This class defines styles for the drag indicator.
This class defines styles for the indicator when it is over an acceptable drop target.
This class defines styles for the indicator when it is over an unacceptable drop target.
This class defines styles for the indicator when it is being dragged, and is not over any drop targets.