Also. > private LinkSource linkSource; This is an internal class, you should be using PageRenderLinkSource. You can replace:
> linkSource.createPageRenderLink(DisplayImagePage.class.getSimpleName(), > false, new Object[]{imageId}); with pageRenderLinkSource.createPageRenderLinkWithContext(DisplayImagePage.class, imageId); Josh On Fri, Aug 5, 2011 at 1:39 PM, David Canteros <davidcanteros....@gmail.com> wrote: > Hi > I have to show a image loaded from database BLOB field. I implemented > Thiago's suggestion, I have created a page with the following code: > > public class ShowImagePage { > > @Inject > private LinkSource linkSource; > (...) > > public Link *getUploadedFile*(String imageId) { > return > linkSource.createPageRenderLink(DisplayImagePage.class.getSimpleName(), > false, new Object[]{imageId}); > } > > public StreamResponse *onActivate*(String imageId) { > this.filename = imageId; > return new StreamResponse() { > > public String *getContentType*() { > return contentType; > } > > public InputStream *getStream*() throws IOException { > User user = > (User)_request.getSession(true).getAttribute("user"); > return user.getImage(); > } > > public void *prepareResponse*(Response response) { > response.setHeader("Content-Disposition", "inline; > filename=" + filename > + ((extension == null) ? "" : ("." + > extension))); > } > }; > } > } > ** > In the javacode of the page where i have to show the image, I injected the > above page and wrote this method > > public Link *getImageLink*(ImageId){ > return showImagewPage.getUploadedFile(imageId); > } > and in html code I put this: > > <img src="${imageLInk}"/> > > It works fine, the image is showed but when I refresh the page (with F5), > the image dissapear. It behavior does not occur if I submit some form placed > in the same page that refresh the page too (the method "onSubmitFrom..." > returns "this" ). I have debugged the code and everything works fine, do you > have any idea about this behavior? > > Thanks!! > > ------------------------------------------------------------------ > David Germán Canteros > > > 2011/3/11 Rich M <rich...@moremagic.com> > >> Thanks everyone for the responses so far, conceptually I think this is >> coming together for me. >> >> So, I'm glad the context path was not a good idea, it felt dirty from the >> beginning. Avoiding that, there are two main options: use the database to >> store/retrieve the images, or use a configured system folder from where I >> can load/save files with Java IO. >> >> Regardless of the option chosen there, the image file will be captured as >> an InputStream and returned as a StreamResponse in some form to a >> page/component. >> >> As far as linking the StreamResponse to an HTML IMG tag, I believe I >> understand the various options presented here. >> >> LLTYK suggests using an EventLink. I was looking through my code and found >> a Captcha implementation I have using a propertyExpression in the TML on the >> src attribute of <IMG> to reference a getImageLink function that returns >> ComponentResources.**createActionLink("image",null)**. Then there is an >> onImage() action handler method that returns a StreamResponse. I understand >> this is ActionLink and not EventLink, but I think the concept must be nearly >> identical. >> >> Alternately, Thiago is suggesting that instead of using ComponentResources >> to generate an ActionLink or EventLink, it may be easier to create a >> seperate Page that handles returning just a StreamResponse. In that case the >> EventLink can be replaced with a PageLink and using an activation context >> the ID for the Image can be passed to the Page so it can load the Image, >> build the StreamResponse, and return it. >> >> <30 minutes later> Okay, the PageLink works out, great! I can see the >> biggest issue I was having was setting up the src attribute for IMG >> correctly. I was stuck thinking it was either the URL to the context path or >> the StreamResponse itself, rather than a link to an event or page that >> returns the StreamResponse. >> >> Thanks, >> Rich >> >> >> >> On 03/11/2011 08:08 AM, Thiago H. de Paula Figueiredo wrote: >> >>> On Fri, 11 Mar 2011 09:24:35 -0300, LLTYK <ll...@mailinator.com> wrote: >>> >>> Nobody's mentioned createEventLink. That's where you get the image url, >>>> create an event link pointing to the event handler that returns the >>>> stream response. >>>> >>> >>> I haven't mentioned it because my preferred approach is to create a page >>> just for returning StreamResponses. It's more reusable, as it can be used to >>> serve images for any page, while an event must be only used inside a give >>> page. >>> >>> >> >> ------------------------------**------------------------------**--------- >> To unsubscribe, e-mail: >> users-unsubscribe@tapestry.**apache.org<users-unsubscr...@tapestry.apache.org> >> For additional commands, e-mail: users-h...@tapestry.apache.org >> >> > --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org For additional commands, e-mail: users-h...@tapestry.apache.org