You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Marcus Veloso <mv...@gmail.com> on 2009/07/10 05:23:06 UTC
[T5.1] Using a custom image component inside a Grid
Hi,
from here (
http://www.nabble.com/-T5.0.18--Bug--:-Null-property-problem-with-the-custom-component-inside-a-grid-to22006082.html#a22021616
)
In fact, if you look at the rendered URL you'll see that every time
the Image component rendered, it rendered the same URL.
Yes, it's always the same image (the last one) in grid component.
The solution is to use event context to identify the book, or in some
other way, identify where the data stream is supposed to come from.
Sorry, but i can't figured this out.
Perhaps someone can elaborate the solution?
Here is the code:
ShowImage.java (component)
******************
public class ShowImage {
@Property
@Parameter(required = true)
private ImageDO image;
...
public Link getImageToShow()
{
return resources.createEventLink("imageEvent", image.getId());
}
public Object onImageEvent(String id) {
try {
// Getting image from database.
final InputStream is = iDAO.getImageInputStreamById(id);
return new StreamResponse()
{
public String getContentType() { return "image/jpeg"; }
public InputStream getStream() throws IOException { return is; }
public void prepareResponse(Response arg0) {}
};
}
...
}
ImageDO.java (bean)
****************
public class ImageDO {
private String id;
private byte[] image;
...
ShowImage.tml (component)
*****************
<div>
<img src="${imageToShow}" alt="photo" />
</div>
List.tml (page)
********
...
<table t:type="grid" source="LisOfImages" object="oneImage" >
<t:parameter name="imageCell">
<t:showImage image="oneImage" />
</t:parameter>
...
</table>
Thank in advance,
Marcus Veloso