Wow... You were absolutely correct that I was making this more complicated
than it needed to be.  It turns out that when I tested the version with the
eventlink context, I accidentally left a line of code in the event method
that caused Tapestry to do a parameter binding to the loop variable.  It
turns out that Tapestry is actually smart enough to not attempt the
parameter unless it is requested... which means that it stopped generating
the exception when I removed the offending line of code.  Doh!  I wish I
would have seen that a few days ago!

With that line of code removed, your suggested solution works perfectly, as
expected... without the need for the code I wrote below.

Thanks much for your help and patience!!!

-Nathan


On Tue, Feb 16, 2010 at 10:01 AM, Nathan Kopp <nathan0...@nathankopp.com>wrote:

> Thanks for the suggestion.  This looks like a great idea, but it didn't
> work for me exactly as-is.  I still get an NPE when Tapestry is trying to
> bind component parameters in the level just above ViewDonkeyInlineEdit.
>
> The point of code with the problem is where I'm passing
>    <t:viewDonkeyInlineEdit donkey="fooLoopVar.donkey"/>
> in Test.tml.  When Tapestry tries to process this parameter binding when
> attempting to fire my startEditDonkey event, it sees that fooLoopVar is
> null, so I get the NPE.  I need to get fooLoopVar to be NOT NULL when T5 is
> processing the parameter binding.
>
> This did get me to think of another possible solution, though.  I could use
> your suggestion of a context parameter, but also make a change to Test.java:
>   <t:viewDonkeyInlineEdit donkey="fooLoopVar.donkey"/>
> becomes
>   <t:viewDonkeyInlineEdit donkey="fooLoopVarDotDonkey"/>
>
> Then add this to Test.java:
>   public getFooLoopVarDotDonkey() { if(fooLoopVar!=null) return
> fooLoopVar.getDonkey() else return null; }
>
> This will allow Tapestry to process the parameter binding without hitting a
> null pointer exception and thus allow it to actually trigger my event code
> so that I can actually retrieve the donkey using the ID passed in the
> EventLink's action context.
>
> I'll test this out and let you know how it works.
>
> -Nathan
>
>
> On Mon, Feb 15, 2010 at 3:32 PM, Thiago H. de Paula Figueiredo <
> thi...@arsmachina.com.br> wrote:
>
>> Try this:
>>
>> <t:container xmlns:t="
>> http://tapestry.apache.org/schema/tapestry_5_1_0.xsd";
>> xmlns:p="tapestry:parameter">
>>    Donkey's name: ${donkey.name}<br/>
>>    <t:if test="editing">
>>        <t:form context="donkey.id">
>>            <t:errors/>
>>            Description: <t:textfield value="editDonkey.descr" size="50"/>
>>            <t:submit value="Save" event="saveEditDonkey"/> <t:eventlink
>> event="cancelEditDonkey">Cancel</t:eventlink><br/>
>>        </t:form>
>>        <p:else>
>>        Description: ${donkey.descr} <t:eventlink
>> event="startEditDonkey" context="donkey.id">Edit</t:eventlink><br/>
>>        </p:else>
>>    </t:if>
>> </t:container>
>>
>> The only differences here are the use of the context parameter to Form and
>> EventLink. You can replace id by any field or info that is unique for all
>> donkeys.
>>
>> public class ViewDonkeyInlineEdit
>> {
>>    @Property @Parameter private Donkey donkey;
>>    @Persist @Property private Donkey editDonkey;
>>    public boolean isEditing() {
>>        return (editDonkey!=null &&
>> editDonkey.getName().equals(donkey.getName()));
>>    }
>>    public void onStartEditDonkey(Integer id) {
>>        // get donkey by id and do any processing needed.
>>    }
>>    public void onSaveEditDonkey(Integer id) {
>>        // get donkey by id
>>        donkey.setDescr(editDonkey.getDescr());
>>        editDonkey = null;
>>    }
>>    public void onCancelEditDonkey()  {
>>        editDonkey = null;
>>    }
>> }
>>
>> By the way, I guess you don't need to @Persist the editDonkey field.
>>
>> --
>> 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: users-unsubscr...@tapestry.apache.org
>> For additional commands, e-mail: users-h...@tapestry.apache.org
>>
>>
>

Reply via email to