ok - that's how it looks:
------------------------------------------------------------------------------------
this is a ListView on the panels left side:
add(listaObrazow = new ListView("pics", obrazki) {
public void populateItem(final ListItem listItem) {
final String obr = (String)listItem.getModelObject();
AjaxLink linka = new AjaxLink("picAjaxLink") {
public void onClick(AjaxRequestTarget
ajaxRequestTarget) {
imgPreview.setImageResource(
EbokTools.getImageResource(
(String)listItem.getModelObject()
)
);
ajaxRequestTarget.addComponent(imgPreview);
myModal.setObraz((String)listItem.getModelObject());
ajaxRequestTarget.addComponent(wyborObrazow);
}};
linka.add(new Label("pic",new Model(obr)));
listItem.add(linka);
}
});
------------------------------------------------------------------------------------
that's getImageResource method:
public static ByteArrayResource getImageResource(String picName) {
byte[] plik = null;
try {
plik = EbokTools.fileToArray(
new File(
EbokSettings.getImgDir()+"/"+picName));
} catch (IOException ex) {
ex.printStackTrace();
}
return new ByteArrayResource("img",plik);
}
------------------------------------------------------------------------------------
As I wrote before imgPreview is a NonCachingImage object placed on the
same Modal Window as ListView. Its created in the panel constructor using
method:
EbokTools.getImage("imgPreview", "nopic.jpg");
getImage looks like this:
public static NonCachingImage getImage(String wicketID, String
picName) {
return new NonCachingImage(wicketID,getImageResource(picName));
}
---------------------------------------------------------------------------------
To make it work I need to:
- open modal window
- click on one of the AjaxLinks on listaObrazow (it doesn't trigger image
refresh :\ )
- close modal
- open it again
After that images are changing on clicking AjaxLinks - as they should.
best regards,
Karol
Dnia 29-02-2008 o 10:15:55 Nino Saturnino Martinez Vazquez Wael
<[EMAIL PROTECTED]> napisał(a):
Could you show us some code?
regards
Karol Wrzesniewski wrote:
Thanks for all your help.
NonCachingImage is exacly what I wanted.
It works fine but only after I open modal window, call
setImageResource, close modal and reopen it again.
After first call of modal window default image is created, when I'm
trying to change it "nothing happens" exacly like with "plain" Image
objects. But when I close modal and open it again everything works as
intended to, pictures are refreshing using chosen resources.
regards,
Zyx
Dnia 28-02-2008 o 10:22:40 Nino Saturnino Martinez Vazquez Wael
<[EMAIL PROTECTED]> napisał(a):
:) I think thats the point of noncaching image thats already there,
it's just that people gets confused by this...
Bernard Niset wrote:
Hi,
I had the same issue yesterday and found a solution somewhere else in
this mailing list. Adding some random query to the url forces the
browser not to reuse a cached image. To achieve that you have to
subclass Image and override onComponentTag like this:
@Override
protected void onComponentTag(ComponentTag tag)
{
super.onComponentTag(tag);
String src = (String) tag.getAttributes().get("src");
src = src + "&rand=" + Math.random();
tag.getAttributes().put("src", src);
}
Bernard.
Igor Vaynberg wrote:
most people want stable urls for their images i would imagine, so
they
can be cached by the browser.
in case of ajax this doesnt work because the url has to change so
that
browser needs to know to refresh it.
maybe image can know if its requested within an ajax request and
automatically add random noise to the url...there maybe room for
improvement here.
please add an rfe
-igor
On Wed, Feb 27, 2008 at 11:12 AM, Nino Saturnino Martinez Vazquez
Wael
<[EMAIL PROTECTED]> wrote:
Should nocachingImage be default, and then have a cachingImage? Or
would
that result in the same amount of confusion? WDYT?
As a couple of people has been confused by this...
regards Nino
Igor Vaynberg wrote:
> use NonCachingImage
>
> -igor
>
>
> On Wed, Feb 27, 2008 at 2:43 AM, Karol Wrzesniewski
> <[EMAIL PROTECTED]> wrote:
>
>> Hi,
>>
>> I'm having problems with refreshing an Image using AjaxLink.
>>
>> I have a ModalWindow. On it's left side theres a ListView
containing Ajax
>> links:
>>
>> ----------
>> add(listaObrazow = new ListView("pics", obrazki) {
>> public void populateItem(final ListItem listItem) {
>> final String obr =
(String)listItem.getModelObject();
>> listItem.add(new Label("pic",new Model(obr)));
>>
>> listItem.add(new AjaxLink("picAjaxLink") {
>> public void onClick(AjaxRequestTarget
>> ajaxRequestTarget) {
>>
>> imgPreview.setImageResource(
>> EbokTools.getImageResource(
>>
(String)listItem.getModelObject()
>> )
>> );
>>
>>
ajaxRequestTarget.addComponent(imgPreview);
>>
>>
>>
myModal.setObraz((String)listItem.getModelObject());
>>
ajaxRequestTarget.addComponent(wyborObrazow);
>> }});
>> }
>> });
>> ----------
>>
>>
>>
>> imgPreview is an Image object, placed on the same modal
Window. What Im
>> trying to achieve is to refresh this image after the AjaxLink
is clicked.
>> Unfortunately it doesn't. After I click on AjaxLink content of
form
>> "wyborObrazow" is refreshed, but image stays unchanged.
>>
>> Image resource is being changed - i know that because after i
close modal
>> and open it again "imgPreview" is showing me the "right"
Resource.
>>
>> The problem is that calling
ajaxRequestTarget.addComponent(imgPreview);
>> after changing imageResource doesn't seem to be enough.
>>
>> I would be very grateful for some hints.
>>
>> best regards,
>> Zyx
>>
>> --
>>
>>
---------------------------------------------------------------------
>> To unsubscribe, e-mail: [EMAIL PROTECTED]
>> For additional commands, e-mail: [EMAIL PROTECTED]
>>
>>
>>
>
>
---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>
>
--
Nino Martinez Wael
Java Specialist @ Jayway DK
http://www.jayway.dk
+45 2936 7684
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
--
___________________________________________________
Karol Wrześniewski, pokój: SSE III F3.5, GG:3494610
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]