Updating a Dynamic Image with AJAX (and JFreeChart)

2007-09-25 Thread Jason Mihalick

I am integrating JFreeChart into my application and I've followed the
JFreeChart example on the wiki.  That works very nicely.  I was impressed. 
What I want to do now is update the graph that I display based on the
selection from a drop down list.  I've successfully added the DropDownChoice
component and added a AjaxFormComponentUpdatingBehavior to it.  I've
verified that my onUpdate( AjaxRequestTarget ) method is being invoked and
I'm receiving the updated value, which is very cool.  Here is my onUpdate
implementation for the DropDownChoice control:

protected void onUpdate( AjaxRequestTarget target ) {
  log.debug( "graphStyles onUpdate invoked! SelectedGraphStyle = " +  
 FieldResultsPanel.this.getSelectedGraphStyle() );
  FieldResultsPanel.this.updateGraph();  // Update the model and re-create
the JFreeChart Image

  // fieldGraph is my JFreeChartImage instance (derived from Image)
  // This is supposed to indicate back to the browser that the image needs
updated.  I think this
  // is working properly
  target.addComponent( FieldResultsPanel.this.fieldGraph );  
}

Even though I am updating the model of my JFreeChartImage, it appears that
the getImageData method is never invoked afterwards.

What do I need to do in order to get the image data to be re-read?

Here is my JFreeChartImage class:

public class JFreeChartImage extends Image {

  private static final Logger log = LoggerFactory.getLogger(
JFreeChartImage.class );
  
  private int width;
  private int height;

  public JFreeChartImage( String id ) {
super( id );
  }

  public JFreeChartImage( String id, int width, int height ) {
this( id );
this.width = width;
this.height = height;
  }
  
  public JFreeChartImage( String id, JFreeChart chart, int width, int height
) {
super(id, new Model( chart ) );
this.width = width;
this.height = height;
  }

  public Component setModel( JFreeChart chart ) {
log.debug( "setModel invoked with chart: " + chart );
return super.setModel( new Model( chart ) );
  }
  
  @Override
  protected Resource getImageResource() {

return new DynamicImageResource(){
  private static final long serialVersionUID = 1L;

  @Override
  protected byte[] getImageData() {
log.debug( "Invoking getImageData..." );
JFreeChart chart = (JFreeChart)getModelObject();
log.debug( "Chart object: " + chart );
return toImageData( chart.createBufferedImage( width, height ) );
  }
  
  @Override
  protected void setHeaders( WebResponse response ) {
if ( isCacheable() ) {
  super.setHeaders(response);
} else {
  response.setHeader( "Pragma", "no-cache" );
  response.setHeader( "Cache-Control", "no-cache" );
  response.setDateHeader( "Expires", 0 );
}
  }
};
  }
 
Any help is much appreciated!

--
Jason
-- 
View this message in context: 
http://www.nabble.com/Updating-a-Dynamic-Image-with-AJAX-%28and-JFreeChart%29-tf4517009.html#a12884455
Sent from the Wicket - User mailing list archive at Nabble.com.


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Updating a Dynamic Image with AJAX (and JFreeChart)

2009-11-13 Thread wicketnewuser

I have same situation. I'm not able to refresh my image. But if i view the
image i do get refreshed image
Here is my code. Based on my dropdownchoice it should make new Jfreechart
and the image should refresh. I couldn't get it working so i wrapped the
image with in a span but it still doesn't work. TugboatChartImage extends
NonCachingImage . Can any one point out what I'm doing wrong
Chart chart1 = new Chart(this.getString(column1.toString()), "Date",
"Dollars");
final String yAxisType = "linear";
final int smallChartWidth=400;
final int smallChartHeight=200;
JFreeChart jfChartOne = chart1.render(chartOneCollection, null, 
yAxisType,
smallChartWidth, smallChartHeight);


// make an image
final TugboatChartImage imageOne = new 
TugboatChartImage("chart1image",
jfChartOne, smallChartWidth, smallChartHeight);
final WebMarkupContainer chart1Span = new
WebMarkupContainer("chart1Span");
chart1Span.add(imageOne);
add(chart1Span);

// draw chart 2
Chart chart2 = new Chart(this.getString(column2.toString()), 
"Date",
"Count");
JFreeChart jfChartTwo = chart2.render(chartTwoCollection, null, 
yAxisType,
smallChartWidth, smallChartHeight);

// make an image
TugboatChartImage imageTwo = new 
TugboatChartImage("chart2image",
jfChartTwo, smallChartWidth, smallChartHeight);
add(imageTwo);
String filterStringList ="";
if (filterStringList!= null){
filterStringList =
report.getFilterParameterList().toString().replaceAll("\\[", "");
filterStringList = filterStringList.replaceAll("\\]", 
"");
}
final DropDownChoice chart1Select 
= new
DropDownChoice("chart1Select" ,new
PropertyModel(this, "column1"), TugboatReportData.trafficColumns,new
IChoiceRenderer() {
public Object getDisplayValue(Object obj) {
//this.getString give you value from the 
propertyfile
return
ReportResultsPage.this.getString(((TugboatReportData.ColumnName)
obj).toString());
}

public String getIdValue(Object obj, int index) {
return obj.toString();
}
});
chart1Select.add(new  
AjaxFormComponentUpdatingBehavior("onchange") {
protected void onUpdate(AjaxRequestTarget target) {
sortByColumn(displayRowSetFinal, column1);
Chart chart1R = new
Chart(ReportResultsPage.this.getString(column1.toString()), "Date",
"Dollars");

SwishTimeSeriesCollection chartOneCollectionR =
createChartCollection(report, originalRowSet, displayRowSetFinal.subList(0,
(originalRowSet.size() > 10) ? 9 : originalRowSet.size() - 1), column1);
logger.error(displayRowSetFinal);
JFreeChart jfChartOneR = 
chart1R.render(chartOneCollectionR, null,
yAxisType, smallChartWidth, smallChartHeight);
imageOne.setDefaultModelObject(jfChartOneR);
imageOne.modelChanged();
chart1Span.modelChanged();
chart1Span.setOutputMarkupId(true);
imageOne.setOutputMarkupId(true);
target.addComponent(imageOne);
target.addComponent(chart1Span);
}
});

Jason Mihalick wrote:
> 
> I am integrating JFreeChart into my application and I've followed the
> JFreeChart example on the wiki.  That works very nicely.  I was impressed. 
> What I want to do now is update the graph that I display based on the
> selection from a drop down list.  I've successfully added the
> DropDownChoice component and added a AjaxFormComponentUpdatingBehavior to
> it.  I've verified that my onUpdate( AjaxRequestTarget ) method is being
> invoked and I'm receiving the updated value, which is very cool.  Here is
> my onUpdate implementation for the DropDownChoice control:
> 
> protected void onUpdate( AjaxRequestTarget target ) {
>   log.debug( "graphStyles onUpdate invoked! SelectedGraphStyle = " +  
>  FieldResultsPanel.this.getSelectedGraphStyle() );
>   FieldResultsPanel.this.updateGraph();  // Update the model and re-create
> the JFreeChart Image
> 
>   // fieldGraph is my JFreeChartImage instance (derived from Image)
>   // This is supposed to indicate back to the browser that the image needs
> updated.  I think this
>   // is working properly
>   target.addComponent( FieldResultsPanel.this.fieldGraph );  
> }
> 
> Even though I am updating the model of my J

Re: Updating a Dynamic Image with AJAX (and JFreeChart)

2009-11-13 Thread McIlwee, Craig
Look at the source of the DynamicImageResource class.  The getResourceState 
method does something like (sorry for the lame pseudocode) 'if image data is 
null then save and return value of getImageData else return the previous image 
data'.  So its gonna call your getImageData() method once and save the value.  
This falls in line with the super class's (DynamicWebResource) javadoc that 
says:

very useful for things you   generate dynamically, but reuse for a while after 
that. If you need resources that stream   directly and are not cached, extend 
WebResource directly and implement Resouce.getResourceStream() yourself.

It has nothing to do with HTTP caching, which it looks like you're trying to 
solve with your headers, but server-side caching.  Anyways... in this case, 
getResourceStream of WebResource ends up calling getResourceState of 
DynamicImageResource.  All you need to do is is override getResourceState (and 
therefore kind of overrides the behavior of getResourceStream) of your 
DynamicImageResource and ensure that it doesn't cache the result of 
getImageData() and you should be set.

Craig
  _  

From: wicketnewuser [mailto:swarn...@hotmail.com]
To: users@wicket.apache.org
Sent: Fri, 13 Nov 2009 20:32:05 -0500
Subject: Re: Updating a Dynamic Image with AJAX (and JFreeChart)


  I have same situation. I'm not able to refresh my image. But if i view the
  image i do get refreshed image
  Here is my code. Based on my dropdownchoice it should make new Jfreechart
  and the image should refresh. I couldn't get it working so i wrapped the
  image with in a span but it still doesn't work. TugboatChartImage extends
  NonCachingImage . Can any one point out what I'm doing wrong
  Chart chart1 = new Chart(this.getString(column1.toString()), "Date",
  "Dollars");
final String yAxisType = "linear";
final int smallChartWidth=400;
final int smallChartHeight=200;
JFreeChart jfChartOne = chart1.render(chartOneCollection, null, yAxisType,
  smallChartWidth, smallChartHeight);


// make an image
final TugboatChartImage imageOne = new TugboatChartImage("chart1image",
  jfChartOne, smallChartWidth, smallChartHeight);
final WebMarkupContainer chart1Span = new
  WebMarkupContainer("chart1Span");
chart1Span.add(imageOne);
add(chart1Span);
  
// draw chart 2
Chart chart2 = new Chart(this.getString(column2.toString()), "Date",
  "Count");
JFreeChart jfChartTwo = chart2.render(chartTwoCollection, null, yAxisType,
  smallChartWidth, smallChartHeight);

// make an image
TugboatChartImage imageTwo = new TugboatChartImage("chart2image",
  jfChartTwo, smallChartWidth, smallChartHeight);
add(imageTwo);
String filterStringList ="";
if (filterStringList!= null){
 filterStringList =
  report.getFilterParameterList().toString().replaceAll("\\[", "");
 filterStringList = filterStringList.replaceAll("\\]", "");
}
final DropDownChoice chart1Select = new
  DropDownChoice("chart1Select" ,new
  PropertyModel(this, "column1"), TugboatReportData.trafficColumns,new
  IChoiceRenderer() {
 public Object getDisplayValue(Object obj) {
  //this.getString give you value from the propertyfile
 return
  ReportResultsPage.this.getString(((TugboatReportData.ColumnName)
  obj).toString());
 }
  
 public String getIdValue(Object obj, int index) {
  return obj.toString();
 }
});
chart1Select.add(new  AjaxFormComponentUpdatingBehavior("onchange") {
 protected void onUpdate(AjaxRequestTarget target) {
sortByColumn(displayRowSetFinal, column1);
Chart chart1R = new
  Chart(ReportResultsPage.this.getString(column1.toString()), "Date",
  "Dollars");

SwishTimeSeriesCollection chartOneCollectionR =
  createChartCollection(report, originalRowSet, displayRowSetFinal.subList(0,
  (originalRowSet.size() > 10) ? 9 : originalRowSet.size() - 1), column1);
logger.error(displayRowSetFinal);
JFreeChart jfChartOneR = chart1R.render(chartOneCollectionR, null,
  yAxisType, smallChartWidth, smallChartHeight);
imageOne.setDefaultModelObject(jfChartOneR);
imageOne.modelChanged();
   chart1Span.modelChanged();
chart1Span.setOutputMarkupId(true);
imageOne.setOutputMarkupId(true);
target.addComponent(imageOne);
target.addComponent(chart1Span);
 }
});
  
  Jason Mihalick wrote:
  > 
  > I am integrating JFreeChart into my application and I've followed the
  > JFreeChart example on the wiki.  That works very nicely.  I was impressed. 
  > What I want to do now is update the graph that I display based on the
  > selection from a

RE: Updating a Dynamic Image with AJAX (and JFreeChart)

2009-11-13 Thread Swarnim Ranjitkar

I couldn't override getResourceState of DynamicImageResource as it new Resource 
state uses variable from DynamicImageResource eg format. Instead i copied 
DynamicImageResource class and made my own version of it and modified the 
getResourceState() get method. When I changed the drop down I was expecting it 
to call the geImageData but it wasn't calling it. Could you please advice.
Here is the modified method.
protected synchronized ResourceState getResourceState()
{
return new ResourceState()
{
private byte[] imageData;
private final String contentType = "image/" + format;

@Override
public Time lastModifiedTime()
{
if (lastModifiedTime == null)
{
lastModifiedTime = 
DynamicImageResource.this.lastModifiedTime;
if (lastModifiedTime == null)
{
lastModifiedTime = Time.now();
}
}
return lastModifiedTime;
}

@Override
public byte[] getData()
{
// here is what I made the change.
imageData = getImageData();
return imageData;
}

@Override
public String getContentType()
{
return contentType;
}
};
}

>From my  Image Class I called the copied version of   in getImageResource() {

return new DynamicImageResource(){


public class TugboatChartImage extends NonCachingImage  {

private int width;
private int height;

public TugboatChartImage(String id, JFreeChart chart, int width, int 
height){
super(id, new Model(chart));
this.width = width;
this.height = height;
}

@Override
protected Resource getImageResource() {
return new DynamicImageResource(){//my copied version of DynamicResouce
@Override
protected byte[] getImageData() {
JFreeChart chart = (JFreeChart)getDefaultModelObject();
return toImageData(chart.createBufferedImage(width, height));
}


};
}

}


> To: users@wicket.apache.org
> From: craig.mcil...@openroadsconsulting.com
> Subject: Re: Updating a Dynamic Image with AJAX (and JFreeChart)
> Date: Fri, 13 Nov 2009 23:31:39 -0500
> 
> Look at the source of the DynamicImageResource class.  The getResourceState 
> method does something like (sorry for the lame pseudocode) 'if image data is 
> null then save and return value of getImageData else return the previous 
> image data'.  So its gonna call your getImageData() method once and save the 
> value.  This falls in line with the super class's (DynamicWebResource) 
> javadoc that says:
> 
> very useful for things you   generate dynamically, but reuse for a while 
> after that. If you need resources that stream   directly and are not cached, 
> extend WebResource directly and implement Resouce.getResourceStream() 
> yourself.
> 
> It has nothing to do with HTTP caching, which it looks like you're trying to 
> solve with your headers, but server-side caching.  Anyways... in this case, 
> getResourceStream of WebResource ends up calling getResourceState of 
> DynamicImageResource.  All you need to do is is override getResourceState 
> (and therefore kind of overrides the behavior of getResourceStream) of your 
> DynamicImageResource and ensure that it doesn't cache the result of 
> getImageData() and you should be set.
> 
> Craig
>   _  
> 
> From: wicketnewuser [mailto:swarn...@hotmail.com]
> To: users@wicket.apache.org
> Sent: Fri, 13 Nov 2009 20:32:05 -0500
> Subject: Re: Updating a Dynamic Image with AJAX (and JFreeChart)
> 
> 
>   I have same situation. I'm not able to refresh my image. But if i view the
>   image i do get refreshed image
>   Here is my code. Based on my dropdownchoice it should make new Jfreechart
>   and the image should refresh. I couldn't get it working so i wrapped the
>   image with in a span but it still doesn't work. TugboatChartImage extends
>   NonCachingImage . Can any one point out what I'm doing wrong
>   Chart chart1 = new Chart(this.getString(column1.toString()), "Date",
>   "Dollars");
> final String yAxisType = "linear";
> final int smallChartWidth=400;
> final int smallChartHeight=200;
> JFreeChart jfChartOne = chart1.render(chartOneCollection, null, yAxisType,
>   smallChartWidth, smallChartHeight);
> 
> 
> // make an image
> final TugboatChartImage imageOne = new TugboatChartImage("chart1image",
>   jfChartOne, smallChartWidth, smallChartHeight);
> 

Re: Updating a Dynamic Image with AJAX (and JFreeChart)

2009-11-14 Thread Wojtek

Hi there,
is JFreeChart your only possible approach? Check out flot integration 
from wicketstuff-core.
It draws nicer charts and you can update datasets sending json object 
and redraw it by js.


Regards,
Wojtek


Swarnim Ranjitkar pisze:

I couldn't override getResourceState of DynamicImageResource as it new Resource 
state uses variable from DynamicImageResource eg format. Instead i copied 
DynamicImageResource class and made my own version of it and modified the 
getResourceState() get method. When I changed the drop down I was expecting it 
to call the geImageData but it wasn't calling it. Could you please advice.
Here is the modified method.
protected synchronized ResourceState getResourceState()
{
return new ResourceState()
{
private byte[] imageData;
private final String contentType = "image/" + format;

@Override
public Time lastModifiedTime()
{
if (lastModifiedTime == null)
{
lastModifiedTime = 
DynamicImageResource.this.lastModifiedTime;
if (lastModifiedTime == null)
{
lastModifiedTime = Time.now();
}
}
return lastModifiedTime;
}

@Override
public byte[] getData()
{
// here is what I made the change.
imageData = getImageData();
return imageData;
}

@Override
public String getContentType()
{
return contentType;
}
};
}

From my  Image Class I called the copied version of   in getImageResource() {

return new DynamicImageResource(){


public class TugboatChartImage extends NonCachingImage  {

private int width;
private int height;

public TugboatChartImage(String id, JFreeChart chart, int width, int 
height){
super(id, new Model(chart));
this.width = width;
this.height = height;
}

@Override
protected Resource getImageResource() {
return new DynamicImageResource(){//my copied version of DynamicResouce
@Override
protected byte[] getImageData() {
JFreeChart chart = (JFreeChart)getDefaultModelObject();
return toImageData(chart.createBufferedImage(width, height));
}



};
}

}


  

To: users@wicket.apache.org
From: craig.mcil...@openroadsconsulting.com
Subject: Re: Updating a Dynamic Image with AJAX (and JFreeChart)
Date: Fri, 13 Nov 2009 23:31:39 -0500

Look at the source of the DynamicImageResource class.  The getResourceState 
method does something like (sorry for the lame pseudocode) 'if image data is 
null then save and return value of getImageData else return the previous image 
data'.  So its gonna call your getImageData() method once and save the value.  
This falls in line with the super class's (DynamicWebResource) javadoc that 
says:

very useful for things you   generate dynamically, but reuse for a while after 
that. If you need resources that stream   directly and are not cached, extend 
WebResource directly and implement Resouce.getResourceStream() yourself.

It has nothing to do with HTTP caching, which it looks like you're trying to 
solve with your headers, but server-side caching.  Anyways... in this case, 
getResourceStream of WebResource ends up calling getResourceState of 
DynamicImageResource.  All you need to do is is override getResourceState (and 
therefore kind of overrides the behavior of getResourceStream) of your 
DynamicImageResource and ensure that it doesn't cache the result of 
getImageData() and you should be set.

Craig
  _  


From: wicketnewuser [mailto:swarn...@hotmail.com]
To: users@wicket.apache.org
Sent: Fri, 13 Nov 2009 20:32:05 -0500
Subject: Re: Updating a Dynamic Image with AJAX (and JFreeChart)


  I have same situation. I'm not able to refresh my image. But if i view the
  image i do get refreshed image
  Here is my code. Based on my dropdownchoice it should make new Jfreechart
  and the image should refresh. I couldn't get it working so i wrapped the
  image with in a span but it still doesn't work. TugboatChartImage extends
  NonCachingImage . Can any one point out what I'm doing wrong
  Chart chart1 = new Chart(this.getString(column1.toString()), "Date",
  "Dollars");
final String yAxisType = "linear";
final int smallChartWidth=400;
final int smallChartHeight=200;
JFreeChart jfChartOne = chart1.render(chartOneCollection, null, yAxisType,
  smallChartWidth, smallChartHeight);


// make an image

final TugboatChartImage imageOne = new TugboatChartImage("chart1image",
  jfChartOne, smallChartWidth, smallChartHeight);
final WebMarkupContai

RE: Updating a Dynamic Image with AJAX (and JFreeChart)

2009-11-14 Thread Swarnim Ranjitkar

I would be nice for this work as we have a JFreeChart written which is called 
by other apps too.

> Date: Sat, 14 Nov 2009 10:23:38 +0100
> From: zabia...@gmail.com
> To: user
se...@wicket.apache.org
> Subject: Re: Updating a Dynamic Image with AJAX (and JFreeChart)
> 
> Hi there,
> is JFreeChart your only possible approach? Check out flot integration 
> from wicketstuff-core.
> It draws nicer charts and you can update datasets sending json object 
> and redraw it by js.
> 
> Regards,
> Wojtek
> 
> 
> Swarnim Ranjitkar pisze:
> > I couldn't override getResourceState of DynamicImageResource as it new 
> > Resource state uses variable from DynamicImageResource eg format. Instead i 
> > copied DynamicImageResource class and made my own version of it and 
> > modified the getResourceState() get method. When I changed the drop down I 
> > was expecting it to call the geImageData but it wasn't calling it. Could 
> > you please advice.
> > Here is the modified method.
> > protected synchronized ResourceState getResourceState()
> > {
> > return new ResourceState()
> > {
> > private byte[] imageData;
> > private final String contentType = "image/" + format;
> >
> > @Override
> > public Time lastModifiedTime()
> > {
> > if (lastModifiedTime == null)
> > {
> > lastModifiedTime = 
> > DynamicImageResource.this.lastModifiedTime;
> > if (lastModifiedTime == null)
> > {
> > lastModifiedTime = Time.now();
> > }
> > }
> > return lastModifiedTime;
> > }
> >
> > @Override
> > public byte[] getData()
> > {
> > // here is what I made the change.
> > imageData = getImageData();
> > return imageData;
> > }
> >
> > @Override
> > public String getContentType()
> > {
> > return contentType;
> > }
> > };
> > }
> >
> > From my  Image Class I called the copied version of   in getImageResource() 
> > {
> >
> > return new DynamicImageResource(){
> >
> >
> > public class TugboatChartImage extends NonCachingImage  {
> >
> > private int width;
> > private int height;
> >
> > public TugboatChartImage(String id, JFreeChart chart, int width, int 
> > height){
> > super(id, new Model(chart));
> > this.width = width;
> > this.height = height;
> > }
> >
> > @Override
> > protected Resource getImageResource() {
> > return new DynamicImageResource(){//my copied version of 
> > DynamicResouce
> > @Override
> > protected byte[] getImageData() {
> > JFreeChart chart = (JFreeChart)getDefaultModelObject();
> > return toImageData(chart.createBufferedImage(width, 
> > height));
> > }
> > 
> >
> > };
> > }
> >
> > }
> >
> >
> >   
> >> To: users@wicket.apache.org
> >> From: craig.mcil...@openroadsconsulting.com
> >> Subject: Re: Updating a Dynamic Image with AJAX (and JFreeChart)
> >> Date: Fri, 13 Nov 2009 23:31:39 -0500
> >>
> >> Look at the source of the DynamicImageResource class.  The 
> >> getResourceState method does something like (sorry for the lame 
> >> pseudocode) 'if image data is null then save and return value of 
> >> getImageData else return the previous image data'.  So its gonna call your 
> >> getImageData() method once and save the value.  This falls in line with 
> >> the super class's (DynamicWebResource) javadoc that says:
> >>
> >> very useful for things you   generate dynamically, but reuse for a while 
> >> after that. If you need resources that stream   directly and are not 
> >> cached, extend WebResource directly and implement 
> >> Resouce.getResourceStream() yourself.
> >>
> >> It has nothing to do with HTTP caching, which it looks like you're trying 
> >> to solve with your headers, but server-side caching.  Anyways... in this 
> >> case, getResourceStream of WebResource ends up calling getResourceState of 

Re: Updating a Dynamic Image with AJAX (and JFreeChart)

2009-06-24 Thread nickponico

I resume an old conversation, but i've a similar problem.

I have exactly same situation : a dynamic image generated at runtime, with a
non caching image i can refresh it easily.

It all works on my pc (and my jboss).

But when I upload this on the server it doesn't work... i think that it
could be something like user permissions (authorization and other), but my
user is the owner of all jboss directory (with 776 permission).

The identical situation in my local pc works great...

I try to show some code:

I have a my implementation of a NonCachingImage

[CODE] 

public class JFreeChartImage extends NonCachingImage {

private int width;
private int height;

public JFreeChartImage(String id, JFreeChart chart, int width, int 
height)
{
super(id, new Model(chart));
this.width = width;
this.height = height;
}

@Override
protected Resource getImageResource() {
return new DynamicImageResource() {
@Override
protected byte[] getImageData() {
JFreeChart chart = (JFreeChart) 
getModelObject();
return 
toImageData(chart.createBufferedImage(width, height));
}

@Override
protected void setHeaders(WebResponse response) {
if (isCacheable()) {
super.setHeaders(response);
} else {
response.setHeader("Pragma", 
"no-cache");
response.setHeader("Cache-Control", 
"no-cache");
response.setDateHeader("Expires", 0);
}
}
};
}

}

[/CODE]


And I've added an instance of this Image on my page (obviously), and in
every refresh I modify only the model (chart) and recall an ajax target
event.

I show to you

[CODE]

private JFreeChartImage image

...
...
...


// In refreshing moment
JFreeChart chart = getChart();
image.setModelObject(chart);

[/CODE]

and then I call an target.addComponent(image) on the AjaxRequestTarget.

 I've seen the html code and I've found the real Image url (something like
?wicket:interface=:7:container:image::IResourceListener&wicket:antiCache=1245855026418)...
in local pc if I try to request that url I receive the image, in the remote
server no.

Can anyone helps me to resolve this strange problem?

If it is a permission problem, where, who and what I have to open to my
user?


Thanks in advance

E.




Jason Mihalick wrote:
> 
> Thanks for the tip.  That worked!  That was too easy.  :-)
> 
> --
> Jason
> 
> David Bernard-2 wrote:
>> 
>> Hi,
>> 
>> Have you try to extend NonCachingImage instead of Image  (and comments
>> setHeaders(...))?
>> 
>> /david
>> 
>> Jason Mihalick wrote:
>>> I am integrating JFreeChart into my application and I've followed the
>>> JFreeChart example on the wiki.  That works very nicely.  I was
>>> impressed. 
>>> What I want to do now is update the graph that I display based on the
>>> selection from a drop down list.  I've successfully added the
>>> DropDownChoice
>>> component and added a AjaxFormComponentUpdatingBehavior to it.  I've
>>> verified that my onUpdate( AjaxRequestTarget ) method is being invoked
>>> and
>>> I'm receiving the updated value, which is very cool.  Here is my
>>> onUpdate
>>> implementation for the DropDownChoice control:
>>> 
>>> protected void onUpdate( AjaxRequestTarget target ) {
>>>   log.debug( "graphStyles onUpdate invoked! SelectedGraphStyle = " +  
>>>  FieldResultsPanel.this.getSelectedGraphStyle() );
>>>   FieldResultsPanel.this.updateGraph();  // Update the model and
>>> re-create
>>> the JFreeChart Image
>>> 
>>>   // fieldGraph is my JFreeChartImage instance (derived from Image)
>>>   // This is supposed to indicate back to the browser that the image
>>> needs
>>> updated.  I think this
>>>   // is working properly
>>>   target.addComponent( FieldResultsPanel.this.fieldGraph );  
>>> }
>>> 
>>> Even though I am updating the model of my JFreeChartImage, it appears
>>> that
>>> the getImageData method is never invoked afterwards.
>>> 
>>> What do I need to do in order to get the image data to be re-read?
>>> 
>>> Here is my JFreeChartImage class:
>>> 
>>> public class JFreeChartImage extends Image {
>>> 
>>>   private static final Logger log = LoggerFactory.getLogger(
>>> JFreeChartImage.class );
>>>   
>>>   private int width;
>>>   private int height;
>>> 
>>>   public JFreeChartImage( String id ) {
>>> super( id );
>>>   }
>>> 
>>>   public JFreeChartImage( String id, int width, int height ) {
>>> this( id );
>>> this.width = width;
>>> this.height = height;
>>>   }
>>>   
>>>   public JFreeChartImage( String id, JFreeCh

Re: Updating a Dynamic Image with AJAX (and JFreeChart)

2007-09-25 Thread David Bernard

Hi,

Have you try to extend NonCachingImage instead of Image  (and comments 
setHeaders(...))?

/david

Jason Mihalick wrote:

I am integrating JFreeChart into my application and I've followed the
JFreeChart example on the wiki.  That works very nicely.  I was impressed. 
What I want to do now is update the graph that I display based on the

selection from a drop down list.  I've successfully added the DropDownChoice
component and added a AjaxFormComponentUpdatingBehavior to it.  I've
verified that my onUpdate( AjaxRequestTarget ) method is being invoked and
I'm receiving the updated value, which is very cool.  Here is my onUpdate
implementation for the DropDownChoice control:

protected void onUpdate( AjaxRequestTarget target ) {
  log.debug( "graphStyles onUpdate invoked! SelectedGraphStyle = " +  
 FieldResultsPanel.this.getSelectedGraphStyle() );

  FieldResultsPanel.this.updateGraph();  // Update the model and re-create
the JFreeChart Image

  // fieldGraph is my JFreeChartImage instance (derived from Image)
  // This is supposed to indicate back to the browser that the image needs
updated.  I think this
  // is working properly
  target.addComponent( FieldResultsPanel.this.fieldGraph );  
}


Even though I am updating the model of my JFreeChartImage, it appears that
the getImageData method is never invoked afterwards.

What do I need to do in order to get the image data to be re-read?

Here is my JFreeChartImage class:

public class JFreeChartImage extends Image {

  private static final Logger log = LoggerFactory.getLogger(
JFreeChartImage.class );
  
  private int width;

  private int height;

  public JFreeChartImage( String id ) {
super( id );
  }

  public JFreeChartImage( String id, int width, int height ) {
this( id );
this.width = width;
this.height = height;
  }
  
  public JFreeChartImage( String id, JFreeChart chart, int width, int height

) {
super(id, new Model( chart ) );
this.width = width;
this.height = height;
  }

  public Component setModel( JFreeChart chart ) {
log.debug( "setModel invoked with chart: " + chart );
return super.setModel( new Model( chart ) );
  }
  
  @Override

  protected Resource getImageResource() {

return new DynamicImageResource(){
  private static final long serialVersionUID = 1L;

  @Override
  protected byte[] getImageData() {
log.debug( "Invoking getImageData..." );
JFreeChart chart = (JFreeChart)getModelObject();
log.debug( "Chart object: " + chart );
return toImageData( chart.createBufferedImage( width, height ) );
  }
  
  @Override

  protected void setHeaders( WebResponse response ) {
if ( isCacheable() ) {
  super.setHeaders(response);
} else {
  response.setHeader( "Pragma", "no-cache" );
  response.setHeader( "Cache-Control", "no-cache" );
  response.setDateHeader( "Expires", 0 );
}
  }
};
  }
 
Any help is much appreciated!


--
Jason


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Updating a Dynamic Image with AJAX (and JFreeChart)

2007-09-25 Thread Jason Mihalick

Thanks for the tip.  That worked!  That was too easy.  :-)

--
Jason

David Bernard-2 wrote:
> 
> Hi,
> 
> Have you try to extend NonCachingImage instead of Image  (and comments
> setHeaders(...))?
> 
> /david
> 
> Jason Mihalick wrote:
>> I am integrating JFreeChart into my application and I've followed the
>> JFreeChart example on the wiki.  That works very nicely.  I was
>> impressed. 
>> What I want to do now is update the graph that I display based on the
>> selection from a drop down list.  I've successfully added the
>> DropDownChoice
>> component and added a AjaxFormComponentUpdatingBehavior to it.  I've
>> verified that my onUpdate( AjaxRequestTarget ) method is being invoked
>> and
>> I'm receiving the updated value, which is very cool.  Here is my onUpdate
>> implementation for the DropDownChoice control:
>> 
>> protected void onUpdate( AjaxRequestTarget target ) {
>>   log.debug( "graphStyles onUpdate invoked! SelectedGraphStyle = " +  
>>  FieldResultsPanel.this.getSelectedGraphStyle() );
>>   FieldResultsPanel.this.updateGraph();  // Update the model and
>> re-create
>> the JFreeChart Image
>> 
>>   // fieldGraph is my JFreeChartImage instance (derived from Image)
>>   // This is supposed to indicate back to the browser that the image
>> needs
>> updated.  I think this
>>   // is working properly
>>   target.addComponent( FieldResultsPanel.this.fieldGraph );  
>> }
>> 
>> Even though I am updating the model of my JFreeChartImage, it appears
>> that
>> the getImageData method is never invoked afterwards.
>> 
>> What do I need to do in order to get the image data to be re-read?
>> 
>> Here is my JFreeChartImage class:
>> 
>> public class JFreeChartImage extends Image {
>> 
>>   private static final Logger log = LoggerFactory.getLogger(
>> JFreeChartImage.class );
>>   
>>   private int width;
>>   private int height;
>> 
>>   public JFreeChartImage( String id ) {
>> super( id );
>>   }
>> 
>>   public JFreeChartImage( String id, int width, int height ) {
>> this( id );
>> this.width = width;
>> this.height = height;
>>   }
>>   
>>   public JFreeChartImage( String id, JFreeChart chart, int width, int
>> height
>> ) {
>> super(id, new Model( chart ) );
>> this.width = width;
>> this.height = height;
>>   }
>> 
>>   public Component setModel( JFreeChart chart ) {
>> log.debug( "setModel invoked with chart: " + chart );
>> return super.setModel( new Model( chart ) );
>>   }
>>   
>>   @Override
>>   protected Resource getImageResource() {
>> 
>> return new DynamicImageResource(){
>>   private static final long serialVersionUID = 1L;
>> 
>>   @Override
>>   protected byte[] getImageData() {
>> log.debug( "Invoking getImageData..." );
>> JFreeChart chart = (JFreeChart)getModelObject();
>> log.debug( "Chart object: " + chart );
>> return toImageData( chart.createBufferedImage( width, height ) );
>>   }
>>   
>>   @Override
>>   protected void setHeaders( WebResponse response ) {
>> if ( isCacheable() ) {
>>   super.setHeaders(response);
>> } else {
>>   response.setHeader( "Pragma", "no-cache" );
>>   response.setHeader( "Cache-Control", "no-cache" );
>>   response.setDateHeader( "Expires", 0 );
>> }
>>   }
>> };
>>   }
>>  
>> Any help is much appreciated!
>> 
>> --
>> Jason
> 
> -
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 
> 
> 

-- 
View this message in context: 
http://www.nabble.com/Updating-a-Dynamic-Image-with-AJAX-%28and-JFreeChart%29-tf4517009.html#a12885649
Sent from the Wicket - User mailing list archive at Nabble.com.


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Updating a Dynamic Image with AJAX (and JFreeChart)

2007-09-26 Thread Andrew Klochkov

Jason Mihalick wrote:

Thanks for the tip.  That worked!  That was too easy.  :-)
  
It's possible update the image in a more smooth manner (to avoid 
blinking). Java part:


   target.appendJavascript("refreshImage(document.getElementById('" 
+ graphImage.getMarkupId() + "'));");


And the script:

   
   function refreshImage(img) {
   if (/refreshImg/.test(img.src)) {
var newSrc = img.src.replace(/&refreshImg.*/, "&refreshImg=" + Math.random());
   img.src = newSrc;
   } else {
   img.src = img.src + "&refreshImg=" + Math.random();
   }
   }
   

--
Andrew Klochkov


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Updating a Dynamic Image with AJAX (and JFreeChart)

2008-02-12 Thread scottomni

I have been unable to get the JFreeChart ToolTips to work in Wicket (NetBeans
6.0).

The wiki example sets the tooltips flag to true, but the resulting web page
contains no image map... thus, no tooltips.

Should this work?

Thanks,

Scott

-- 
View this message in context: 
http://www.nabble.com/Updating-a-Dynamic-Image-with-AJAX-%28and-JFreeChart%29-tp12884455p15439692.html
Sent from the Wicket - User mailing list archive at Nabble.com.


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]