You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Peter Farkas <pf...@gmail.com> on 2013/01/22 19:58:05 UTC

Null pointer exception when updating a component in a loop

I'm try to show a list of components with AJAX zones in a table:



An 'ExecutableRowPair' consists of a header row (that's always visible) and
a details row, that's loaded through AJAX. The request is triggered by an
event link in the header row.



In ExecutablePair.java, I'm injecting the component as follows:

    

When rendering the AJAX response, Tapestry tries to evaluate an expression
on 'child' (*), but 'child' is null.

Why does Tapestry need the value of 'child'? How is it supposed to know?




--
View this message in context: http://tapestry.1045711.n5.nabble.com/Null-pointer-exception-when-updating-a-component-in-a-loop-tp5719424.html
Sent from the Tapestry - User 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: Null pointer exception when updating a component in a loop

Posted by Thiago H de Paula Figueiredo <th...@gmail.com>.
On Wed, 23 Jan 2013 13:54:58 -0200, Peter Farkas <pf...@gmail.com>  
wrote:

> Thiago H de Paula Figueiredo wrote
>> I'm sorry, but you're wrong here. It has absolutely nothing to do with
>> loops. Nothing. The issue, as I've said before, was not passing a
>> parameter in an later AJAX render. The first render, a full page one,
>> passed the parameter correctly. A second one, AJAX, didn't. That's why  
>> the
>> addition of the object in the context fixes your code. Loop is a  
>> component
>> like any other in Tapestry, not having any special treatment.
>
> Thank you very much for the clarification. I'm glad it's that simple :)

:) It's simple, as you said, but the two renders, one full, another  
partial (AJAX), makes it a little more complicated to understand and to  
get it right.

-- 
Thiago H. de Paula Figueiredo

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


Re: Null pointer exception when updating a component in a loop

Posted by Peter Farkas <pf...@gmail.com>.
Thiago H de Paula Figueiredo wrote
> I'm sorry, but you're wrong here. It has absolutely nothing to do with  
> loops. Nothing. The issue, as I've said before, was not passing a  
> parameter in an later AJAX render. The first render, a full page one,  
> passed the parameter correctly. A second one, AJAX, didn't. That's why the  
> addition of the object in the context fixes your code. Loop is a component  
> like any other in Tapestry, not having any special treatment.

Thank you very much for the clarification. I'm glad it's that simple :)




--
View this message in context: http://tapestry.1045711.n5.nabble.com/Null-pointer-exception-when-updating-a-component-in-a-loop-tp5719424p5719452.html
Sent from the Tapestry - User 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: Null pointer exception when updating a component in a loop

Posted by Thiago H de Paula Figueiredo <th...@gmail.com>.
On Wed, 23 Jan 2013 06:03:33 -0200, Peter Farkas <pf...@gmail.com>  
wrote:

> Thanks a lot, Thiago! Yes, passing the child as a context parameter  
> fixes it.

;)

> I think Tapestry does try to figure out the component parameters for a
> partial update, but for loops, it can't.

I'm sorry, but you're wrong here. It has absolutely nothing to do with  
loops. Nothing. The issue, as I've said before, was not passing a  
parameter in an later AJAX render. The first render, a full page one,  
passed the parameter correctly. A second one, AJAX, didn't. That's why the  
addition of the object in the context fixes your code. Loop is a component  
like any other in Tapestry, not having any special treatment.

-- 
Thiago H. de Paula Figueiredo

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


Re: Null pointer exception when updating a component in a loop

Posted by Peter Farkas <pf...@gmail.com>.
Thanks a lot, Thiago! Yes, passing the child as a context parameter fixes it.

In ExecutableRowPair.java:



I think Tapestry does try to figure out the component parameters for a
partial update, but for loops, it can't.

In the loop, the same instance of 'ExecutableRowPair' is rendered multiple
times with different parameters. Thus the component injected by

  

is always the same and doesn't hold the information for a particular
iteration.




--
View this message in context: http://tapestry.1045711.n5.nabble.com/Null-pointer-exception-when-updating-a-component-in-a-loop-tp5719424p5719437.html
Sent from the Tapestry - User 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: Null pointer exception when updating a component in a loop

Posted by Thiago H de Paula Figueiredo <th...@gmail.com>.
You said:

> When rendering the AJAX response, Tapestry tries to evaluate an  
> expression on 'child' (*), but 'child' is null.Why does Tapestry need  
> the value of 'child'? How is it supposed to know?

The stack trace says the problem is elsewhere:

[ERROR] batch.ViewBatch Render queue error in  
BeginRender[batch/View:executabletable.executablerowpair.zone]: Failure  
reading parameter 'id' of component  
batch/View:executabletable.executablerowpair.zone: Property 'executable'  
(within property expression 'executable.id', of  
ch.sukha.testmachine.components.ExecutableRowPair@2b44cce) is null. (...)  
/ExecutableRowPair.tml, line 17.

I don't know what exactly is in ExecutableRowPair line 17, but, anyway,  
what happens here  very much probably is that during the AJAX render the  
executable property you're passing to an ExecutableRowPair parameter is  
null.

Here's your code:

<t:loop source="executable.children" value="child">  <!-- * -->
       <t:ExecutableRowPair executable="child" .../>
</t:loop>

You said:

> Why does Tapestry need the value of 'child'?

Quite obviously, you're passing it as a parameter to a component, so the  
component needs the value of 'child'. ;)

> How is it supposed to know?

You're supposed to provide it.

Don't forget that, when a Zone is rendered though AJAX, just its contents  
are rendered again, so the Loop isn't executed and the child property is  
null. The most probable solution to your problem is to pass the child  
parameter value as the context parameter of your toggleEvent link.

-- 
Thiago H. de Paula Figueiredo

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


Re: Null pointer exception when updating a component in a loop

Posted by Peter Farkas <pf...@gmail.com>.
Ok. There are more nested components than necessary, though.

ExecutableRowPair.tml:



ExecutableRowPair.java:



Stack trace (actually the null pointer exception is in ExecutableRowPair):




--
View this message in context: http://tapestry.1045711.n5.nabble.com/Null-pointer-exception-when-updating-a-component-in-a-loop-tp5719424p5719430.html
Sent from the Tapestry - User 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: Null pointer exception when updating a component in a loop

Posted by Thiago H de Paula Figueiredo <th...@gmail.com>.
Full stack trace and ExecutableRowPair code component please.

On Tue, 22 Jan 2013 16:58:05 -0200, Peter Farkas <pf...@gmail.com>  
wrote:

> I'm try to show a list of components with AJAX zones in a table:
>
>
>
> An 'ExecutableRowPair' consists of a header row (that's always visible)  
> and
> a details row, that's loaded through AJAX. The request is triggered by an
> event link in the header row.
>
>
>
> In ExecutablePair.java, I'm injecting the component as follows:
>
>
> When rendering the AJAX response, Tapestry tries to evaluate an  
> expression
> on 'child' (*), but 'child' is null.
>
> Why does Tapestry need the value of 'child'? How is it supposed to know?
>
>
>
>
> --
> View this message in context:  
> http://tapestry.1045711.n5.nabble.com/Null-pointer-exception-when-updating-a-component-in-a-loop-tp5719424.html
> Sent from the Tapestry - User 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
>


-- 
Thiago H. de Paula Figueiredo

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