Dieser Inhalt ist in der von Ihnen ausgewählten Sprache nicht verfügbar.
RichFaces Developer Guide
for use with JBoss Enterprise Application Platform 5
Edition 5.2.0
Abstract
Chapter 1. Introduction Link kopierenLink in die Zwischenablage kopiert!
- Experience the benefits of JSF while working with AJAX. RichFaces is fully integrated into the JSF life cycle. Where other frameworks only allow access to the managed bean facility, RichFaces lets you access the action and value change listeners, and invokes server-side validators and converters during the AJAX request-response cycle.
- Add AJAX capabilities to existing JSF applications. The RichFaces framework provides two component libraries (Core AJAX and UI). The Core library adds AJAX functionality to existing pages, so you need not write any JavaScript or replace existing components with new AJAX components manually. RichFaces enables page-wide rather than component-wide AJAX support, giving you the opportunity to define events on the page.
- Quickly and easily create different views with a variety of components, available out-of-the-box. The RichFaces UI library contains components for adding rich user interface (UI) features to JSF applications, providing you with a broad variety of AJAX-enabled components with extensive skins support. RichFaces components are designed to integrate seamlessly with other third-party component libraries, so you have more options when you develop applications.
- Write your own rich components with built-in AJAX support. The Component Development Kit (CDK) is constantly being expanded. It includes both code generation and templating facilities and a simple JSP-like (JavaServer Pages) syntax, letting you create first-class rich components with built-in AJAX functionality.
- Package resources with application Java classes. RichFaces provides advanced support for managing different resource types, including images, JavaScript code, and CSS stylesheets. The resource framework makes it easier to include these resources in JAR files with your custom component code.
- Quickly and easily generate binary resources. The resource framework can generate images, sounds, Excel spreadsheets, etc. in real time, so you can, for example, create images with the Java Graphics 2D library and other similar resources.
- Customize the look and feel of your user interface with skins-based technology. RichFaces lets you easily define and manage different color schemes and other user interface parameters by using named skin parameters. This means you can access UI parameters from JSP and Java code to adjust your UI in real time. RichFaces includes a number of predefined skins to kick-start your application's development, but it is easy to create your own custom skins.
- Simultaneously create and test your components, actions, listeners, and pages. RichFaces will soon include an automated testing facility to generate test cases for your component as you develop it. The testing framework tests not only the components, but also any other server-side or client-side functionality, including JavaScript code — and it will do so without deploying the test application into the Servlet container.
Chapter 2. Getting Started with RichFaces Link kopierenLink in die Zwischenablage kopiert!
2.1. Simple JSF application with RichFaces Link kopierenLink in die Zwischenablage kopiert!
Greeter. Include all required libraries, and continue with the instructions that follow.
2.1.1. Adding RichFaces libraries into the project Link kopierenLink in die Zwischenablage kopiert!
RichFaces folder where you unzipped the RichFaces binary files, open the lib. This folder contains three *.jar files with API, UI, and implementation libraries. Copy these JARs from lib to the WEB-INF/lib directory of your Greeter JSF application.
Important
commons-beanutils-1.7.0.jarcommons-collections-3.2.jarcommons-digester-1.8.jarcommons-logging-1.0.4.jarjhighlight-1.0.jar
2.1.2. Registering RichFaces in web.xml Link kopierenLink in die Zwischenablage kopiert!
web.xml file. Add the following to web.xml:
web.xml should look like this:
2.1.3. Managed bean Link kopierenLink in die Zwischenablage kopiert!
JavaSource directory, create a new managed bean named user in the demo package. Place the following code in user:
2.1.4. Registering the bean in faces-config.xml Link kopierenLink in die Zwischenablage kopiert!
user bean, add the following to the faces-config.xml file:
2.1.5. RichFaces Greeter index.jsp Link kopierenLink in die Zwischenablage kopiert!
index.jsp in the root of WEB CONTENT folder and add the following to the JSP file:
Note
<xmlns:a4j="http://richfaces.org/a4j"> <xmlns:rich="http://richfaces.org/rich">
<xmlns:a4j="http://richfaces.org/a4j">
<xmlns:rich="http://richfaces.org/rich">
index.jsp page: http://localhost:8080/Greeter/index.jsf
Figure 2.1. "RichFaces Greeter" application
2.2. Relevant Resources Links Link kopierenLink in die Zwischenablage kopiert!
Chapter 3. Settings for different environments Link kopierenLink in die Zwischenablage kopiert!
lib directory of the project, and add filter mapping. The behavior of the existing project does not change when you add RichFaces.
3.1. Web Application Descriptor Parameters Link kopierenLink in die Zwischenablage kopiert!
web.xml, but the RichFaces parameters listed below will help you during the development process and increase the flexibility of your RichFaces applications.
| Name | Default | Description |
|---|---|---|
| org.richfaces.SKIN | DEFAULT | The name of a skin that is used in an application. Can be a literal string with a skin name or the EL expression (#{...}) associated with a String property (skin name) of a property of a org.richfaces.framework.skin type. In the latter case, that instance is used as the current skin. |
| org.richfaces.LoadScriptStrategy | DEFAULT | Defines how the RichFaces script files are loaded to the application. Possible values are ALL, DEFAULT and NONE. |
| org.richfaces.LoadStyleStrategy | DEFAULT | Defines how the RichFaces style files are loaded into the application. Possible values are: ALL, DEFAULT, or NONE. |
| org.ajax4jsf.LOGFILE | none | The URL of an application or a container log file (if applicable). If this parameter is set, content from the given URL is shown on a Debug page in the iframe window. |
| org.ajax4jsf.VIEW_HANDLERS | none | A comma-separated list of ViewHandler instances for inserting in a view handler chain. These handlers are inserted before the RichFaces viewhandlers, in the order they are listed. In a Facelets application, you would declare com.sun.facelets.FaceletViewHandler here instead of in the faces-config.xml file. |
| org.ajax4jsf.CONTROL_COMPONENTS | none | A comma-separated list of special control case components, such as the messages bundle loader or an alias bean component. These handlers are provided via a reflection from the static field COMPONENT_TYPE. Encoding methods for these components are always called while rendering AJAX responses, even if a component has not been updated. |
| org.ajax4jsf.ENCRYPT_RESOURCE_DATA | false | For generated resources (such as encrypt generation data), this is encoded in the resource URL. For example, the URL of an image generated by the mediaOutput component contains the name of a generation method. Since malicious code can exploit this to create a request for any JSF bean or attribute, this parameter should be set to true in critical applications. (This fix works with Java Runtime Environment 1.4.) |
| org.ajax4jsf.ENCRYPT_PASSWORD | random | A password used to encrypt resource data. If this is not set, a random password is used. |
| org.ajax4jsf.COMPRESS_SCRIPT | true | When defined, does not allow the frameword to reformat JavaScript files. This means that the debug feature cannot be used. |
| org.ajax4jsf.RESOURCE_URI_PREFIX | a4j | Defines the prefix to be added to the URLs of all generated resources. This is designed to handle RichFaces generated resource requests. |
| org.ajax4jsf.GLOBAL_RESOURCE_URI_PREFIX | a4j/g | Defines the prefix to be added to the URI of all global resources. This prefix is designed to handle RichFaces generated resource requests. |
| org.ajax4jsf.SESSION_RESOURCE_URI_PREFIX | a4j/s | Defines the prefix to be used to track the sessions of generated resources. This prefix is designed to handle RichFaces generated resource requests. |
| org.ajax4jsf.DEFAULT_EXPIRE | 86400 | Defines the period (in seconds) for which resources are cached when they are streamed back to the browser. |
| org.ajax4jsf.SERIALIZE_SERVER_STATE | false | If set to true, the component state (not the tree) will be serialized before it is stored in the session. This can be useful in applications with view state that is sensitive to model changes. Alternatively, use com.sun.faces.serializeServerState and org.apache.myfaces.SERIALIZE_STATE_IN_SESSION parameters in their respective environments. |
Note
org.richfaces.SKIN is used in the same way as org.ajax4jsf.SKIN.
| Name | Default | Description |
|---|---|---|
| log4j-init-file | - | A path (relative to the web application's context) to the log4j.xml configuration file. This can be used to set up per-application custom logging. |
| enable-cache | true | Enables caching of framework-generated resources (JavaScript, CSS, images, etc.). However, your cached resources will not be used when attempting to debug custom JavaScript or Styles. |
| forcenotrf | true | Forces all JSF pages to be parsed by a HTML syntax check filter. If set to false, only AJAX responses will be parsed and converted to well-formed XML. Setting this to false can improve performance, but may also cause unexpected information to be rendered during AJAX updates. |
3.2. Sun JSF RI Link kopierenLink in die Zwischenablage kopiert!
3.3. Facelets Support Link kopierenLink in die Zwischenablage kopiert!
ViewHandler be listed first in the ViewHandler chain. RichFaces also requires that its AjaxViewHandler be listed first, but because it is installed first, no settings will need to be altered. Where multiple frameworks are used without RichFaces, you can use the VIEW_HANDLERS parameter to define the order in which the ViewHandlers are used. For example:
Facelets will officially be first, AjaxViewHandler will briefly be ahead of it to perform some small, important task.
Note
FaceletViewHandler in WEB-INF/faces-config.xml.
3.4. JBoss Seam Support Link kopierenLink in die Zwischenablage kopiert!
web.xml must be as follows:
web.xml must look like this:
Chapter 4. Basic concepts of the RichFaces Framework Link kopierenLink in die Zwischenablage kopiert!
4.1. Introduction Link kopierenLink in die Zwischenablage kopiert!
Figure 4.1. Request Processing flow
XMLHTTPRequest objects by hand — everything is done automatically.
4.2. RichFaces Architecture Overview Link kopierenLink in die Zwischenablage kopiert!
Figure 4.2. Core AJAX component structure
To make the most of RichFaces, you should register a Filter in your application's web.xml. The Filter recognizes multiple request types. The sequence diagram in Figure 5.3 shows the differences in processing between a regular JSF request and an AJAX request.
Figure 4.3. Request processing sequence diagram
ResourceBuilder class.
Resource Cache for this resource. If it is present, the resource is returned to the client. Otherwise, the filter searches for the resource among those registered in the ResourceBuilder. If the resource is registered, the RichFaces filter requests that the ResourceBuilder creates (delivers) the resource.
Figure 4.4. Resource request sequence diagram
AJAX Action components are used to send AJAX requests from the client side. There are a number of AJAX Action components, including <a4j:commandButton>, <a4j:commandLink>, <a4j:poll>, and <a4j:support>.
AjaxContainer is an interface that defines an area on your JSF page that should be decoded during an AJAX request. AjaxViewRoot and AjaxRegion are both implementations of this interface.
The RichFaces JavaScript Engine runs on the client side, and updates different areas of your JSF page based on information from the AJAX response. This JavaScript code operates automatically, so there is no need to use it directly.
4.3. Request Errors and Session Expiration Handling Link kopierenLink in die Zwischenablage kopiert!
web.xml:
<context-param> <param-name>org.ajax4jsf.handleViewExpiredOnClient</param-name> <param-value>true</param-value> </context-param>
<context-param>
<param-name>org.ajax4jsf.handleViewExpiredOnClient</param-name>
<param-value>true</param-value>
</context-param>
4.3.1. Request Errors Handling Link kopierenLink in die Zwischenablage kopiert!
A4J.AJAX.onError method like so:
A4J.AJAX.onError = function(req, status, message){
window.alert("Custom onError handler "+message);
}
A4J.AJAX.onError = function(req, status, message){
window.alert("Custom onError handler "+message);
}
req- a parameter string of a request that calls an error
status- the number of an error returned by the server
message- a default message for the given error
4.3.2. Session Expired Handling Link kopierenLink in die Zwischenablage kopiert!
onExpired framework method that is called on the SessionExpiration event.
loc- the URL of the current page (can be updated on demand)
expiredMsg- a default message for display in the event of
SessionExpiration.
Note
onExpire handlers do not work under MyFaces. MyFaces handles exceptions by internally generating a debug page. To prevent this behavior, use the following:
4.4. Skinnability Link kopierenLink in die Zwischenablage kopiert!
4.4.1. Why Skinnability Link kopierenLink in die Zwischenablage kopiert!
skinnability feature cannot completely replace standard CSS, and does not eliminate its usage. Instead, it is a high-level extension of standard CSS that can be used in combination with regular CSS declarations. You can also refer to skin parameters in CSS through the JSF Expression Language. This lets you completely synchronize the appearance of all elements in your pages.
4.4.2. Using Skinnability Link kopierenLink in die Zwischenablage kopiert!
- skin parameters defined in the RichFaces framework,
- predefined CSS classes for components, and
- user style classes.
- A default style class inserted into the framework
This contains style parameters that are linked to some constants from a skin. It is defined for every component and specifies a default level of representation. You can modify an application interface by changing the values of the skin parameters.
- A style class of skin extension
This class name is defined for every component element, and inserted into the framework to let you define a class with the same name in your CSS files. This lets you easily extend the appearance of all components that use this class.
- User style class
You can use one of the
styleClassparameters to define your own class for component elements. As a result, the appearance of one particular component is changed according to a CSS style parameter specified in the class.
4.4.3. Example Link kopierenLink in die Zwischenablage kopiert!
<rich:panel> ... </rich:panel>
<rich:panel> ... </rich:panel>
<div> element and a <div> element for the panel body with the specified style properties. The wrapper <div> element will look like this:
<div class="dr-pnl rich-panel">
...
</div>
<div class="dr-pnl rich-panel">
...
</div>
dr-pnl is a CSS class that is specified in the framework via skin parameters:
background-coloris defined withgeneralBackgroundColorborder-coloris defined withpanelBorderColor
<rich:panel> class on the page, its parameters are also acquired by all panels on this page.
<rich:panel styleClass="customClass" />
<rich:panel styleClass="customClass" />
customClass to one particular panel. As a result, we will get three styles:
<div class="dr_pnl rich-panel customClass"> ... </div>
<div class="dr_pnl rich-panel customClass">
...
</div>
4.4.4. Skin Parameters Tables in RichFaces Link kopierenLink in die Zwischenablage kopiert!
- DEFAULT
- plain
- emeraldTown
- blueSky
- wine
- japanCherry
- ruby
- classic
- deepMarine
org.richfaces.SKIN context parameter.
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 |
| tabBackgroundColor | #C6DEFF |
| tabDisabledTextColor | #8DB7F3 |
| trimColor | #D6E6FB |
| tipBackgroundColor | #FAE6B0 |
| tipBorderColor | #E5973E |
| selectControlColor | #E79A00 |
| generalLinkColor | #0078D0 |
| hoverLinkColor | #0090FF |
| visitedLinkColor | #0090FF |
| Parameter name | Default value |
|---|---|
| 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 |
plain skin was added in version 3.0.2. It has no parameters, and is important when embedding RichFaces components into existing projects with their own styles.
4.4.5. Creating and Using Your Own Skin File Link kopierenLink in die Zwischenablage kopiert!
- Create a file. In it, define skin constants to be used by style classes (see Section 4.4.4, “Skin Parameters Tables in RichFaces”). The name of the skin file should follow this format:
<name>.skin.properties. (For examples of this file, see the RichFaces predefined skin parameters:blueSky,classic,deepMarine, etc. These files are located in therichfaces-impl-xxxxx.jararchive in the/META-INF/skinsfolder. - Add the skin definition
<contex-param>to theweb.xmlof your application, like so:Copy to Clipboard Copied! Toggle word wrap Toggle overflow - Place your
<name>.skin.propertiesfile in either your/META-INF/skinsor/WEB-INF/classesdirectory.
4.4.6. Built-in Skinnability in RichFaces Link kopierenLink in die Zwischenablage kopiert!
- Create a custom render kit and register it in the
faces-config.xmllike so:<render-kit> <render-kit-id>NEW_SKIN</render-kit-id> <render-kit-class>org.ajax4jsf.framework.renderer.ChameleonRenderKitImpl</render-kit-class> </render-kit><render-kit> <render-kit-id>NEW_SKIN</render-kit-id> <render-kit-class>org.ajax4jsf.framework.renderer.ChameleonRenderKitImpl</render-kit-class> </render-kit>Copy to Clipboard Copied! Toggle word wrap Toggle overflow - Next, create and register custom renderers for the component based on the look-and-feel predefined variables:
<renderer> <component-family>javax.faces.Command</component-family> <renderer-type>javax.faces.Link</renderer-type> <renderer-class>newskin.HtmlCommandLinkRenderer</renderer-class> </renderer><renderer> <component-family>javax.faces.Command</component-family> <renderer-type>javax.faces.Link</renderer-type> <renderer-class>newskin.HtmlCommandLinkRenderer</renderer-class> </renderer>Copy to Clipboard Copied! Toggle word wrap Toggle overflow - Finally, place a properties file with skin parameters into the class path root. There are two requirements for the properties file:
- The file must be named
skinName.skin.properties. In this case, we would call itnewskin.skin.properties. - The first line in this file should be
render.kit=render-kit-id. In this case, we would userender.kit=NEW_SKIN.
4.4.7. Changing skin in runtime Link kopierenLink in die Zwischenablage kopiert!
web.xml.
<context-param>
<param-name>org.richfaces.SKIN</param-name>
<param-value>#{skinBean.skin}</param-value>
</context-param>
<context-param>
<param-name>org.richfaces.SKIN</param-name>
<param-value>#{skinBean.skin}</param-value>
</context-param>
skinBean code looks like this:
skin property's initial value in the configuration file. To set classic:
Figure 4.5. Changing skin in runtime
4.4.8. Standard Controls Skinning Link kopierenLink in die Zwischenablage kopiert!
rich-* classes to particular elements, or to a container of elements that nests controls.
Extended is used. However, if you want to explicitly specify the level to be applied, add a org.richfaces.CONTROL_SKINNING_LEVEL context parameter to your web.xml and set the value to either basic or extended.
- The Basic level provides customization for only basic style properties. Basic skinning is applied to the following browsers:
- Internet Explorer 6
- Internet Explorer 7 in BackCompat mode (see document.compatMode property in MSDN)
- Opera
- Safari
- The Extended level introduces a broader number of style properties on top of basic skinning, and is applied to browsers with rich visual styling control capabilities. The following browsers support Extended skinning:
- Mozilla Firefox
- Internet Explorer 7 in Standards-compliant mode (CSS1Compat mode)
inputselecttextareakeygenisindexlegendfieldsethra(together with thea:hover,a:visitedpseudo-elements)
- add the
org.richfaces.CONTROL_SKINNINGparameter toweb.xml.org.richfaces.CONTROL_SKINNINGtakesenableanddisableas parameters. This method implies that skinning style properties are applied per-element and attribute type (where applicable). No additional steps are required. See the Section 4.4.8.1, “Standard Level” and Section 4.4.8.2, “Extended level” tables for elements to which skinning can be applied. - add the
org.richfaces.CONTROL_SKINNING_CLASSESparameter toweb.xml.org.richfaces.CONTROL_SKINNING_CLASSEStakesenableanddisableas parameters. When enabled, you are provided with a set of predefined CSS classes to apply skins to your HTML components.
org.richfaces.CONTROL_SKINNING_CLASSES provides you style classes that can be applied to:
- basic elements nested within elements with a rich-container class. For example:
... .rich-container select { //class content } ...... .rich-container select { //class content } ...Copy to Clipboard Copied! Toggle word wrap Toggle overflow - Elements with a class name that corresponds to one of the basic element names or types are mapped with the
rich-<elementName>[-<elementType>]scheme, as in the following example:Copy to Clipboard Copied! Toggle word wrap Toggle overflow Note
Elements are given classes depending upon theirlinktype and pseudo-class name, for example,rich-link,rich-link-hover,rich-link-visited
ui/core/src/main/resources/org/richfaces/ directory of the RichFaces SVN repository.
4.4.8.1. Standard Level Link kopierenLink in die Zwischenablage kopiert!
| CSS Properties | Skin Parameters |
|---|---|
| font-size | generalSizeFont |
| font-family | generalFamilyFont |
| color | controlTextColor |
| CSS Properties | Skin Parameters |
|---|---|
| border-color | panelBorderColor |
| CSS Properties | Skin Parameters |
|---|---|
| border-color | panelBorderColor |
| CSS Properties | Skin Parameters |
|---|---|
| color | generalLinkColor |
| CSS Properties | Skin Parameters |
|---|---|
| color | hoverLinkColorgeneralLinkColor |
| CSS Properties | Skin Parameters |
|---|---|
| color | visitedLinkColor |
| CSS Properties | Skin Parameters |
|---|---|
| font-size | generalSizeFont |
| font-family | generalFamilyFont |
| color | controlTextColor |
| CSS Properties | Skin Parameters |
|---|---|
| border-color | panelBorderColor |
| CSS Properties | Skin Parameters |
|---|---|
| border-color | panelBorderColor |
| border-width | 1px |
| border-style | solid |
| CSS Properties | Skin Parameters |
|---|---|
| color | generalLinkColor |
| CSS Properties | Skin Parameters |
|---|---|
| color | hoverLinkColor |
| CSS Properties | Skin Parameters |
|---|---|
| color | visitedLinkColor |
| CSS Properties | Skin parameters/Value |
|---|---|
| border-width | 1px |
| border-style | inset |
| border-color | panelBorderColor |
| background-color | controlBackgroundColor |
| background-repeat | no-repeat |
| background-position | 1px 1px |
| CSS Properties | Skin Parameters |
|---|---|
| border-width | 1px |
| border-style | inset |
| border-color | panelBorderColor |
| background-color | editBackgroundColor |
| CSS Properties | Skin Parameters |
|---|---|
| border-width | 1px |
| border-style | inset |
| border-color | panelBorderColor |
| background-color | warningBackgroundColor |
| background-repeat | no-repeat |
| background-position | center left |
| padding-left | 7px |
| CSS Properties | Skin Parameters |
|---|---|
| border-width | 1px |
| border-style | solid |
| border-color | panelBorderColor |
| background-color | trimColor |
| padding | 2px 10px 2px 10px |
| text-align | center |
| cursor | pointer |
| background-repeat | repeat-x |
| background-position | top left |
| CSS Properties | Skin Parameters |
|---|---|
| background-position | bottom left |
| CSS Properties | Skin Parameters |
|---|---|
| border-color | panelBorderColor |
| border-width | 1px |
| border-style | solid |
| padding | 10px |
| padding | 10px |
| CSS Properties | Skin Parameters |
|---|---|
| font-size | generalSizeFont |
| font-family | generalFamilyFont |
| color | controlTextColor |
| font-weight | bold |
| CSS Properties | Skin Parameters |
|---|---|
| padding | 0px |
| margin | 0px |
4.4.8.2. Extended level Link kopierenLink in die Zwischenablage kopiert!
| CSS Properties | Skin Parameters |
|---|---|
| border-width | 1px |
| border-color | panelBorderColor |
| color | controlTextColor |
| CSS Properties | Skin Parameters |
|---|---|
| border-color | panelBorderColor |
| font-size | generalSizeFont |
| font-family | generalFamilyFont |
| color | headerTextColor |
| background-color | headerBackgroundColor |
| background-image | org.richfaces.renderkit.html.images.ButtonBackgroundImage |
| CSS Properties | Skin Parameters |
|---|---|
| border-color | panelBorderColor |
| font-size | generalSizeFont |
| font-family | generalFamilyFont |
| color | headerTextColor |
| background-color | headerBackgroundColor |
| background-image | org.richfaces.renderkit.html.images.ButtonBackgroundImage |
| CSS Properties | Skin Parameters |
|---|---|
| color | tabDisabledTextColor |
| border-color | tableFooterBackgroundColor |
| background-color | tableFooterBackgroundColor |
| background-image | org.richfaces.renderkit.html.images.ButtonDisabledBackgroundImage |
| CSS Properties | Skin Parameters |
|---|---|
| color | tabDisabledTextColor |
| background-color | tableFooterBackgroundColor |
| border-color | tableFooterBackgroundColor |
| background-image | org.richfaces.renderkit.html.images.ButtonDisabledBackgroundImage |
| CSS Properties | Skin Parameters |
|---|---|
| color | tabDisabledTextColor |
| border-color | tableFooterBackgroundColor |
| background-color | tableFooterBackgroundColor |
| CSS Properties | Skin Parameters |
|---|---|
| border-color | panelBorderColor |
| font-size | generalSizeFont |
| font-family | generalFamilyFont |
| color | controlTextColor |
| background-color | controlBackgroundColor |
| background-image | org.richfaces.renderkit.html.images.InputBackgroundImage |
| CSS Properties | Skin Parameters |
|---|---|
| border-color | panelBorderColor |
| font-size | generalSizeFont |
| font-family | generalFamilyFont |
| color | controlTextColor |
| background-color | controlBackgroundColor |
| background-image | org.richfaces.renderkit.html.images.InputBackgroundImage |
| CSS Properties | Skin Parameters |
|---|---|
| color | tableBorderColor |
| CSS Properties | Skin Parameters |
|---|---|
| color | tableBorderColor |
| CSS Properties | Skin Parameters |
|---|---|
| color | tableBorderColor |
Note
ajaxPortlet is configured as follows:
4.4.9. Client-side Script for Extended Skinning Support Link kopierenLink in die Zwischenablage kopiert!
org.richfaces.LoadStyleStrategy parameter to NONE in your web.xml file, like so:
skinning.js client script is added to the RichFaces library. This detects the browser type and enables extended skinning only for browsers that fully support it.
<script type="text/javascript"> window.RICH_FACES_EXTENDED_SKINNING_ON = true; </script>
<script type="text/javascript">
window.RICH_FACES_EXTENDED_SKINNING_ON = true;
</script>
media attribute in the link tag. This adds the extended_both.xcss style sheet to rich-extended-skinning.
<link href='/YOUR_PROJECT_NAME/a4j_3_2_2-SNAPSHOTorg/richfaces/renderkit/html/css/basic_both.xcss/DATB/eAF7sqpgb-jyGdIAFrMEaw__.jsf' type='text/css' rel='stylesheet' class='component' /> <link media='rich-extended-skinning' href='/ YOUR_PROJECT_NAME /a4j_3_2_2-SNAPSHOTorg/richfaces/renderkit/html/css/extended_both.xcss/DATB/eAF7sqpgb-jyGdIAFrMEaw__.jsf' type='text/css' rel='stylesheet' class='component' /> <link href='/ YOUR_PROJECT_NAME /a4j_3_2_2-SNAPSHOT/org/richfaces/skin.xcss/DATB/eAF7sqpgb-jyGdIAFrMEaw__.jsf' type='text/css' rel='stylesheet' class='component' />
<link href='/YOUR_PROJECT_NAME/a4j_3_2_2-SNAPSHOTorg/richfaces/renderkit/html/css/basic_both.xcss/DATB/eAF7sqpgb-jyGdIAFrMEaw__.jsf' type='text/css' rel='stylesheet' class='component' />
<link media='rich-extended-skinning' href='/ YOUR_PROJECT_NAME /a4j_3_2_2-SNAPSHOTorg/richfaces/renderkit/html/css/extended_both.xcss/DATB/eAF7sqpgb-jyGdIAFrMEaw__.jsf' type='text/css' rel='stylesheet' class='component' />
<link href='/ YOUR_PROJECT_NAME /a4j_3_2_2-SNAPSHOT/org/richfaces/skin.xcss/DATB/eAF7sqpgb-jyGdIAFrMEaw__.jsf' type='text/css' rel='stylesheet' class='component' />
Note
! instead of ., so remember to use the a4j/versionXXX resources prefix instead of a4j_versionXXX.
4.4.10. XCSS File Format Link kopierenLink in die Zwischenablage kopiert!
< u:selector > and < u:style> XML tags, which define the mapping structure, as in the following example:
name attribute of <u:selector> defines the CSS selector, while the name attribute of the <u:style> tag defines the skin constant that is mapped to a CSS property. You can also use the value attribute of the <u:style> tag to assign a value to a CSS property.
... <u:selector name=".rich-ordering-control-disabled, .rich-ordering-control-top, .rich-ordering-control-bottom, .rich-ordering-control-up, .rich-ordering-control-down"> <u:style name="border-color" skin="tableBorderColor" /> </u:selector> ...
...
<u:selector name=".rich-ordering-control-disabled, .rich-ordering-control-top, .rich-ordering-control-bottom, .rich-ordering-control-up, .rich-ordering-control-down">
<u:style name="border-color" skin="tableBorderColor" />
</u:selector>
...
4.4.11. Plug-n-Skin Link kopierenLink in die Zwischenablage kopiert!
archetypeVersion— indicates the RichFaces version; for example,3.3.1.GAartifactId— the artifact ID of the projectgroupId— the group ID of the projectversion— the version of the project you create. By default, this is set to1.0.-SNAPSHOT
ARTIFACT-ID. The directory contains a template of the Maven project.
pom.xml file.)
... mvn cdk:add-skin -Dname=SKIN-NAME -Dpackage=SKIN-PACKAGE ...
...
mvn cdk:add-skin -Dname=SKIN-NAME -Dpackage=SKIN-PACKAGE
...
name— defines the name of the new skinpackage— the base package of the skin. By default, the project'sgroupIdis used.
baseSkin— defines the name of the base skin.createExt— if set totrue, extended CSS classes are added. For more information, please, see Section 4.4.8, “Standard Controls Skinning”.
mvn cdk:add-skin -Dname=SKIN-NAME -Dpackage=SKIN-PACKAGE Command” for which files are created by the command.
|
File Name
|
Location
|
Description
|
|---|---|---|
BaseImage.java
| \src\main\java\SKIN-PACKAGE\SKIN-NAME\images\
|
the base class used to store images.
|
|
BaseImageTest.java
| \src\test\java\SKIN-PACKAGE\SKIN-NAME\images\
|
a test version of a class that stores images.
|
|
XCSS files
| \src\main\resources\SKIN-PACKAGE\SKIN-NAME\css\
|
define the new look of RichFaces components affected by the new skin.
|
SKIN-NAME.properties
| \src\main\resources\SKIN-PACKAGE\SKIN-NAME\css\
|
a file that contains the new skin's properties.
The following properties are used to configure the
SKIN-NAME.properties file:
|
SKIN-NAME.xcss
| src\main\resources\META-INF\skins
|
an XCSS file that imports the component's XCSS files to be modified by the new skin.
|
|
XCSS files
| \src\main\resources\SKIN-PACKAGE\SKIN-NAME\css\
|
determine styles for standard controls (
extended_classes.xcss and extended.xcss), if the createExt key is set to true.
|
SKIN-NAME-ext.xcss
| src\main\resources\META-INF\skins.
|
imports defining styles for standard controls if
createExt is set to true.
|
SKIN-NAME-resources.xml
| src\main\config\resources.
|
contains descriptions of all files listed previously.
|
\src\main\resources\SKIN-PACKAGE\SKIN-NAME\css\. Assign new style properties to your selectors (listed in the XCSS files) in either of the following ways:
- Standard CSS coding approach (that is, add CSS properties to the selectors). Remember that the selectors must be within
<f:verbatim> </f:verbatim>tags. For example:... .rich-calendar-cell { background: #537df8; } ...... .rich-calendar-cell { background: #537df8; } ...Copy to Clipboard Copied! Toggle word wrap Toggle overflow - XCSS coding approach (the usual method of creating XCSS files in RichFaces). XCSS tags must be placed outside
<f:verbatim> </f:verbatim>tags.Copy to Clipboard Copied! Toggle word wrap Toggle overflow
pom.xml file):
... mvn clean install ...
...
mvn clean install
...
background-image CSS property is defined with <f:resource f:key="org.richfaces.renderkit.html.CustomizeableGradient">, which sets the gradient. The gradient type can be specified in the SKIN-NAME.properties with the gradientType property, which can be set to glass, plastic, or plain. The gradient can then be adjusted with the baseColor, gradientColor, gradientHeight, valign attributes, as seen in the previous code snippet.
web.xml file, and placing the JAR file containing your skin (located in the target directory of your skin project) in the \WebContent\WEB-INF\lib\.
4.4.11.1. Details of Usage Link kopierenLink in die Zwischenablage kopiert!
P-n-S directory to view the files and folders created.
mvn cdk:add-skin -DbaseSkin=blueSky -DcreateExt=true -Dname=PlugnSkinDemo -Dpackage=SKINPACKAGE
mvn cdk:add-skin -DbaseSkin=blueSky -DcreateExt=true -Dname=PlugnSkinDemo -Dpackage=SKINPACKAGE
-DbaseSkin defines the RichFaces built-in skin to use as a base, and -DcreateExt=true, which determines that the new skin will include XCSS files that unify the appearance of the rich components and the standard HTML controls.
<rich:calendar> style attributes and some basic HTML controls. We will show you how to:
- Recolor the background of the current day in the
<rich:calendar>; - Recolor a standard HTML submit button;
<rich:properties>'s style properties, you must open the calendar.xcss file, located in P-n-S\src\main\resources\skinpackage\plugnskindemo\css\.
calendar.xcss file, find the .rich-calendar-today selector and amend it as follows:background-color: #075ad1;. This will change the background color of the current day.
extended.xcss file from the P-n-S\src\main\resources\skinpackage\plugnskindemo\css\ directory and insert font-weight: bold; between the curly braces of these selectors, like so:
button[type="button"], button[type="reset"], button[type="submit"], input[type="reset"], input[type="submit"], input[type="button"] {
font-weight: bold;
}
button[type="button"], button[type="reset"], button[type="submit"], input[type="reset"], input[type="submit"], input[type="button"] {
font-weight: bold;
}
PlugnSkinDemo skin and importing it into the project.
mvn clean install from the P-n-S directory. This creates a target directory containing a JAR file with a newly-compiled skin. In our case, the file is named P-n-S-1.0.-SNAPSHOT.jar.
PlugnSkinDemo skin into your project:
- Copy the
P-n-S-1.0.-SNAPSHOT.jarfile to the\WebContent\WEB-INF\lib\directory. - Add the name of the new skin to the
web.xmlfile, like so:<context-param> <param-name>org.ajax4jsf.SKIN</param-name> <param-value>PlugnSkinDemo</param-value> </context-param>
<context-param> <param-name>org.ajax4jsf.SKIN</param-name> <param-value>PlugnSkinDemo</param-value> </context-param>Copy to Clipboard Copied! Toggle word wrap Toggle overflow
web.xml. Add the following to enable standard controls skinning:
<context-param> <param-name>org.richfaces.CONTROL_SKINNING</param-name> <param-value>enable</param-value> </context-param>
<context-param>
<param-name>org.richfaces.CONTROL_SKINNING</param-name>
<param-value>enable</param-value>
</context-param>
Figure 4.6. Plug-n-Skin feature in action.
4.5. State Manager API Link kopierenLink in die Zwischenablage kopiert!
Confirm) is displayed, and button labels and methods are changed when the user clicks the To register link:
Figure 4.7. Login Dialog
Figure 4.8. Register Dialog
States class interfaces with a map, where the keySet defines the State name and the entrySet is a State map. The State map defines the properties, method bindings, or constant state variables of a key or object, where these values may change depending on the active State.
Figure 4.9. RichFaces State API
States. The API implements changes in State through standard JSF navigation. When the action component returns an outcome, the JSF navigation handler (extended through the RichFaces State API) checks whether the outcome is registered as a State change outcome. If true, the corresponding State is activated. If false, standard navigation handling is called.
- Register the State Navigation Handler and the EL Resolver in your
faces-config.xmlfile:Copy to Clipboard Copied! Toggle word wrap Toggle overflow - Register an additional application factory in the
faces-config.xml:... <factory> <application-factory>org.richfaces.ui.application.StateApplicationFactory</application-factory> </factory> ...
... <factory> <application-factory>org.richfaces.ui.application.StateApplicationFactory</application-factory> </factory> ...Copy to Clipboard Copied! Toggle word wrap Toggle overflow - Register two managed beans in the
faces-config.xml:Copy to Clipboard Copied! Toggle word wrap Toggle overflow One bean (config) defines and storesStateas seen in the following example:Copy to Clipboard Copied! Toggle word wrap Toggle overflow The second bean, with theorg.richfaces.ui.model.Statestype (state), contains the managed property states, which is bound to the firstconfigbean. - Next, use state bindings on the page, as in the following example:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
4.6. Identifying User Roles Link kopierenLink in die Zwischenablage kopiert!
rich:isUserInRole(Object) function. This function takes a String or a comma-delineated list of Strings, a Collection, etc. as arguments and returns a Boolean value.
admin) in your web.xml file. Then implement authorization that assigns the admin role to the user that has logged in as an administrator. Once this has been done, you can use the rich:isUserInRole(Object) function with the rendered attribute of any component. For example:
...
<rich:editor value="#{bean.text}" rendered="#{rich:isUserInRole('admin')}" />
...
...
<rich:editor value="#{bean.text}" rendered="#{rich:isUserInRole('admin')}" />
...
admin role can see the text editor, which will not be rendered for users with other roles.
Appendix A. Revision History Link kopierenLink in die Zwischenablage kopiert!
| Revision History | |||
|---|---|---|---|
| Revision 5.2.0-100.400 | 2013-10-31 | ||
| |||
| Revision 5.2.0-100 | Wed 23 Jan 2013 | ||
| |||
| Revision 5.1.2-100 | Thu 8 December 2011 | ||
| |||