Hello,
I am building a simple Page. The Page has a form and allows an user
to upload a profile picture.
If the user does not have a profile picture, then I want to display a
standard
picture. This should be a shared resource, so the browser can cache it.
Now if the user uploads a picture, the new picture should be shown instead.
I tried and played with shared resources and WebResource but I cant
get it working.
This is my code:
Image image = null;
final byte[] pic = MyApplication.get().getUserPicFromDB(userid);
if (pic == null) {
image = new Image("photo", new
ResourceReference(MyApplication.PROFILE_STANDARD));
} else {
WebResource resource = new WebResource() {
public IResourceStream getResourceStream() {
IResourceStream resourceStream = new
AbstractResourceStream() {
private InputStream is;
public InputStream getInputStream() throws
ResourceStreamNotFoundException {
is = new BufferedInputStream(new
ByteArrayInputStream(pic));
return is;
}
public void close() throws IOException {
is.close();
}
};
return resourceStream;
}
};
image = new Image("photo", resource);
}
add(image)
If an user has no picture and he uploads one, then I still see the share
resource.
Ok, because the Page was constructed with the shared resource.
Then I tried to test if a user picture is present in the getResourceStream()
Method of WebResource:
WebResource resource = new WebResource() {
public IResourceStream getResourceStream() {
IResourceStream resourceStream;
final byte[] pic =
MyApplication.get().getUserPicFromDB(userid);
if (pic != null) {
resourceStream = new AbstractResourceStream() {
private InputStream is;
public InputStream getInputStream() throws
ResourceStreamNotFoundException {
is = new BufferedInputStream(new
ByteArrayInputStream(pic));
return is;
}
public void close() throws IOException {
is.close();
}
};
} else {
resourceStream = new
ResourceReference(MyApplication.PROFILE_STANDARD)
.getResource().getResourceStream();
}
return resourceStream;
}
};
add(new Image("photo", resource));
But now I get a NullPointerException:
at .....PhotoUploadPage$1.getResourceStream(PhotoUploadPage.java:66)
at org.apache.wicket.Resource.init(Resource.java:199)
at org.apache.wicket.Resource.onResourceRequested(Resource.java:105)
at
org.apache.wicket.markup.html.image.resource.LocalizedImageResource.onResourceRequested(LocalizedImageResource.java:198)
at
org.apache.wicket.markup.html.image.Image.onResourceRequested(Image.java:147)
I would be thankful for suggestions.
Thanks
--
View this message in context:
http://www.nabble.com/Resource-SharedResource---Display-an-image-tp18348115p18348115.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]