6.10.2. < rich:paint2D > available since 3.0.0

### Create new RichFaces Documentation Jira issue

Summary
255 characters left
Description
Environment
This will launch the RichFaces Jira page - to complete your feedback please login if needed, and submit the Jira.

JBoss.org Community Documentation

- Prev
- Next

### 6.10.2. < rich:paint2D > available since 3.0.0

expand all

#### 6.10.2.1. Description

Create image by painting from a managed bean method, same as "paint" (Graphics2D) in "SWING" components.

Figure 6.78. <rich:paint2D> component

#### 6.10.2.2. Key Features

- Simple Graphics2D - painting style directly on the Web page

- Supports client/server caching for generated images

- Fully supports "JPEG" (24-bit, default), "GIF" (8-bit with transparency), and "PNG" (32-bit with transparency) formats for sending generated images

- Easily customizable borders and white space to wrap the image

- Dynamically settable paint parameters using tag attributes

#### 6.10.2.3. 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:

    ...

    &lt;rich:paint2D paint="#{paint2D.paint}" data="#{paint2DModel.data}"/&gt;

    ...

#### 6.10.2.4. Reference Data

Table of <rich:paint2D> attributes.

Table 6.109. 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

#### 6.10.2.5. Relevant Resources Links

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

- Prev6.10.1. <rich:modalPanel> available since 3.0.0
- Top of page
- Front page
- Next6.10.3. < rich:panel > available since 3.0.0