|
Hi Wicket Team and Wicket Mailinglist! As this is my first post on this list, I would like
to introduce myself. My name is Sebastian and I am working on a university
project, comparing Java web frameworks. As you might guess, my primary topic is
the Wicket framework ;). I am not what one would call a programmer or coder, I guess.
Rather someone familiar with the underling concepts, but sometimes a bit lots
with the actual implementations of a certain language. So please excuse me, if
my questions are stupid ;). My problem at this moment is the following. I need to
implement a feature in wicket that lets me upload images to a webpage and then
use those images to be displayed on certain pages. It doesn’t really
matter if the images are stored on the file system or in a database. I am not looking
for a solution to an explicit problem but rather for a best practice that shows
how the wicket framework supports such a feature. I have tried to read up on anything I could find addressing
such a feature. But everything I got so far is either way beyond my scope of
understanding, not offering enough to archive the goal or just not working as I
understand it should. I have tried to read the example in the wiki (http://www.wicket-wiki.org.uk/wiki/index.php/UploadDownload),
but I can not really follow it. Too many libraries used that are not included
and overall to confusing for a non professional like myself. I did understand the example for the upload in the
wikiexamples though. No problems writing files to disk or even to database,
following that example code. My attempt to store images in the Database is looking
something like this: To write to the Database, I use this code sniped: public
final void onSubmit() { try { //
get the content of the upload field final
FileUpload upload_image = upload.getFileUpload(); //
create a byte array of the uploaded item byte[]
bild = upload_image.getBytes(); if(upload_image
!= null) {
*write byte[] to database* } } catch
(Exception e) { } } So far so good. Got my byte array stored. The source
file is a jpeg image. I am not sure if I miss some kind cast here to let the
system know what *sort* of byte array it should use. When I try to retrieve the image from the database, I
use the following code: public
ResourceReference getImage() { return
new ResourceReference(some.class, "bild") { public
BufferedDynamicImageResource newResource() { try { // get
the byte[] from DB byte[]
bild = a.getBild(); // create
a buffered image template BufferedDynamicImageResource resource = new
BufferedDynamicImageResource(); BufferedImage
image = new BufferedImage(200, 200, BufferedImage.TYPE_INT_RGB); //
transform the byte[] back to an image (does it work that way? How does //
java know it was a jpeg before and not a gif for example?) java.awt.Image
i = Toolkit.getDefaultToolkit().createImage(bild); //
convert image to buffered image image.getGraphics().drawImage(i,
0, 0, null); Graphics
g = image.getGraphics(); g.drawImage(i,
0, 0, null); g.dispose(); //
return the image resource.setImage(image); return
resource; } catch
(Exception e) { } } }; } This leads to a black box in the place my image is
supposed to be. So I guess somewhere along the way I lose my image information.
My best guess is, that the problem lies in the image conversion. Jpeg isn’t
a java.awt.image, I suppose. But still leaves the question, does wicket offer
anything more to me to help me here? To make things (even) simpler for me? The next attempt I took was storing images on the
file system. This went pretty well, as it pretty much is covered by the upload
example from the wicket examples. I was able to put the files in pretty much
any directory I liked, following that code. The problems started once again,
when I tried to retrieve and reuse the stored data. In the past I did a bit of PHP
programming and was used to just store my things anywhere on the web server as
a file and access them again via URL. This doesn’t really work for me in the
java world (using jboss application server, ejb3, wicket), as the resources are
stored in archives and not easily written to archives at runtime (at least to
my current knowledge – please correct me if wicket offers a way to do
such a thing). I understand that wicket uses resource references to
stream resources not in the actual “environment” of the core application.
But I cannot seem to get that concept working correctly. I guess, my closest
attempt to reference a resource outside an archive would be this one: java.io.File
f = new java.io.File("d:/someimage.jpg"); File
ff = new File(f); FileResourceStream
frs = new FileResourceStream(ff); ResourceStreamRequestTarget
resource = new ResourceStreamRequestTarget(frs, frs.getContentType()); String url = ""> WebMarkupContainer
bild = new WebMarkupContainer("bild"); add(bild); bild.add(new
SimpleAttributeModifier("src", url)); which just leads to a runtime exception, I fail to understand.
Something about not being able to stream the object, I think. Once again, I am sure the problem is just based on my
lack of java skills, rather then by anything wicket does, but never the less
the question stands: Is there anything wicket can do for me in that situation
to make my life easier and maybe even get the things done I want to do? What would
be the best practice to archive the goal, using wicket? My current solution is
a second webserver to which I upload the imagefiles and then refer them via URL
in wicket, pretty much like I would, using PHP. But I guess that cannot be it,
can it? Thanks in advance for anyone taking the time to read
this or even give me a few pointers. Sorry if my lack of java knowledge causes
most of my problems. Please feel free to point me to any resource filling me in
on what I am missing. Regards, Sebastian Pflugbeil |
------------------------------------------------------------------------- Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________ Wicket-user mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/wicket-user
