Hi,

Yea, I wasn't expecting TML shorthand, rather some way to load the proper information in the page class.

I couldn't really see how the ContextAssetFactory would be useful. I was under the impression internal services shouldn't be used, in fact trying to Inject it gives an error.

In terms of loading the file as a Resource (required parameter for the createAsset method), I've had trouble with that as well.

I have a database entity that stores a reference to the image file (this is the same entity in the grid I mentioned before). When creating or editing this entity, I tried making a validation check that the file actually exists in the system.

    Resource resc = new ContextResource(cimpl, 
"src/main/webapp/layout/images/products/"+link);

    if(!resc.exists()){

            debug("\nImageLink is to a non-existant file! " + resc.getPath() + " get file: " + 
resc.getFile() + " to url: " + resc.toURL() + "\n\n");

            _form.recordError(imageLink 
,messages.get("image-link-non-existant"));

            return;

    }


Even though the files I tried definitely exist (I know because if I remove the validation I can get some images to show in pages loading the entity), the condition on !resc.exists() always fails.

I have code elsewhere that uses

Resource resc = new ContextResource(cimpl, 
"src/main/webapp/layout/images/products/"+link);

to load .xml files with the beginning to the path "src/main/webapp/.." that works, so I'm having a hard time understanding why it fails. The other implementation is in components.reports package, while this one is in pages.admin package. That wouldn't make a difference on the path needed for the ContextResource, would it?

I actually got passed the filter issue by doing this:

instead of TML having <img src="/app/assets/ctx/1.0/layout/images/products/${prod.imageLink}" />

I moved the src text to the page class

<img src="${getImageThumb()}" />

maybe that wasn't even the issue.. So it seems I am able to load the images alright then.

I could still use some help with the Resource checking. Is that the best idea for validating the existence of a file in the context (assuming I get it to work properly)?

Thanks,
Rich

On 12/14/2010 06:52 AM, LLTYK wrote:
I don't think there's a tml shorthand. You'd use ContextAssetFactory in your
java code:
http://tapestry-users.832.n2.nabble.com/T5-How-to-load-image-Asset-from-filesystem-td2454924.html#a2455270

But that would generate the same /app/assets links, just not hardcoded. This
filter issue remains a mystery, tell us more about it. What do your css urls
look like?

   Hi,

   I'm having a hard time figuring out how to dynamically display some
   images I have in a sub-path of my webapp/ folder in my Tapestry
   application (1.5.0.5).

   I have db entities that store the names of files in a folder in
   webapp/layout/images/products/, and in a TML page using a grid, I
   want to be able to display these images.

   The only way I was able to get an image to display was to provide a
   path like: /app/assets/ctx/1.0/layout/images/products/${prod.imageLink}

   That gave me problems with my Application filter/dispatcher,
   however, as it seemed to regard this is a page access outside the
   scope of the user-session context and log out the user.

   I'm pretty sure I shouldn't be hardcoding that reference to the
   asset from a url anyway, how can I have it load the image through
   tapestry like all the other images in the site, like the ones I load
   through CSS that do not break the application filter/dispatcher?

   I hope I was clear enough as to what my problem is.

   Thanks,
Rich

Reply via email to