You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Iren Tuna <ir...@sphinx.at> on 2009/02/13 23:25:43 UTC

[T5.0.18] Bug? : Null property problem with the custom component inside a grid

Hello,

I have implemented a custom component to display (Blob) images. While it
works without a problem inside BeanEditForm and BeanDisplay, inside a Grid a
NullPointerException occurs while trying to pass a property of the actual
object (row) at the grid as a parameter to the component.

The relevant parts of the code:

Image.java (component)
******************
public class Image
{
    ...
    @Parameter
    private Blob data;

    public Link getSrc()
    {
        return resources.createEventLink("displayImage", new Object[]{});
    }

    StreamResponse onDisplayImage()
    {
        return new StreamResponse() {
            public String getContentType()
            {
                return "image/jpeg";
            }

            public InputStream getStream() throws IOException
            {
                try {
                    return data.getBinaryStream();
                }
                catch (SQLException e) {
                    throw new IllegalArgumentException(e);
                }
            }

            public void prepareResponse(Response response)
            {
            }
        };
    }
}

Image.tml
*******
<html xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd">
    < img ... src="${src}"...>
</html>


Edit.tml (page)
***********
...
<t:beaneditform t:id="BookEdit" object="book" model="model"
...
            <t:parameter name="mediumImage">
                <t:image id="literal:book-image-register"
t:alt="literal:bookImage"
                         t:data="book.mediumImage"/>
            </t:parameter>
...
</t:beaneditform>
...

In this page (Edit.tml) there is no problem, and the mediumImage of the book
is passed successfully to the Image component, and displayed. However,
below...


Search.tml (page)
*************
...
<t:grid t:id="BookEdit" t:source="books" row="book" model="model"
...
            <t:parameter name="smallImageCell">
                <t:image id="literal:book-image-register"
t:alt="literal:bookImage"
                         t:data="book.smallImage"/>
            </t:parameter>

            <t:parameter name="titleCell">
                    <t:pageLink t:page="detail"
context="book.id">${book.title}</t:pageLink>
            </t:parameter>
            <t:parameter name="authorsCell">
                 <t:loop source="book.authors" value="author">
                   <div>* ${author.name}</div>
                 </t:loop>
            </t:parameter>
</t:grid>
...

Here (Search.tml), inside the Grid, always NullPointerException is thrown
with the message: "Property 'book' is null in (book.smallImage)". While
there is no problem with the "book.id", "book.title", "book.authors"...

Might this be somehow a problem in tapestry, or am I missing sth. (which is
perhaps more probable)?

Thanks a lot,
iren
-- 
View this message in context: http://n2.nabble.com/-T5.0.18--Bug--%3A-Null-property-problem-with-the-custom-component-inside-a-grid-tp2324166p2324166.html
Sent from the Tapestry Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: [T5.0.18] Bug? : Null property problem with the custom component inside a grid

Posted by Marcus Veloso <mv...@gmail.com>.
Hi Howard,
> "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 you can elaborate the solution?

Here is the "relevant" code:
[
http://www.nabble.com/-T5.1--Using-a-custom-image-component-inside-a-Grid-td24421215s302.html]<http://www.nabble.com/-T5.1--Using-a-custom-image-component-inside-a-Grid-td24421215s302.html>

Regards,

Marcus Veloso

Re: [T5.0.18] Bug? : Null property problem with the custom component inside a grid

Posted by Howard Lewis Ship <hl...@gmail.com>.
It's very simple.

When the Grid component renders, it is keeping the book property up-to
date as the components in its body render.  Thus, if you look at the
rendered output, you'll see an <img> element and a URL that references
the component and the displayImage custom event.

Now what happens when that URL is triggered?

The Image component attempts to read the book property and
de-reference the binaryStream property.  Well, it was the Grid
components job to keep the book property up-to date *while it was
rendering*, but the Grid component isn't rendering in this new
request.

In fact, if you look at the rendered URL you'll see that every time
the Image component rendered, it rendered the same URL.  How is it
supposed to know from that which book's image to stream to the client?

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.

On Thu, Feb 19, 2009 at 8:05 AM, Iren Tuna <ir...@sphinx.at> wrote:
>
> If there are no other ideas, whether it should work or not (and why), the way
> I have done it, aside from the alternative solution hints, maybe I should
> try to create a bug issue in T5 jira. For me it is still not clear, why it
> does not work. Any other ideas?
>
> --
> iren
>
>
>
> Thiago H. de Paula Figueiredo wrote:
>>
>> On Sun, Feb 15, 2009 at 8:21 AM, Otho <ta...@googlemail.com> wrote:
>>> One possible solution is to store the images in the filesystem instead of
>>> the database and store only the filename in the db from where you can
>>> construct a path. But I think that isn't compatible with your
>>> requirements?
>>
>> Maybe a better solution would be to provide an Asset binding (like
>> context and classpath) and AssetFactory, both pulling the images from
>> the database.
>>
>> --
>> Thiago
>>
>>
>
> --
> View this message in context: http://n2.nabble.com/-T5.0.18--Bug--%3A-Null-property-problem-with-the-custom-component-inside-a-grid-tp2324166p2353720.html
> Sent from the Tapestry Users mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>



-- 
Howard M. Lewis Ship

Creator Apache Tapestry and Apache HiveMind

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: [T5.0.18] Bug? : Null property problem with the custom component inside a grid

Posted by Iren Tuna <ir...@sphinx.at>.
If there are no other ideas, whether it should work or not (and why), the way
I have done it, aside from the alternative solution hints, maybe I should
try to create a bug issue in T5 jira. For me it is still not clear, why it
does not work. Any other ideas?

--
iren



Thiago H. de Paula Figueiredo wrote:
> 
> On Sun, Feb 15, 2009 at 8:21 AM, Otho <ta...@googlemail.com> wrote:
>> One possible solution is to store the images in the filesystem instead of
>> the database and store only the filename in the db from where you can
>> construct a path. But I think that isn't compatible with your
>> requirements?
> 
> Maybe a better solution would be to provide an Asset binding (like
> context and classpath) and AssetFactory, both pulling the images from
> the database.
> 
> -- 
> Thiago
> 
> 

-- 
View this message in context: http://n2.nabble.com/-T5.0.18--Bug--%3A-Null-property-problem-with-the-custom-component-inside-a-grid-tp2324166p2353720.html
Sent from the Tapestry Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: [T5.0.18] Bug? : Null property problem with the custom component inside a grid

Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
On Sun, Feb 15, 2009 at 8:21 AM, Otho <ta...@googlemail.com> wrote:
> One possible solution is to store the images in the filesystem instead of
> the database and store only the filename in the db from where you can
> construct a path. But I think that isn't compatible with your requirements?

Maybe a better solution would be to provide an Asset binding (like
context and classpath) and AssetFactory, both pulling the images from
the database.

-- 
Thiago

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: [T5.0.18] Bug? : Null property problem with the custom component inside a grid

Posted by Otho <ta...@googlemail.com>.
You are right.

I tried it out and came to the same result. The Image component works
everywhere except within a t:loop. It seems, that the PropertyConduitSource
is the reason for that. Is it possible, that one has to supply a custom
translator for byte[] ?

One possible solution is to store the images in the filesystem instead of
the database and store only the filename in the db from where you can
construct a path. But I think that isn't compatible with your requirements?

Otho

2009/2/14 Iren Tuna <ir...@sphinx.at>

>
> Hi,
>
> @Persist is already there on "books". Anyway, I have no problem with the
> listing of the search results. Only the images in the grid are not
> displayed, because of this "null property" problem. I have already tried
> @Persist on the "book" property (row object of the grid) in the Search
> page,
> too. In this case, the images are indeed displayed, but then in the image
> cells of all books only the image of the last book in the result list. I
> mean, if there are 3 books, three times the image of the last book, which
> is
> for me somehow comprehensible (not totally yet, though :-)).
>
> Thanks anyway for the reply.
> iren
>
>
>
>
> Otho wrote:
> >
> > Maybe some problem in the setup of the grid page?
> >
> > Like forgetting the @Persist on the books list?
> >
> > Otho
> >
> >
>
> --
> View this message in context:
> http://n2.nabble.com/-T5.0.18--Bug--%3A-Null-property-problem-with-the-custom-component-inside-a-grid-tp2324166p2326447.html
> Sent from the Tapestry Users mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>

Re: [T5.0.18] Bug? : Null property problem with the custom component inside a grid

Posted by Iren Tuna <ir...@sphinx.at>.
Hi,

@Persist is already there on "books". Anyway, I have no problem with the
listing of the search results. Only the images in the grid are not
displayed, because of this "null property" problem. I have already tried
@Persist on the "book" property (row object of the grid) in the Search page,
too. In this case, the images are indeed displayed, but then in the image
cells of all books only the image of the last book in the result list. I
mean, if there are 3 books, three times the image of the last book, which is
for me somehow comprehensible (not totally yet, though :-)).

Thanks anyway for the reply.
iren




Otho wrote:
> 
> Maybe some problem in the setup of the grid page?
> 
> Like forgetting the @Persist on the books list?
> 
> Otho
> 
> 

-- 
View this message in context: http://n2.nabble.com/-T5.0.18--Bug--%3A-Null-property-problem-with-the-custom-component-inside-a-grid-tp2324166p2326447.html
Sent from the Tapestry Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: [T5.0.18] Bug? : Null property problem with the custom component inside a grid

Posted by Otho <ta...@googlemail.com>.
Maybe some problem in the setup of the grid page?

Like forgetting the @Persist on the books list?

Otho