Hi Sigbjørn, Hi Bob,

Yeah, I think, I get the idea.

So, if you want to use the HTML img tag for streaming, you need a
org.apache.tapestry5.Link (for example, it can be created by a
componentResources.createEventLink("image", id)) or you need to inject
a LinkSource (just as in the UploadStore example), and use the
createPageRenderLink method, because you cannot stream the
BufferedImage object directly.

Thank you both very much for your help. You have solved my first
Tapestry problem in my life. :)

It is not impossible, that someone might be interested in the
solution, so I paste my code here. It uses my Hello1.jpg, Hello2.jpg,
Hello3.jpg and Hello4.jpg, depending on the address.id and pastes them
into a Grid component.

------------
Index.tml:
------------

<t:grid source="addresses" row="address" include="city, image">
      <p:cityCell>
             <div id="CellItem_1">
                 <t:pagelink page="about"
context="address.id">${address.firstName}</t:pagelink>
             </div>
      </p:cityCell>
      <p:imageCell>
           <img src="${getImageLink(address.id)}" alt="the image
should be here" />
      </p:imageCell>
  </t:grid>


-------------
Index.java:
-------------

  public Link getImageLink(int id) {
          return this.componentResources.createEventLink("image", id);
  }

  StreamResponse onImage(final int i) {
        return new StreamResponse() {
          public String getContentType() {return "image/jpeg";}
          public InputStream getStream() throws IOException {           
                  File fnew=new File("d:\\Hello" + i + ".jpg");         
                  BufferedImage originalImage=ImageIO.read(fnew);
                  ByteArrayOutputStream baos=new ByteArrayOutputStream();
                  ImageIO.write(originalImage, "jpg", baos );           
              return new ByteArrayInputStream(baos.toByteArray());
          }
          public void prepareResponse(final Response response) {}
        };
}


Now, I will try to read my JPG Images from my Hibernate/MySql database
and place them into the above mentioned Grid component.

Have a nice day!
Bela


2013/3/17, Sigbjørn Tvedt <sigbjo...@gmail.com>:
> Hi
>
> As Bob Harner said, the "img" tag you are using is a normal html tag that
> takes a url.
> If you look at the example you are linking to, you will see that it is
> using 2 different classes (UploadStore and SomePage)
>
> These pages have different tasks.
> UpploadStore redenders a image based on the ID in the activation
> contextwhile SomePage is the page beeing displayed.
>
>
> You should therefore create a page (without the tml file) that returns the
> binary content when it is activated (you may test this by pointing your
> browser to it. ) and then link to it from your index page.
>
>
> Regards
>
> Sigbjørn Tvedt
>
> On 17 March 2013 01:19, Bob Harner <bobhar...@gmail.com> wrote:
>
>> The src attribute of the img element requires the URL of the image, not
>> the
>> image contents.
>> On Mar 16, 2013 7:46 PM, "Bela Takacs" <bela.takacs....@gmail.com> wrote:
>>
>> > Hi All,
>> >
>> > I am writing my very first program using Tapestry, and I've got my
>> > first problem...
>> >
>> > I want to display an image in my Index.tml template, so I'm trying to
>> > use two files (InlineStreamResponse.java and JPEGInline.java) from
>> > here:
>> > http://wiki.apache.org/tapestry/Tapestry5HowToStreamAnExistingBinaryFile
>> >
>> > Firefox an IE can display my template but neither Firefox nor IE can
>> > display the images (I cannot see any images on the screen). I got the
>> > following error message in my Eclipse/Jetty console
>> > (IllegalArgumentException: '@' character is not valid), but I do not
>> > use any '@' character:
>> >
>> > [INFO] AppModule.TimingFilter Request time: 2 ms
>> > [INFO] AppModule.TimingFilter Request time: 3 ms
>> > [ERROR] TapestryModule.RequestExceptionHandler Processing of request
>> > failed with uncaught exception: Input string
>> > 'com.example.tutorial.pictureHandler.JPEGInline@608a6351' is not
>> > valid; the character '@' at position 47 is not valid.
>> > java.lang.IllegalArgumentException: Input string
>> > 'com.example.tutorial.pictureHandler.JPEGInline@608a6351' is not
>> > valid; the character '@' at position 47 is not valid.
>> >         at
>> >
>> org.apache.tapestry5.internal.services.URLEncoderImpl.decode(URLEncoderImpl.java:144)
>> >         at $URLEncoder_6d6aa2f29b30.decode(Unknown Source)
>> >         at
>> >
>> org.apache.tapestry5.internal.services.ContextPathEncoderImpl.decodePath(ContextPathEncoderImpl.java:92)
>> >         at $ContextPathEncoder_6d6aa2f29b18.decodePath(Unknown Source)
>> >         at
>> >
>> org.apache.tapestry5.internal.services.ComponentEventLinkEncoderImpl.checkIfPage(ComponentEventLinkEncoderImpl.java:501)
>> >         at
>> >
>> org.apache.tapestry5.internal.services.ComponentEventLinkEncoderImpl.decodePageRenderRequest(ComponentEventLinkEncoderImpl.java:475)
>> >         at
>> >
>> org.apache.tapestry5.internal.services.linktransform.LinkTransformerInterceptor.decodePageRenderRequest(LinkTransformerInterceptor.java:68)
>> >         at
>> > $ComponentEventLinkEncoder_6d6aa2f29b0c.decodePageRenderRequest(Unknown
>> > Source)
>> >         at
>> >
>> org.apache.tapestry5.internal.services.PageRenderDispatcher.dispatch(PageRenderDispatcher.java:41)
>> >         at $Dispatcher_6d6aa2f29b0d.dispatch(Unknown Source)
>> >         at $Dispatcher_6d6aa2f29b07.dispatch(Unknown Source)
>> >         at
>> >
>> org.apache.tapestry5.services.TapestryModule$RequestHandlerTerminator.service(TapestryModule.java:302)
>> >         at
>> >
>> org.apache.tapestry5.internal.services.RequestErrorFilter.service(RequestErrorFilter.java:26)
>> >         at $RequestHandler_6d6aa2f29b08.service(Unknown Source)
>> >         at
>> >
>> org.apache.tapestry5.services.TapestryModule$3.service(TapestryModule.java:902)
>> >         at $RequestHandler_6d6aa2f29b08.service(Unknown Source)
>> >         at
>> >
>> org.apache.tapestry5.services.TapestryModule$2.service(TapestryModule.java:892)
>> >         at $RequestHandler_6d6aa2f29b08.service(Unknown Source)
>> >         at
>> >
>> org.apache.tapestry5.internal.services.StaticFilesFilter.service(StaticFilesFilter.java:90)
>> >         at $RequestHandler_6d6aa2f29b08.service(Unknown Source)
>> >         at
>> > com.example.tutorial.services.AppModule$1.service(AppModule.java:89)
>> >         at $RequestFilter_6d6aa2f29b02.service(Unknown Source)
>> >         at $RequestHandler_6d6aa2f29b08.service(Unknown Source)
>> >         at
>> >
>> org.apache.tapestry5.internal.services.CheckForUpdatesFilter$2.invoke(CheckForUpdatesFilter.java:105)
>> >         at
>> >
>> org.apache.tapestry5.internal.services.CheckForUpdatesFilter$2.invoke(CheckForUpdatesFilter.java:95)
>> >         at
>> >
>> org.apache.tapestry5.ioc.internal.util.ConcurrentBarrier.withRead(ConcurrentBarrier.java:85)
>> >         at
>> >
>> org.apache.tapestry5.internal.services.CheckForUpdatesFilter.service(CheckForUpdatesFilter.java:119)
>> >         at $RequestHandler_6d6aa2f29b08.service(Unknown Source)
>> >         at $RequestHandler_6d6aa2f29afb.service(Unknown Source)
>> >         at
>> >
>> org.apache.tapestry5.services.TapestryModule$HttpServletRequestHandlerTerminator.service(TapestryModule.java:253)
>> >         at
>> > org.apache.tapestry5.internal.gzip.GZipFilter.service(GZipFilter.java:53)
>> >         at $HttpServletRequestHandler_6d6aa2f29afd.service(Unknown
>> Source)
>> >         at
>> >
>> org.apache.tapestry5.internal.services.IgnoredPathsFilter.service(IgnoredPathsFilter.java:62)
>> >         at $HttpServletRequestFilter_6d6aa2f29af9.service(Unknown
>> > Source)
>> >         at $HttpServletRequestHandler_6d6aa2f29afd.service(Unknown
>> Source)
>> >         at
>> >
>> org.apache.tapestry5.services.TapestryModule$1.service(TapestryModule.java:852)
>> >         at $HttpServletRequestHandler_6d6aa2f29afd.service(Unknown
>> Source)
>> >         at $HttpServletRequestHandler_6d6aa2f29af8.service(Unknown
>> Source)
>> >         at
>> > org.apache.tapestry5.TapestryFilter.doFilter(TapestryFilter.java:171)
>> >         at
>> >
>> org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1212)
>> >         at
>> > org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:399)
>> >         at
>> >
>> org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
>> >         at
>> > org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182)
>> >         at
>> > org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:766)
>> >         at
>> > org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:450)
>> >         at
>> > org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
>> >         at org.mortbay.jetty.Server.handle(Server.java:326)
>> >         at
>> > org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542)
>> >         at
>> >
>> org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:928)
>> >         at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:549)
>> >         at
>> org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:212)
>> >         at
>> org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)
>> >         at
>> >
>> org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:410)
>> >         at
>> >
>> org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:582)
>> > [INFO] AppModule.TimingFilter Request time: 28 ms
>> >
>> >
>> > Further informations from my pom.xml:
>> >         <tapestry-release-version>5.3.6</tapestry-release-version>
>> >
>> > <artifactId>maven-jetty-plugin</artifactId><version>6.1.16</version>
>> >
>> >
>> > In my template, I tried these two things:
>> > <img src="${getImageThumb()}" />
>> > <img src="${imageThumb}" />
>> >
>> > As a result, I got the following URLs in my Index.tml template (in both
>> > cases):
>> > <img src="com.example.tutorial.pictureHandler.JPEGInline@24ca1465"/>
>> >
>> >
>> > This is the relevant part of my Index.java:
>> > ...
>> >   public StreamResponse getImageThumb() {
>> >         System.out.println("Trying to do that....");
>> >         try {
>> >            return new JPEGInline(new FileInputStream("d:\\Hello.jpg"),
>> > "d:\\Hello.jpg");
>> >         } catch (FileNotFoundException e) {
>> >                 System.out.println("The file (jpg) cannot be found.");
>> >                 e.printStackTrace();
>> >         } catch (Exception ex) {
>> >                 System.out.println("Other problem.");
>> >         }
>> >         return null;
>> >   }
>> >
>> >
>> >
>> > Question: What does the exception, that I copy-pasted above, mean? And
>> > what should I do?
>> >
>> >
>> > Thanks a lot,
>> > Bela
>> >
>> > ---------------------------------------------------------------------
>> > To unsubscribe, e-mail: 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

Reply via email to