### 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.14. < a4j:mediaOutput >

### 6.14.1. Description

The <a4j:mediaOutput> component implements one of the basic features specified in the framework. The component is a facility for generating images, video, sounds and other binary resources defined by you on-the-fly.

Table 6.27. a4j : mediaOutput attributes

Attribute Name | Description
--- | ---
accesskey | This attribute assigns an access key to an element. An access key is a single character from the document character set. Note: Authors should consider the input method of the expected reader when specifying an accesskey
align | Deprecated. This attribute specifies the position of an IMG, OBJECT, or APPLET with respect to its context. The possible values are "bottom", "middle", "top", "left" and "right". The default value is "middle".
archive | space-separated list of URIs
binding | The attribute takes a value-binding expression for a component property of a backing bean
border | Deprecated. This attribute specifies the width of an IMG or OBJECT border, in pixels. The default value for this attribute depends on the user agent
cacheable | If "true", the resource is cached (on the server and the client sides).
charset | The character encoding of a resource designated by this hyperlink
classid | identifies an implementation
codebase | base URI for classid, data, archive
codetype | content type for code
converter | ID of a converter to be used or a reference to a converter.
coords | This attribute specifies the position and shape on the screen. The number and order of values depends on the shape being defined. Possible combinations: * rect: left-x, top-y, right-x, bottom-y. * circle: center-x, center-y, radius. Note. When the radius value is percentage value, user agents should calculate the final radius value based on the associated object's width and height. The radius should be the smaller value of the two. * poly: x1, y1, x2, y2, ..., xN, yN. The first x and y coordinate pair and the last should be the same to close the polygon. When these coordinate values are not the same, user agents should infer an additional coordinate pair to close the polygon. Coordinates are relative to the top, left corner of the object. All values are lengths. All values are separated by commas
createContent | Method call expression to send generated resource to OutputStream. It must have two parameter with a type of java.io.OutputStream and java.lang.Object ( deserialized value of data attribute )
createContentExpression | Method call expression to send generated resource to OutputStream. It must have two parameter with a type of java.io.OutputStream and java.lang.Object ( deserialized value of data attribute )
declare | declare but don't instantiate flag
dir | Direction indication for text that does not inherit directionality. Valid values are "LTR" (left-to-right) and "RTL" (right-to-left)
element | Name of html element for resource link - may be <a> <img> <object> <applet> <script> or <link>
expires | The attribute allows to manage caching and defines the period after which a resource is reloaded.
hreflang | Base language of a resource specified with the href attribute; hreflang may only be used with href
hspace | Deprecated. This attribute specifies the amount of white space to be inserted to the left and right of an IMG, APPLET, or OBJECT. The default value is not specified, but is generally a small, non-zero length
id | Every component may have a unique id that is automatically created if omitted
ismap | use server-side image map
lang | Code describing the language used in the generated markup for this component
lastModified | The attribute allows to manage caching. A browser can send request with the header "If-Modified-Since" for necessity of object reloading. If time of modification is earlier, then the framework doesn't call generation and return code 304.
mimeType | Geterated content mime-type for append to response header ( 'image/jpeg' etc )
onblur | JavaScript code. The onblur event occurs when an element loses focus either by the pointing device or by tabbing navigation. It may be used with the same elements as onfocus
onclick | HTML: a script expression; a pointer button is clicked
ondblclick | HTML: a script expression; a pointer button is double-clicked
onfocus | JavaScript code. The onfocus event occurs when an element gets focus
onkeydown | HTML: a script expression; a key is pressed down
onkeypress | HTML: a script expression; a key is pressed and released
onkeyup | HTML: a script expression; a key is released
onmousedown | HTML: script expression; a pointer button is pressed down
onmousemove | HTML: a script expression; a pointer is moved within
onmouseout | HTML: a script expression; a pointer is moved away
onmouseover | HTML: a script expression; a pointer is moved onto
onmouseup | HTML: script expression; a pointer button is released
rel | The relationship from the current document to the anchor specified by this hyperlink. The value of this attribute is a space-separated list of link types
rendered | If "false", this component is not rendered
rev | A reverse link from the anchor specified by this hyperlink to the current document. The value of this attribute is a space-separated list of link types
session | If "true", a session for an object generation is restored.
shape | This attribute specifies the shape of a region. The possible values are "default", "rect", "circle" and "poly".
standby | message to show while loading
style | CSS style(s) is/are to be applied when this component is rendered
styleClass | Corresponds to the HTML class attribute
tabindex | This attribute specifies the position of the current element in the tabbing order for the current document. This value must be a number between 0 and 32767. User agents should ignore leading zeros
target | This attribute specifies the name of a frame where a document is to be opened. By assigning a name to a frame via the name attribute, authors can refer to it as the "target" of links defined by other elements
title | Advisory title information about markup elements generated for this component
type | The content type of the resource designated by this hyperlink
uriAttribute | Name of attribute for resource-link attribute ( 'href' for <a>, 'src' for <img> or <script>, etc)
usemap | use client-side image map
value | Data value calculated at render time and stored in URI (also as part of cache Key ), at generation time passed to send method. Can be used for update cache at change of generating conditions, and for creating beans as "Lightweight" pattern components (request scope). IMPORTANT: Since serialized data stored in URI, avoid using big objects.
vspace | Deprecated. This attribute specifies the amount of white space to be inserted above and below an IMG, APPLET, or OBJECT. The default value is not specified, but is generally a small, non-zero length

Table 6.28. Component identification parameters

Name | Value
--- | ---
component-type | org.ajax4jsf.MediaOutput
component-family | org.ajax4jsf.Resource
component-class | org.ajax4jsf.component.html.MediaOutput
renderer-type | org.ajax4jsf.MediaOutputRenderer

### 6.14.2. Creating on a page

Component definition on a page for graphical data output

Example:

    ...

    <a4j:mediaOutput element="img" cacheable="false" session="true"

        createContent="#{paintBean.paint}" value="#{paintData}"

        mimeType="image/jpeg"/>

    ...

### 6.14.3. Creating the Component Dynamically Using Java

Example:

    import org.ajax4jsf.component.html.MediaOutput;

    ...

    MediaOutput myMedia = new MediaOutput ();

    ...

### 6.14.4. Key attributes and ways of usage

To use the component it's necessary to define it on a page and set Java methods for data keeping and data transmission to output stream.

Here is the content of `paintData` that is a bean containing output data

Example:

    package demo;

    public class PaintData implements Serializable{

            private static final long serialVersionUID = 1L;

            Integer width=100;

            Integer weight=50;

    ...

The Paint method of the `paintBean` class is a method transmitting graphical data into output stream.

Example:

    public void paint(OutputStream out, Object data) throws IOException{

        <!--...Some code that puts binary data to "out" Stream-->

            }

As it was shown in the example above there are two main components:

- "createContent" specifies a method accepting 2 parameters. The first (of `java.io.OutputStream` type) defines a stream, where any binary data is output. The second (of `java.lang.Object` type) contains deserialized object with data specified in the "value" attribute.

- Value specifies a bean class keeping data for transmitting into a method that transmits it into a stream.

## Note:

A bean class transmitted into value should `implement Serializable` interface.

Hence, when using the component it's possible to output your data of any type on a page with Ajax requests.

### 6.14.5. Relevant resources links

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

- Prev6.13. < a4j:log >
- Top of page
- Front page
- Next6.15. < a4j:outputPanel >