You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Fidel Chavarria <fi...@gmail.com> on 2007/06/28 01:08:55 UTC

How can i make a Tapestry Component of a Stream Response

I trying to create a Chart dinamically and place it in  a html page , to do
so a create a ImageStreamResponse  class that convert my Jfreechart instance
to a byteArrayInputStream


 class ImageStreamResponse implements StreamResponse {

		 private JFreeChart jfreeChart ;
		 private String contentType ;
		 
		 public ImageStreamResponse(final String contentType, JFreeChart chart){
			 this.contentType = contentType ;
			 jfreeChart = chart ;
		 }
		 
		public String getContentType() {
			return contentType;
		}

		public InputStream getStream() throws IOException {
			BufferedImage image  = jfreeChart.createBufferedImage(600, 400);
			ByteArrayOutputStream byteArray = new ByteArrayOutputStream() ;
			ChartUtilities.writeBufferedImageAsJPEG(byteArray, image) ;
			return new ByteArrayInputStream(byteArray.toByteArray());
		}
		 
	 }


with an ActionLink 

StreamResponse onActionFromViewChart(Object[] context) {
		return viewChart.getGraph(context) ;
	}


my viewChart.getGraph(Object[] context) method 

public StreamResponse getGraph(Object[] context)  {
 JFreeChart jfreeChart = new BurnDownChartGenerator(context).getChart() ;
return jfreeChart != null ? new ImageStreamResponse("image/jpeg",
jfreeChart) : new TextStreamResponse("text/html","chart not available") ;
	}


it generate a blank page with the image, but i need it to be a component so
i can place it (the image)within a fancy page.  
 
-- 
View this message in context: http://www.nabble.com/How-can-i-make-a-Tapestry-Component-of-a-Stream-Response-tf3989719.html#a11328870
Sent from the Tapestry - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: How can i make a Tapestry Component of a Stream Response

Posted by Davor Hrg <hr...@gmail.com>.
I've got little time so I did not try this,

I think this could work:
start with source from
org.apache.tapestry.corelib.components.ActionLink

change renderBody:
from
        Link link = _resources.createActionLink(ACTION_EVENT, false,
contextArray);
        writer.element("a", "href", link, "id", _clientId);
to:
        Link link = _resources.createActionLink("graph", false,
contextArray);
        writer.element("IMG", "src", link, "id", _clientId);


and then make your method for generating the graphs:


public StreamResponse onGraph(Object[] context)  {
 JFreeChart jfreeChart = new BurnDownChartGenerator(context).getChart() ;
return jfreeChart != null ? new ImageStreamResponse("image/jpeg",
jfreeChart) : new TextStreamResponse("text/html","chart not available") ;
       }



On 6/28/07, Peter Schröder <Pe...@freenet-ag.de> wrote:
>
> hi fidel,
>
> there is already an example somewhere on the list. search for
> streamresponse or chart.
>
> kind regards,
> peter
>
> -----Ursprüngliche Nachricht-----
> Von: Fidel Chavarria [mailto:fidelchavarria@gmail.com]
> Gesendet: Donnerstag, 28. Juni 2007 01:09
> An: users@tapestry.apache.org
> Betreff: How can i make a Tapestry Component of a Stream Response
>
>
> I trying to create a Chart dinamically and place it in  a html page , to
> do
> so a create a ImageStreamResponse  class that convert my Jfreechart
> instance
> to a byteArrayInputStream
>
>
> class ImageStreamResponse implements StreamResponse {
>
>                  private JFreeChart jfreeChart ;
>                  private String contentType ;
>
>                  public ImageStreamResponse(final String contentType,
> JFreeChart chart){
>                          this.contentType = contentType ;
>                          jfreeChart = chart ;
>                  }
>
>                 public String getContentType() {
>                         return contentType;
>                 }
>
>                 public InputStream getStream() throws IOException {
>                         BufferedImage image  =
> jfreeChart.createBufferedImage(600, 400);
>                         ByteArrayOutputStream byteArray = new
> ByteArrayOutputStream() ;
>                         ChartUtilities.writeBufferedImageAsJPEG(byteArray,
> image) ;
>                         return new ByteArrayInputStream(
> byteArray.toByteArray());
>                 }
>
>          }
>
>
> with an ActionLink
>
> StreamResponse onActionFromViewChart(Object[] context) {
>                 return viewChart.getGraph(context) ;
>         }
>
>
> my viewChart.getGraph(Object[] context) method
>
> public StreamResponse getGraph(Object[] context)  {
> JFreeChart jfreeChart = new BurnDownChartGenerator(context).getChart() ;
> return jfreeChart != null ? new ImageStreamResponse("image/jpeg",
> jfreeChart) : new TextStreamResponse("text/html","chart not available") ;
>         }
>
>
> it generate a blank page with the image, but i need it to be a component
> so
> i can place it (the image)within a fancy page.
>
> --
> View this message in context:
> http://www.nabble.com/How-can-i-make-a-Tapestry-Component-of-a-Stream-Response-tf3989719.html#a11328870
> Sent from the Tapestry - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>

AW: How can i make a Tapestry Component of a Stream Response

Posted by Peter Schröder <Pe...@freenet-ag.de>.
hi fidel,

there is already an example somewhere on the list. search for streamresponse or chart.

kind regards,
peter 

-----Ursprüngliche Nachricht-----
Von: Fidel Chavarria [mailto:fidelchavarria@gmail.com] 
Gesendet: Donnerstag, 28. Juni 2007 01:09
An: users@tapestry.apache.org
Betreff: How can i make a Tapestry Component of a Stream Response


I trying to create a Chart dinamically and place it in  a html page , to do
so a create a ImageStreamResponse  class that convert my Jfreechart instance
to a byteArrayInputStream


 class ImageStreamResponse implements StreamResponse {

		 private JFreeChart jfreeChart ;
		 private String contentType ;
		 
		 public ImageStreamResponse(final String contentType, JFreeChart chart){
			 this.contentType = contentType ;
			 jfreeChart = chart ;
		 }
		 
		public String getContentType() {
			return contentType;
		}

		public InputStream getStream() throws IOException {
			BufferedImage image  = jfreeChart.createBufferedImage(600, 400);
			ByteArrayOutputStream byteArray = new ByteArrayOutputStream() ;
			ChartUtilities.writeBufferedImageAsJPEG(byteArray, image) ;
			return new ByteArrayInputStream(byteArray.toByteArray());
		}
		 
	 }


with an ActionLink 

StreamResponse onActionFromViewChart(Object[] context) {
		return viewChart.getGraph(context) ;
	}


my viewChart.getGraph(Object[] context) method 

public StreamResponse getGraph(Object[] context)  {
 JFreeChart jfreeChart = new BurnDownChartGenerator(context).getChart() ;
return jfreeChart != null ? new ImageStreamResponse("image/jpeg",
jfreeChart) : new TextStreamResponse("text/html","chart not available") ;
	}


it generate a blank page with the image, but i need it to be a component so
i can place it (the image)within a fancy page.  
 
-- 
View this message in context: http://www.nabble.com/How-can-i-make-a-Tapestry-Component-of-a-Stream-Response-tf3989719.html#a11328870
Sent from the Tapestry - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org