You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Brendan McNichols <bm...@uievolution.com> on 2008/08/10 03:52:58 UTC

[T5] Custom component parameter value within a loop

Hi All,

 

I have been struggling with the following problem for quite a while.  I
have a custom component for which I have defined a parameter with a
binding type of property.  I have the component within a form that is
within a loop on my page.  The parameter of my component is bound to the
value of the "value" parameter of the loop.  The value of my parameter
ends up always being null, when the value is requested in my component,
a PropBinding calls the getter on my page class.  Everything is good so
far as rendering goes. The problem is that when I submit the form, I
want to access my value, so the PropBinding again calls the getter on my
page class.  At this point, I get a NullPointerException since the value
of the property in my page class is now null since the loop is no longer
being rendered.  So my question is this:  Is there a way to retaint the
value of the property in the component instead of it always being null
and having the PropBinding call the getter on the page?  (BTW, I am
using version 5.0.13)

 

Here's a snippet of the component java class:

 

public class MenuEntry {

     // This setter never gets called.

    public void setModel(Model model) {

        this.model = model;

    }

 

     // This works fine because it is only called when rendering.

    public String getModelName() {

        return model.getName();

    }

 

     // NullPointerException gets thrown because the PropBinding calls
the getter

     // on the page class and the property is null since the loop is no
longer being renderes.

    public void setModelName(String name) {

        model.setName(name);

    }

 

    // a bunch of non-relevant methods not shown...

 

    @Parameter(required = true, principal = true)

    private Model model;

 

    // bunch of non-relevant fields not shown...

}

 

And a snippet of the page class:

 

public class Build {

    // bunch of non-relevant methods not shown...

 

    public Model getMenuModel() {

        return menuModel;

    }

 

    public void setMenuModel(Model model) {

        menuModel = model;

    }

 

    // bunch of non-relevant fields not shown...

 

    private Model menuModel;

}

 

And finally, a snippet of the page tml:

 

<!-- bunch of non-relevant html not shown -->

<t:loop t:source="menuModels" t:value="menuModel">


    <t:form t:id="menuEntryDetails" context="menuModel">

        <t:menuentry t:id="menuEntryComponent" model="menuModel"/>


        <div><input type="submit" value="Save"/></div>

    </t:form>

</t:loop>

<!-- bunch more non-relevant html not shown -->

 

 

Thanks very much in advance for any help!

 

Brendan McNichols


Re: [T5] Custom component parameter value within a loop

Posted by Avi Cherry <av...@cherrydev.com>.
Have you had any luck with this?

I'm trying to figure out the same thing...

I have a complicated form that uses several nested components to  
implement it.  The structure of the form is straightforward, though.

Everything renders just fine, but when the form is being submitted and  
the form fields are updating values, only the property bound to a  
loop's 'value' binding is non-null.  Notably, all of the components'  
parameters are null!  Unfortunately, I can't recreate the entire state  
of the component from just that single object.

I'm rather stuck at this point.  I've tried dissecting the  
BeanEditForm and enclosed components to try to figure out how it deals  
with something similar, but I don't seem to be able to find where the  
trick is.

Howard?  Anybody?

:-)

On Aug 9, 2008, at 6:52 PM, Brendan McNichols wrote:

> Hi All,
>
>
>
> I have been struggling with the following problem for quite a  
> while.  I
> have a custom component for which I have defined a parameter with a
> binding type of property.  I have the component within a form that is
> within a loop on my page.  The parameter of my component is bound to  
> the
> value of the "value" parameter of the loop.  The value of my parameter
> ends up always being null, when the value is requested in my  
> component,
> a PropBinding calls the getter on my page class.  Everything is good  
> so
> far as rendering goes. The problem is that when I submit the form, I
> want to access my value, so the PropBinding again calls the getter  
> on my
> page class.  At this point, I get a NullPointerException since the  
> value
> of the property in my page class is now null since the loop is no  
> longer
> being rendered.  So my question is this:  Is there a way to retaint  
> the
> value of the property in the component instead of it always being null
> and having the PropBinding call the getter on the page?  (BTW, I am
> using version 5.0.13)
>
>
>
> Here's a snippet of the component java class:
>
>
>
> public class MenuEntry {
>
>     // This setter never gets called.
>
>    public void setModel(Model model) {
>
>        this.model = model;
>
>    }
>
>
>
>     // This works fine because it is only called when rendering.
>
>    public String getModelName() {
>
>        return model.getName();
>
>    }
>
>
>
>     // NullPointerException gets thrown because the PropBinding calls
> the getter
>
>     // on the page class and the property is null since the loop is no
> longer being renderes.
>
>    public void setModelName(String name) {
>
>        model.setName(name);
>
>    }
>
>
>
>    // a bunch of non-relevant methods not shown...
>
>
>
>    @Parameter(required = true, principal = true)
>
>    private Model model;
>
>
>
>    // bunch of non-relevant fields not shown...
>
> }
>
>
>
> And a snippet of the page class:
>
>
>
> public class Build {
>
>    // bunch of non-relevant methods not shown...
>
>
>
>    public Model getMenuModel() {
>
>        return menuModel;
>
>    }
>
>
>
>    public void setMenuModel(Model model) {
>
>        menuModel = model;
>
>    }
>
>
>
>    // bunch of non-relevant fields not shown...
>
>
>
>    private Model menuModel;
>
> }
>
>
>
> And finally, a snippet of the page tml:
>
>
>
> <!-- bunch of non-relevant html not shown -->
>
> <t:loop t:source="menuModels" t:value="menuModel">
>
>
>    <t:form t:id="menuEntryDetails" context="menuModel">
>
>        <t:menuentry t:id="menuEntryComponent" model="menuModel"/>
>
>
>        <div><input type="submit" value="Save"/></div>
>
>    </t:form>
>
> </t:loop>
>
> <!-- bunch more non-relevant html not shown -->
>
>
>
>
>
> Thanks very much in advance for any help!
>
>
>
> Brendan McNichols
>


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