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 NameDescription
accesskeyThis 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
alignbottom|middle|top|left|right Deprecated. This attribute specifies the position of an IMG, OBJECT, or APPLET with respect to its context. The following values for align concern the object's position with respect to surrounding text: * bottom: means that the bottom of the object should be vertically aligned with the current baseline. This is the default value. * middle: means that the center of the object should be vertically aligned with the current baseline. * top: means that the top of the object should be vertically aligned with the top of the current text line
archivespace-separated list of URIs
bindingThe attribute takes a value-binding expression for a component property of a backing bean
borderDeprecated. This attribute specifies the width of an IMG or OBJECT border, in pixels. The default value for this attribute depends on the user agent
cacheableIf "true", the resource is cached (on the server and the client sides).
charsetThe character encoding of a resource designated by this hyperlink
classididentifies an implementation
codebasebase URI for classid, data, archive
codetypecontent type for code
converterID of a converter to be used or a reference to a converter.
coordsThis 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
createContentMethod 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 )
createContentExpressionMethod 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 )
declaredeclare but don't instantiate flag
dirDirection indication for text that does not inherit directionality. Valid values are "LTR" (left-to-right) and "RTL" (right-to-left)
elementName of html element for resource link - may be <a> <img> <object> <applet> <script> or <link>
expiresThe attribute allows to manage caching and defines the period after which a resource is reloaded.
hreflangBase language of a resource specified with the href attribute; hreflang may only be used with href
hspaceDeprecated. 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
idEvery component may have a unique id that is automatically created if omitted
ismapuse server-side image map
langCode describing the language used in the generated markup for this component
lastModifiedThe 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.
mimeTypeGeterated content mime-type for append to response header ( 'image/jpeg' etc )
onblurJavaScript 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
onclickHTML: a script expression; a pointer button is clicked
ondblclickHTML: a script expression; a pointer button is double-clicked
onfocusJavaScript code. The onfocus event occurs when an element gets focus
onkeydownHTML: a script expression; a key is pressed down
onkeypressHTML: a script expression; a key is pressed and released
onkeyupHTML: a script expression; a key is released
onmousedownHTML: script expression; a pointer button is pressed down
onmousemoveHTML: a script expression; a pointer is moved within
onmouseoutHTML: a script expression; a pointer is moved away
onmouseoverHTML: a script expression; a pointer is moved onto
onmouseupHTML: script expression; a pointer button is released
relThe 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
renderedIf "false", this component is not rendered
revA 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
sessionIf "true", a session for an object generation is restored.
shapedefault|rect|circle|poly [CI] This attribute specifies the shape of a region. Possible values: * default: Specifies the entire region. * rect: Define a rectangular region. * circle: Define a circular region. * poly: Define a polygonal region.
standbymessage to show while loading
styleCSS style(s) is/are to be applied when this component is rendered
styleClassCorresponds to the HTML class attribute
tabindexThis 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
targetThis 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
titleAdvisory title information about markup elements generated for this component
typeThe content type of the resource designated by this hyperlink
uriAttributeName of attribute for resource-link attribute ( 'href' for <a>, 'src' for <img> or <script>, etc
usemapuse client-side image map
valueData 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.
vspaceDeprecated. 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

NameValue
component-typeorg.ajax4jsf.MediaOutput
component-familyorg.ajax4jsf.Resource
component-classorg.ajax4jsf.component.html.MediaOutput
renderer-typeorg.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

Here you can see the example of <a4j:mediaOutput > usage and sources for the given example.