You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by nickponico <sc...@gmail.com> on 2009/06/24 17:12:36 UTC

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

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, 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: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>> 
>> 
>> 
> 
> 

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


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