paint rich:paint2D HtmlPaint2D

Component identification parameters

Name | Value
--- | ---
component-type | org.richfaces.Paint2D
component-class | org.richfaces.component.html.HtmlPaint2D
component-family | javax.faces.Output
renderer-type | org.richfaces.Paint2DRenderer
tag-class | org.richfaces.taglib.Paint2DTag

## Creating the Component with a Page Tag

To create the simplest variant on a page use the following syntax:

Example:

    ...
        <rich:paint2D paint="#{paint2D.paint}" data="#{paint2DModel}"/>
    ...

Here "paint" specifies the method performing drawing and "data" specifies Managed Bean property keeping the data used by the method.

## Creating the Component Dynamically Using Java

Example:

    import org.richfaces.component.html.HtmlPaint2D;
    ...
    HtmlPaint2D myImage = new HtmlPaint2D();
    ...

## Details of Usage

The example shows two main attributes of the component:

- "paint"

  Specify a method receiving an object specified in data as a parameter and sending graphical information into the stream

- "data"

  Specifies a bean class keeping your data for rendering

Note:

Data object should implement serializable interface

The "format" attribute of the component defines a format of visual data passing to the server.

Generated data can be used as a cacheable or non-cacheable resource. It's defined with "cacheable" attribute. If cache support is turned on, a key is created in URI with a mix of size (width/height), `"paint"` method, "format" and "data" attributes.

Example:

    paintBean.java:

          public void paint(Graphics2D g2, Object obj) {
              // code that gets data from the data Bean (PaintData)
              PaintData data = (PaintData) obj;
              ...
              // a code drawing a rectangle
              g2.drawRect(0, 0, data.Width, data.Height);
              ...
              // some more code placing graphical data into g2 stream below
         }

    dataBean.java:

        public class PaintData implements Serializable{
            private static final long serialVersionUID = 1L;
            Integer Width=100;
            Integer Height=50;
            ...
        }

        page.xhtml:
        ...
        <rich:paint2D paint="#{paint2D.paint}" data="#{paint2DModel.data}"/>
        ...

## Look-and-Feel Customization

Paint2D has no skin parameters and special style classes, as it consists of one element generated with a your method on the server.

To define some style properties such as an indent or a border, it's possible to use "style" and "styleClass" attributes on the component.

## Relevant Resources Links

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