You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Steve Swinsburg <st...@gmail.com> on 2009/02/03 18:59:38 UTC

ajax submit of form caching images

Hi all,

I have two search forms on the one page, one for searching by name,  
one for searching by interest.

When either is submitted via Ajax, it gets the results and then  
repaints a ListView. This List View has an LDM that wraps the results.  
This is all working fine, the data is coming back as expected.

What is not working is in the populateItem method of the ListView, it  
retrieves an image for the user. On the first submit, this works and  
it gets the correct image (as byte[]) for each user that was found, on  
subsequent searches the first image seems to be cached. It seems to be  
using the same byte[] for the first item of the previous search, on  
the first iteration.

Do I need to get the image and add it to my SearchResult item and  
return that as another property in my object? Currently it's done in  
the populateItem method based on the result found.


Has anyone come across this before?

Simplified code:

// model to wrap search results
LoadableDetachableModel resultsModel = new LoadableDetachableModel(){
	protected Object load() {
		return results;
	}
};
		
		
		
//search results, calls LDM
ListView resultsListView = new ListView("results-list", resultsModel) {
			

	protected void populateItem(ListItem item) {
		
	SearchResult searchResult = (SearchResult)item.getModelObject();
		    	
	//get userUuid
	final String userUuid = searchResult.getUserUuid();
		    	
	final byte[] photo;
	if(isAllowed) {
		photo = profile.getImageForUser(userUuid);
	} else {
		photo = null;
	}
	
	//do stuff
	}
};


and in the form:
protected void onSubmit(AjaxRequestTarget target, Form form) {					
	results = new ArrayList<SearchResult>(profile.findUsers(searchText));
	target.addComponent(resultsListView);
}



thanks,
Steve
	

Re: ajax submit of form caching images

Posted by Steve Swinsburg <s....@lancaster.ac.uk>.
SOLVED!

used NonCachingImage instead of Image when rendering the component to  
add random guff to the end of the img src url. woo hoo!


cheers,
Steve




On 3 Feb 2009, at 17:59, Steve Swinsburg wrote:

> Hi all,
>
> I have two search forms on the one page, one for searching by name,  
> one for searching by interest.
>
> When either is submitted via Ajax, it gets the results and then  
> repaints a ListView. This List View has an LDM that wraps the  
> results. This is all working fine, the data is coming back as  
> expected.
>
> What is not working is in the populateItem method of the ListView,  
> it retrieves an image for the user. On the first submit, this works  
> and it gets the correct image (as byte[]) for each user that was  
> found, on subsequent searches the first image seems to be cached. It  
> seems to be using the same byte[] for the first item of the previous  
> search, on the first iteration.
>
> Do I need to get the image and add it to my SearchResult item and  
> return that as another property in my object? Currently it's done in  
> the populateItem method based on the result found.
>
>
> Has anyone come across this before?
>
> Simplified code:
>
> // model to wrap search results
> LoadableDetachableModel resultsModel = new LoadableDetachableModel(){
> 	protected Object load() {
> 		return results;
> 	}
> };
> 		
> 		
> 		
> //search results, calls LDM
> ListView resultsListView = new ListView("results-list",  
> resultsModel) {
> 			
>
> 	protected void populateItem(ListItem item) {
> 		
> 	SearchResult searchResult = (SearchResult)item.getModelObject();
> 		    	
> 	//get userUuid
> 	final String userUuid = searchResult.getUserUuid();
> 		    	
> 	final byte[] photo;
>
> 	if(isAllowed) {
> 		photo = profile.getImageForUser(userUuid);
> 	} else {
> 		photo = null;
> 	}
> 	
> 	//do stuff
> 	}
> };
>
>
> and in the form:
> protected void onSubmit(AjaxRequestTarget target, Form form) {					
> 	results = new ArrayList<SearchResult>(profile.findUsers(searchText));
> 	target.addComponent(resultsListView);
> }
>
>
>
> thanks,
> Steve
> 	
>