Actually, I think mounting a custom resource _is_ the way to go.

To keep things simple, let me suggest two options:

(1) Create a custom resource which serves the correct image based on a url parameter (see WebResource)
This will allow you to generate user-friendly urls to your images

(2) Create a custom component which implements IResourceListener; You can then generate a session-specific url for this component, which when requested by a browser will call onResourceRequested(). You can then send the image based on component-specific variables, e.g. a database-id;

(1) has the benefit of non-session-specific (seo-friendly) urls
(2) has the benefit of having all image related functionality in a single component (both generating the url and serving the image)

Bas

Op 5-8-2011 19:58, schreef Dan Retzlaff:
It sounds like a shared resource is not the right solution for your problem.
Just throw a wicket:id on your Lightbox image tag and create a Wicket Image
like "image5" of the wicketstuff examples link I sent.

On Fri, Aug 5, 2011 at 10:46 AM, Miroslav F.<[email protected]>  wrote:

Answer myself: should be solution before
Start.get().getSharedResources().add("image" + random.toString() + ".jpg",
image);
do something like "unmount all previosly mounted images"?

In Application.init() isn't possible to mount them - I don't know which
page
user click. In database is around 1.000 images
and there are on around 100 pages (every page has around 10 images). For me
it looks crazy in Application.init() take all images
from DB and mount them.


-----Original Message-----
From: Miroslav F. [mailto:[email protected]]
Sent: Friday, 05. August 2011 18:54
To: [email protected]
Subject: RE: tomcat eats memory

Using non-shared images? My problem is that I need same url
for href in<a>  and for src in<img>  for lightbox to work.



-----Original Message-----
From: Dan Retzlaff [mailto:[email protected]]
Sent: Friday, 05. August 2011 18:45
To: [email protected]
Subject: Re: tomcat eats memory

This is your problem:

Start.get().getSharedResources().add("image" +
random.toString() + ".jpg", image);

Adding shared resources during page construction is very unusual.
Consider registering shared resources in
Application.init(), or using
non-shared images. Refer to http://wicketstuff.org/wicket/images/

On Fri, Aug 5, 2011 at 9:20 AM, Miroslav F.
<[email protected]>  wrote:
Hi folks,

I have these classes:

package com.myapp;
public class Minerals extends WebPage{
        public Minerals(){
                RepeatingView repeater = new
RepeatingView("repeater");
                //data from database - images and descriptions
                ArrayList dataFromDB = (new
ImagesMinerals()).load();
                //descriptions
                ArrayList desc = new ArrayList();
                desc = (ArrayList) dataFromDB.get(0);
                //images
                ArrayList images = new ArrayList();
                images = (ArrayList) dataFromDB.get(1);
                int size = images.size();
                for(int i = 0; i<  size; i++){
                        String repeaterID = repeater.newChildId();
                        ImageRepeater repeaterChild = new
ImageRepeater(repeaterID);
                        //add description
                        repeaterChild.add(new Label("description",
(String) desc.get(i)));
                        //add image
                        DBImage image = new DBImage();
                        image.setImageData((byte[]) images.get(i));
                        //not caching on browser
                        Double random = Math.random();
                        //put shared resource (image) on clean path

Start.get().getSharedResources().add("image" +
random.toString() + ".jpg", image);
                        ResourceReference imageResource = new
ResourceReference("image" + random.toString() + ".jpg");
                        String url =
RequestCycle.get().urlFor(imageResource).toString();
                        //href in<a>  and src in<img>
should have same
path because lightbox won't work...
                        ExternalLink odkaz = new
ExternalLink("anchor",
url);
                        WebMarkupContainer imageSrcAttribute = new
WebMarkupContainer("image");
                        imageSrcAttribute.add(new
AttributeModifier("src", new Model<String>(url)));
                        odkaz.add(imageSrcAttribute);
                        odkaz.add(new
SimpleAttributeModifier("title",
(String) desc.get(i)));
                        repeaterChild.add(odkaz);
                        repeater.add(repeaterChild);
                }
                this.add(repeater);
        }
}

package com.myapp;
public class ImagesMinerals extends
LoadableDetachableModel<ArrayList<byte[]>>{
        @Override
        protected ArrayList load(){
                DBGetImages databaseMinerals = new DBGetImages();
                ArrayList dataMineraly =
databaseMinerals.getData();
                return dataMinerals;
        }
}

My problem is that when i again and again click on page the
memory in
tomcat is eaten and I end-up with Java heap space error. Doesn't
matter if heap is 64MB or 1GB on start, after some clicks
memory is
eaten.

Somethink wrong with my LDM?

Miro



---------------------------------------------------------------------
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]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]


Reply via email to