title: Grails: displaying created image in gsp
body: <p>I'm very new to Grails so there's probably a very simple answer to this question.  I'm trying to display a dynamically created image in a gsp.  The image is NOT stored in a database, it's created on the fly in the controller.  </p>
  
  <p>What I essentially have is one gsp that has a form which takes in a set of user inputs (requestGraph.gsp).  Upon submitting the form, the parameters are sent to the a displayGraph action in the controller which queries information from a database completely outside of Grails and creates a chart using the JFreeChart library.  I would like to display this image within a displayGraph.gsp or something like that.</p>
  
  <p>So basically within requestGraph.gsp I have a snippet similar to:</p>
  
  <pre><code>&lt;g:form action="displayGraph"&gt;
      &lt;!-- ... bunch of labels and boxes --&gt;
      &lt;g:submitButton name="displayGraph" value="Display Graph" /&gt;
  &lt;/g:form&gt;
  </code></pre>
  
  <p>Within the controller I have something like:</p>
  
  <pre><code>def requestGraph = {}
  
  def displayGraph = {
      //... code that uses params  to make an image byte array and assigns to var img
      return [image : img]
  }
  </code></pre>
  
  <p>Within displayGraph.gsp:</p>
  
  <pre><code>&lt;body&gt;
      &lt;h1&gt;Graph Title&lt;/h1&gt;
      &lt;!-- ??? How to dislpay image? --&gt;
  &lt;/body&gt;
  </code></pre>
  
  <p>I tried piping the image directly to the output stream in the displayGraph action.  This works, but then I lose control of all page formatting in displayGraph.gsp.  </p>
  
  <p>Most tutorials I've found create a dedicated action to pipe the image to an output steam then call that action using a  tag.  The problem is that my image isn't stored in a database and I see no way of passing the image byte array (or even the form parameters) to create/render the image.  Can anybody help me with this?  Thanks.</p>