<?xml version='1.0' encoding='UTF-8'?>
<chapter>
  <chapterinfo>
    <keywordset>
      <keyword>a4j:mediaOutput</keyword>
    </keywordset>
  </chapterinfo>
     <table>
	  <title>Component identification parameters </title>
      <tgroup cols="2">
	  <thead>
            <row>
                  <entry>Name</entry>
                  <entry>Value</entry>
            </row>
        </thead>
        <tbody>
          <row>
            <entry>component-type</entry>
            <entry>org.ajax4jsf.MediaOutput</entry>
          </row>
          <row>
            <entry>component-family</entry>
            <entry>org.ajax4jsf.Resource</entry>
          </row>
          <row>
            <entry>component-class</entry>
            <entry>org.ajax4jsf.component.html.MediaOutput</entry>
          </row>
          <row>
            <entry>renderer-type</entry>
            <entry>org.ajax4jsf.MediaOutputRenderer</entry>
          </row>
        </tbody>
      </tgroup>
    </table>
  
  <section>
    <title>Creating on a page</title>
    <para>Component definition on a page for graphical data output</para>

  <para>
      <emphasis role="bold">Example:</emphasis>
 </para>
    <programlisting role="XML"><![CDATA[...
<a4j:mediaOutput element="img" cacheable="false" session="true"
    createContent="#{paintBean.paint}" value="#{paintData}"
    mimeType="image/jpeg"/>
...
]]></programlisting>

  </section>
  <section>
    <title>Creating the Component Dynamically Using Java</title>

  <para>
      <emphasis role="bold">Example:</emphasis>
 </para>
    <programlisting role="JAVA"><![CDATA[import org.ajax4jsf.component.html.MediaOutput;
...
MediaOutput myMedia = new MediaOutput ();
...
]]></programlisting>
  </section>
  <section>
    <title>Key attributes and ways of usage</title>
    <para>To use the component it&apos;s necessary to define it on a page and set Java methods for data keeping and data transmission to output stream. </para>
    <para>Here is the content of <code>paintData</code> that is a bean containing output data</para>
        <para>
      <emphasis role="bold">Example:</emphasis>
    </para>
    <programlisting role="JAVA"><![CDATA[package demo;

public class PaintData implements Serializable{
        private static final long serialVersionUID = 1L;
        Integer width=100;
        Integer weight=50;
...
]]></programlisting>
    <para>The Paint method of the <code>paintBean</code> class is a method transmitting graphical data into output stream.</para>
    
    <para>
      <emphasis role="bold">Example:</emphasis>
    </para>
    <programlisting role="JAVA"><![CDATA[public void paint(OutputStream out, Object data) throws IOException{
	<!--...Some code that puts binary data to "out" Stream-->
        }
]]></programlisting>
    <para>As it was shown in the example above there are two main components:</para>
    <itemizedlist>
        <listitem><para>
         <emphasis><property> &quot;createContent&quot; </property></emphasis>specifies a method accepting 2 parameters. The first (of <code>java.io.OutputStream</code> type) defines a stream, where any binary data is output. The second (of <code>java.lang.Object</code> type) contains deserialized object with data specified in the <emphasis >
        <property>&quot;value&quot;</property>
      </emphasis> attribute.
		</para></listitem>
        <listitem><para>
          Value specifies a bean class keeping data for transmitting into a method that transmits it into a stream.
        </para></listitem>
      </itemizedlist>
	  <note><title>Note:</title><para>A bean class transmitted into value should <code>implement Serializable</code> interface.
	  </para>
	  </note>
	  <para>Hence, when using the component it&apos;s possible to output your data of any type on a page with Ajax requests.</para>
      </section>

  <section>
    <title>Relevant resources links</title>
	<para>
		  <ulink url="http://livedemo.exadel.com/richfaces-demo/richfaces/mediaOutput.jsf?c=mediaOutput">Here</ulink> you can see the example of <emphasis role="bold"
	    ><property>&lt;a4j:mediaOutput &gt;</property></emphasis> usage and sources for the given example.
	</para>
  </section>	  
 
</chapter>