Yes it seems to be valid. I wrote some lines of code which saves the image to a 
file before returning the stream just to see if the stream returned belongs to 
image. And image file is created correctly.
Somehow I cannot redirect to stream to page, although it actually is created..



-----Original Message-----
From: Chuck Kring [mailto:cjkr...@pacbell.net] 
Sent: Friday, August 13, 2010 2:08 AM
To: users@tapestry.apache.org
Subject: Re: Stream redirection problem when using JFreeChart with Tapestry


  Did you verify that the _context in onChart() is valid?

On 8/12/2010 1:45 PM, Ruksen Inanir wrote:
> Thanks for the response. I had not post the Chart component to keep 
> the mail shorter. But here it is;
>
> public class Chart {
>      @Inject
>      private ComponentResources _resources;
>      @Inject
>      private TypeCoercer _coercer;
>      /**list(array) of paired values(label&  value): 
> [String,Number,String,Number,...]*/
>      @Parameter(required=true)
>      private JFreeChart _chart;
>      @Persist
>      private JFreeChart _context;
>      @Parameter(required=true)
>      private int _width;
>      @Parameter(required=true)
>      private int _height;
>
>      void beginRender(MarkupWriter writer)
>      {
>          _context=_chart;
>          Object[] params = { new Integer(_width),
>                              new Integer(_height) };
>
>          //generate action link
>          Link link = _resources.createEventLink("chart", params);
>          Element img = writer.element("img", "src", link);
>          _resources.renderInformalParameters(writer);
>      }
>
>      void afterRender(MarkupWriter writer)
>      {
>          writer.end();
>      }
>
>      public StreamResponse onChart(final int width, final int height/*, 
> Object ...rest*/){
>          return new StreamResponse(){
>              public String getContentType(){
>                  return "image/jpeg";
>              }
>              public InputStream getStream() throws IOException {
>                  BufferedImage image  = _context.createBufferedImage(width, 
> height);
>                  ByteArrayOutputStream byteArray = new 
> ByteArrayOutputStream() ;
>                  ChartUtilities.writeBufferedImageAsJPEG(byteArray, image) ;
>                  return new ByteArrayInputStream(byteArray.toByteArray());
>              }
>              public void prepareResponse(Response response){}
>          };
>      }
> }
>
>
> -----Original Message-----
> From: Chuck Kring [mailto:cjkr...@pacbell.net]
> Sent: Thursday, August 12, 2010 11:32 PM
> Cc: Tapestry users
> Subject: Re: Stream redirection problem when using JFreeChart with 
> Tapestry
>
>
>    A few things:
>
> 1) You didn't include the chart component.  It's the thing that is generating 
> the exception.
>
> 2) I would verify that  _context in getStream() is a valid JFreeChart
> and that ChartUtils.writeBufferedImageAsJpeg works correctly.   I
> suspect that a problem with the chart is causing getStream() to fail, which 
> then causes the Chart onChart() event to not return a StreamResponse.
>
> I generate charts in a slightly different manner than this example:
>
> a) I use Chart as a base object and extend Chart for my individual 
> chart types.  For example, I don't call<t:chart  t:chart=lineChart>  
> but use MyLineChart extends Chart and call<t:myLinerChart 
> nodeId="...">
>
> b) The code to create the chart is in the derived class rather than the page 
> class.  I don't pass the serialized chart object to the client as a context.  
> Rather, the context contains the identity of the object to be charted - in my 
> case a nodeId - and the chart is generated by the
> component rather than the page.   One benefit of this approach is it
> allows me to use the same chart on different pages.
>
> c) I personally like PNG as an output format rather than JPEG.
>
> Once again, make sure that the actual chart is working correctly.
>
> Chuck
>
> public class MyParticularChart extends Chart{
>
>       private static final Logger logger = 
> Logger.getLogger("gateway.components.MyParticularChart ");
>
>       public StreamResponse onChart(short id, long timestamp)
>       {
>           BSU bsu = (BSU)Node.getByNodeId(id);
>           ArrayList<Motecomm>  list =
> MotecommCache.getInstance().getList(bsu, getTimeService(), 
> getSession());
>
>           synchronized(ChartMutex.getMutex()){
>
>               TimeSeriesCollection dataset = new TimeSeriesCollection();
>               addBSUTimeSeries(bsu.getIdleVariance(), list, dataset);
>
>
>               final JFreeChart chart = ChartFactory.createTimeSeriesChart(
>                       null, // title
>                       null,             // x-axis label
>                       null,   // y-axis label
>                       null,            // data
>                       true,               // create legend?
>                       false,               // generate tooltips?
>                       false               // generate URLs?
>               );
>
>               XYItemRenderer r = chart.getXYPlot().getRenderer();
>               r.setSeriesPaint(0, Color.darkGray);
>               r.setSeriesPaint(1, Color.RED);
>               r.setSeriesPaint(2, Color.GREEN);
>               r.setSeriesPaint(3, Color.GRAY);
>
>               XYPlot plot = chart.getXYPlot();
>               plot.setRangeAxisLocation(1, AxisLocation.BOTTOM_OR_RIGHT);
>               NumberAxis axis = new NumberAxis("");
>               axis.setRange(new Range(0,4 * bsu.getIdleVariance()), true, 
> false );
>               plot.setRangeAxis(0, axis);
>               plot.setDataset(1,dataset);
>
>               return new StreamResponse(){
>                   public String getContentType(){
>                       return "image/png";
>                   }
>                   public InputStream getStream() throws IOException {
>                       BufferedImage image  = chart.createBufferedImage(500, 
> 175);
>                       ByteArrayOutputStream byteArray = new
> ByteArrayOutputStream() ;
>                       
> ChartUtilities.writeBufferedImageAsPNG(byteArray,
> image) ;
>                       return new
> ByteArrayInputStream(byteArray.toByteArray());
>                   }
>                   public void prepareResponse(Response response){}
>               };
>           }
>       }
>
> On 8/12/2010 11:53 AM, Ruksen Inanir wrote:
>> Hi,
>>      I placed the the exact same Chart.java from 
>> http://wiki.apache.org/tapestry/Tapestry5HowToCreateGenericGraphComponent 
>> under the package 'com.mycompany.myproject.webapp.components'. My tapestry 
>> version is 5.1.0.5. And I use jfreechart 1.0.12.
>>
>> here is my \src\main\webapp\reports\LineChartPage.tml;
>>
>> <html xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd";>
>>       <body>
>>           <h1>Line Chart</h1>
>>           <t:chart width="200" height="150" chart="lineChart"/>
>>       </body>
>> </html>
>>
>> And below is the LineChartPage.java under package 
>> com.mycompany.myproject.webapp.pages.reports;
>>
>> public class LineChartPage {
>>       public JFreeChart getLineChart() {
>>           XYSeries series = new XYSeries("Average Size");
>>           series.add(20.0, 10.0);
>>           series.add(40.0, 20.0);
>>           series.add(70.0, 50.0);
>>           XYDataset xyDataset = new XYSeriesCollection(series);
>>           final JFreeChart chart = ChartFactory.createXYLineChart
>>                   ("Sample XY Chart",  // Title
>>                           "Height",           // X-Axis label
>>                           "Weight",           // Y-Axis label
>>                           xyDataset,          // Dataset
>>                           PlotOrientation.HORIZONTAL,
>>                           true,                // Show legend
>>                           true,                            // Tooltips
>>                           true                             // Urls
>>                   );
>>
>>           return chart;
>>       }
>> }
>>
>> Everything seems to be right but I get the exception; 20:39:44,240 
>> ERROR [RequestExceptionHandler] Processing of request failed with uncaught 
>> exception: Sanity check - neither a stream response nor a redirect response 
>> was generated for this action request.
>> java.lang.IllegalStateException: Sanity check - neither a stream response 
>> nor a redirect response was generated for this action request.
>>           at 
>> org.apache.tapestry5.internal.services.ImmediateActionRenderResponseFilter.handle(ImmediateActionRenderResponseFilter.java:63)
>>           at 
>> $ComponentEventRequestHandler_12a675b8084.handle($ComponentEventRequestHandler_12a675b8084.java)
>>           at 
>> org.apache.tapestry5.internal.services.AjaxFilter.handle(AjaxFilter.java:42)
>>           at 
>> $ComponentEventRequestHandler_12a675b8084.handle($ComponentEventRequestHandler_12a675b8084.java)
>>           at 
>> org.apache.tapestry5.upload.internal.services.UploadExceptionFilter.handle(UploadExceptionFilter.java:75)
>>           at 
>> $ComponentEventRequestHandler_12a675b8084.handle($ComponentEventRequestHandler_12a675b8084.java)
>>           at 
>> org.apache.tapestry5.services.TapestryModule$36.handle(TapestryModule.java:2164)
>>           at 
>> $ComponentEventRequestHandler_12a675b8084.handle($ComponentEventRequestHandler_12a675b8084.java)
>>           at 
>> $ComponentEventRequestHandler_12a675b7fca.handle($ComponentEventRequestHandler_12a675b7fca.java)
>>           at
>> org.apache.tapestry5.internal.services.ComponentRequestHandlerTermina
>> t
>> or.handleComponentEvent(ComponentRequestHandlerTerminator.java:43)
>>
>>
>>
>> -----Original Message-----
>> From: Chuck Kring [mailto:cjkr...@pacbell.net]
>> Sent: Tuesday, August 10, 2010 8:28 PM
>> To: users@tapestry.apache.org
>> Subject: Re: Stream redirection problem when using JFreeChart with 
>> Tapestry
>>
>>
>>     Hi.
>>
>> I use JfreeChart extensively with T 5.0.1.5 and I'm very happy with
>> it.   Most likely your exception is caused by a bug in your .tml or the
>> underlying class.     If you could reduce the template and the class to
>> the minimum size that still shows the bug and post both to a follow up 
>> email, somebody on the list will probably be able to help you.
>>
>> Chuck
>>
>> On 8/10/2010 2:10 AM, Ruksen Inanir wrote:
>>> Hi,
>>>      I want to display a line-chart for my application. I tested 
>>> chenille-kit chart component it worked quite good, but it does not 
>>> support Dates on the x-axis. I want to to draw time-series on the 
>>> chart. So I decided to use JFreeChart. The link 
>>> http://wiki.apache.org/tapestry/Tapestry5HowToCreateGenericGraphComp
>>> o n ent describes the usage of JFreeChart with Tapestry. I used to 
>>> code as it is, I put the Chart.java under components package, 
>>> Prepared the LineChartPage.java and LineChartPage.tml. The page 
>>> rendered, displayed but the chart is not displayed. When I look at 
>>> the Jboss console I saw the "neither a stream response nor a 
>>> redirect response was generated for this action request." exception;
>>>
>>> [org.apache.tapestry5.services.TapestryModule.RequestExceptionHandler] 
>>> Processing of request failed with uncaught exception: Sanity check - 
>>> neither a stream response nor a redirect response was generated for this 
>>> action request.
>>> java.lang.IllegalStateException: Sanity check - neither a stream response 
>>> nor a redirect response was generated for this action request.
>>>     at 
>>> org.apache.tapestry5.internal.services.ImmediateActionRenderResponseFilter.handle(ImmediateActionRenderResponseFilter.java:63)
>>>     at 
>>> $ComponentEventRequestHandler_12a5b36106e.handle($ComponentEventRequestHandler_12a5b36106e.java)
>>>     at 
>>> org.apache.tapestry5.internal.services.AjaxFilter.handle(AjaxFilter.java:42)
>>>     at 
>>> $ComponentEventRequestHandler_12a5b36106e.handle($ComponentEventRequestHandler_12a5b36106e.java)
>>>     at 
>>> org.apache.tapestry5.upload.internal.services.UploadExceptionFilter.handle(UploadExceptionFilter.java:75)
>>>     at 
>>> $ComponentEventRequestHandler_12a5b36106e.handle($ComponentEventRequestHandler_12a5b36106e.java)
>>>     at 
>>> org.apache.tapestry5.services.TapestryModule$36.handle(TapestryModule.java:2164)
>>>     at 
>>> $ComponentEventRequestHandler_12a5b36106e.handle($ComponentEventRequestHandler_12a5b36106e.java)
>>>     at 
>>> $ComponentEventRequestHandler_12a5b361006.handle($ComponentEventRequestHandler_12a5b361006.java)
>>>     at 
>>> org.apache.tapestry5.internal.services.ComponentRequestHandlerTerminator.handleComponentEvent(ComponentRequestHandlerTerminator.java:43)
>>>     at 
>>> $ComponentRequestHandler_12a5b360ff8.handleComponentEvent($ComponentRequestHandler_12a5b360ff8.java)
>>>     at
>>> org.apache.tapestry5.internal.services.ComponentEventDispatcher.disp
>>> a
>>> t
>>> ch(ComponentEventDispatcher.java:46)
>>>
>>> Did anyone encountered this exception? Or do you have any idea of the 
>>> cause? Or a better solution to display time-series charts, which contain 
>>> time information on x-axis.
>>>
>>> Regars,
>>> Ruksen
>>> --------------------------------------------------------------------
>>> - To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
>>> For additional commands, e-mail: users-h...@tapestry.apache.org
>>>
>>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
>> For additional commands, e-mail: users-h...@tapestry.apache.org
>>
>>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
> For additional commands, e-mail: users-h...@tapestry.apache.org
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
> For additional commands, e-mail: users-h...@tapestry.apache.org
>
>

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


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

Reply via email to