I agree... It sounded like a normal use case to me and I was fully expecting
it to "just work." But it didn't. I'm not trying to complicate things...
I'm looking for an uncomplicated solution... but I have not found one yet.
All of the code necessary to run this example can be found in my original
email except for the backing-bean for the Test page and some boilerplate
code (XML headers, Java getters/setters, and imports). Below is the Java
code for the Test page without the onPassivate/onActivate methods. This
isn't pseudo-code... all of this is the real code that I created for myself
to isolate the issue that I'm facing. I tried to boil the use case down to
its simplest form to make sure nothing else was happening behind the scenes
to break it.
Here's the backing-bean for the Test.tml page:
public class Test
{
@Property private Foo fooLoopVar;
// this static list takes the place of an injected JPA DAO
private static List<Foo> list = new ArrayList<Foo>();
static {
list.add(new Foo("foo1", new Donkey("donkey1","This is Donkey 1")));
list.add(new Foo("foo2", new Donkey("donkey2","This is Donkey 2")));
list.add(new Foo("foo3", new Donkey("donkey3","This is Donkey 3")));
}
public Foo getFirstFoo() { return getFooList().get(0); }
public Foo getSecondFoo() { return getFooList().get(1); }
public Foo getThirdFoo() { return getFooList().get(2); }
public List<Foo> getFooList() { return list; }
}
If you take this code combined with the code in the original email, you have
all you need to demonstrate the null pointer exception. Add the
onPassivate/onActivate methods to make the NPE go away... but remember that
this solution doesn't work if "Test" is used as a component instead of a
page.
To summarize the code:
Two simple Java Beans : Foo and Donkey; Donkey contains string name and
string descr; Foo contains string name and a reference to a Donkey.
One component that takes a Donkey as a parameter, displays the Donkey, and
contains an embedded editing form that can be turned on and off using
eventlinks internal to the component.
One page, containing a list of Foo objects, each containing a Donkey object.
It uses the custom component to render (with editing capability) each
Donkey in the list.
-Nathan
On Mon, Feb 15, 2010 at 3:01 AM, Inge Solvoll <[email protected]>wrote:
> I also think that you're over-complicating this. To me this sounds like a
> very normal use case, looping over items and creating a form for each one.
> It should "just work". And it shouldn't be too many lines of complicated
> code either, so the code listed here confuses me a bit.
>
> Someone should post the rather simple code needed to do this. I don't have
> the time right now :)
>
> On Mon, Feb 15, 2010 at 12:06 AM, Thiago H. de Paula Figueiredo <
> [email protected]> wrote:
>
> > On Sun, 14 Feb 2010 17:33:43 -0200, Nathan Kopp <
> [email protected]>
> > wrote:
> >
> > Even with your suggested change, this would still generate a null
> pointer
> >> exception (NPE) in the same place, since the problem lies with
> >> "fooLoopVar" being null when the eventlink is click is processed by
> >> Tapestry.
> >>
> >
> > You simply can't use it in the EventLink method handler.
> >
> >
> > The NPE
> >> happens before I even get to rendering the description text field.
> >>
> >
> > Never forget that T5 uses redirect after post, so the event handling
> > request is not the same as the render request.
> >
> >
> > --
> > Thiago H. de Paula Figueiredo
> > Independent Java, Apache Tapestry 5 and Hibernate consultant, developer,
> > and instructor
> > Owner, software architect and developer, Ars Machina Tecnologia da
> > Informação Ltda.
> > http://www.arsmachina.com.br
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [email protected]
> > For additional commands, e-mail: [email protected]
> >
> >
>