rich:colorPicker colorPicker

Component identification parameters

Name | Value
--- | ---
component-type | org.richfaces.ColorPicker
component-class | org.richfaces.component.html.HtmlColorPicker
component-family | org.richfaces.ColorPicker
renderer-type | org.richfaces.ColorPickerRenderer
tag-class | org.richfaces.taglib.ColorPickerTag

## Creating the Component with a Page Tag

Here is a simple example of how the component can be used on a page:

Example:

    ...
    <rich:colorPicker value="#{bean.color}" />
    ...

## Creating the Component Dynamically Using Java

Example:

    import org.richfaces.component.html.colorPicker;
    ...
    HtmlColorPicker myColorPicker = new ColorPicker();
    ...

## Details of Usage

The <rich:colorPicker> component allows you easily select a color or define it in hex, RGB, or HSB input fields. There are two squares in the widget that help you to compare the currently selected color and the already selected color.

The "value" attribute stores the selected color.

The value of the <rich:colorPicker> component could be saved in hex or RGB color models. You can explicitly define a color model in the "colorMode" attribute.

Example:

    ...
    <rich:colorPicker value="#{bean.color}" colorMode="rgb" />
    ...

This is the result:

Usage of the "colorMode" attribute.

The <rich:colorPicker> component has two representation states: flat and inline. With the help of the "flat" attribute you can define whether the component is rendered flat.

Example:

    ...
    <rich:colorPicker value="#{bean.color}" flat="true" />
    ...

The component specific event handler "onbeforeshow" captures the event which occurs before the <rich:colorPicker> widget is opened. The "onbeforeshow" attribute could be used in order to cancel this event. See the example below:

    ...
    <rich:colorPicker value="#{bean.color}" onbeforeshow="if (!confirm('Are you sure you want to change a color?')){return false;}" />
    ...

The "showEvent" attribute defines the event that shows <rich:colorPicker> widget. The default value is "onclick".

The <rich:colorPicker> component allows to use the "icon" facet.

You can also customize <rich:colorPicker> rainbow slider ( ) with the help of the "arrows" facet.

    ...
    <rich:colorPicker value="#{bean.color}">
    	<f:facet name="icon">
    		<h:graphicImage value="/pages/colorPicker_ico.png" />
    	</f:facet>
    	<f:facet name="arrows">
    		<f:verbatim>
    			<div style="width: 33px; height: 5px; border: 1px solid #bed6f8; background:none;" />
    		</f:verbatim>
    	</f:facet>
    </rich:colorPicker>
    ...

This is the result:

Usage of the "icon" , and "arrows" facets

## Look-and-Feel Customization

For skinnability implementation, the components use a style class redefinition method. Default style classes are mapped on skin parameters.

There are two ways to redefine the appearance of all <rich:colorPicker> components at once:

- Redefine the corresponding skin parameters

- Add style classes used by a <rich:colorPicker> component to your style sheets

## Skin Parameters Redefinition

Skin parameters redefinition for the input field that contains selected color

Skin parameters | CSS properties
--- | ---
panelBorderColor | border-color
generalSizeFont | font-size
generalFamilyFont | font-family

Skin parameters redefinition for the wrapper <div> element of a widget

Skin parameters | CSS properties
--- | ---
panelBorderColor | border-color
generalBackgroundColor | background-color
generalFamilyFont | font-family

Skin parameters redefinition for the icon, color palette, current color, and new color

Skin parameters | CSS properties
--- | ---
panelBorderColor | border-color

Skin parameters redefinition for the hex, RGB, and HSB input fileds

Skin parameters | CSS properties
--- | ---
generalSizeFont | font-size
generalFamilyFont | font-family
generalTextColor | color
panelBorderColor | border-color
controlBackgroundColor | background-color

Skin parameters redefinition for the "Apply" and "Cancel" button

Skin parameters | CSS properties
--- | ---
buttonFontSize | font-size
buttonFamilyFont | font-family
headerTextColor | color
headerBackgroundColor | border-color
panelBorderColor | border-color
generalSizeFont | font-size
generalFamilyFont | font-family
headerBackgroundColor | background-color

## Definition of Custom Style Classes

On the screenshot there are classes names that define styles for component elements.

Classes names

Classes names for the representation of the input field and icon containing selected color

Selector name | Description
--- | ---
.rich-colorPicker-span input | Defines styles for the input field that contains selected color
.rich-colorPicker-icon | Defines styles for the icon

Classes names for the widget

Class name | Description
--- | ---
.rich-colorPicker-ext | Defines styles for the wrapper <div> element of a widget
.rich-colorPicker-color | Defines styles for the color palette
.rich-colorPicker-current-color | Defines styles for the currently selected color
.rich-colorPicker-new-color | Defines styles for the already selected color
.rich-colorPicker-colors-input | Defines styles for the hex, RGB, and HSB input fileds

Classes names for the buttons representation

Class name | Description
--- | ---
.rich-colorPicker-submit | Defines styles for the "Apply" button
.rich-colorPicker-cancel | Defines styles for the "Cancel" button

In order to redefine styles for all <rich:colorPicker> components on a page using CSS, it's enough to create classes with the same names (possible classes could be found in the tables above) and define necessary properties in them.

Example:

    ...
    .rich-colorPicker-ext{
        background-color: #ecf4fe;
    }
    ...

This is the result:

Redefinition styles with predefined classes

In the shown example the background color for the widget is changed.

## Relevant Resources Links

On the component LiveDemo page you can see the example of <rich:colorPicker> component usage and sources for the given example.