You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Nathan Quirynen <na...@pensionarchitects.be> on 2013/04/09 13:53:22 UTC

Reuse component containing form, but with extra fields

Hi,

I have a component which I pass a Person object as parameter. This 
component contains a form to edit the person's data.

*page.tml*

<t:personeditor t:person="person" />

*personeditor.tml*

<t:form>
     <t:textfield t:value="person.name" />
     ...
</t:form>

Now what should I do if I have the following:
I have a class Employee containing a Person object and 1 extra field.

public class Employee {
     private Person person;
     private String extraField;
}

I'd like to reuse the component to edit the person data, but I also need 
to be able to edit that extra field, which should be located in one and 
the same form. The problem here is that the form is defined in the 
person editor component.
So what's a good way to do this and still reuse my personeditor in some 
way, or at least avoid duplicate code.

-- 

Een klare kijk op aanvullende pensioenen

*Nathan Quirynen*
03 340 04 60 | 0494 28 45 15
nathan@pensionarchitects.be <ma...@pensionarchitects.be>

Follow us on Web <http://www.pensionarchitects.be> | Twitter 
<http://www.twitter.com/pen_arch> | LinkedIn 
<http://www.linkedin.com/company/pension-architects> | RSS 
<http://feeds.feedburner.com/pensionarchitects> | YouTube 
<http://www.youtube.com/pensionarchitects>


Re: Reuse component containing form, but with extra fields

Posted by Ivan Khalopik <ik...@gmail.com>.
1. You can move form up, so that you personeditor component will contain
only form controls:

*page.tml*

<t:form>
  <t:personeditor t:person="person" />
</t:form>

*personeditor.tml*

    <t:textfield t:value="person.name" />
    ...

*page2.tml*

<t:form>
  <t:personeditor t:person="person" />
  <t:textfield t:value="extraField" />
</t:form>

All validation logic can be deffered using FormSupport.



2. Or you can use block parameters.

*page.tml*

<t:personeditor t:person="person" />

*personeditor.tml*

<t:form>
    <t:textfield t:value="person.name" />
    ...
    <t:delegate to="extra"/>
</t:form>

*PersonEditor.java*

@Property
@Parameter
private Block extra;

*page2.tml*

<t:personeditor t:person="person">
  <p:extra>
    <t:textfield t:value="extraField" />
  </p:extra>
</t:personeditor>



On Tue, Apr 9, 2013 at 2:53 PM, Nathan Quirynen <nathan@pensionarchitects.be
> wrote:

>  Hi,
>
> I have a component which I pass a Person object as parameter. This
> component contains a form to edit the person's data.
>
> *page.tml*
>
> <t:personeditor t:person="person" />
>
> *personeditor.tml*
>
> <t:form>
>     <t:textfield t:value="person.name" />
>     ...
> </t:form>
>
> Now what should I do if I have the following:
> I have a class Employee containing a Person object and 1 extra field.
>
> public class Employee {
>     private Person person;
>     private String extraField;
> }
>
> I'd like to reuse the component to edit the person data, but I also need
> to be able to edit that extra field, which should be located in one and the
> same form. The problem here is that the form is defined in the person
> editor component.
> So what's a good way to do this and still reuse my personeditor in some
> way, or at least avoid duplicate code.
>
> --
>
> Een klare kijk op aanvullende pensioenen
>
> *Nathan Quirynen*
> 03 340 04 60 | 0494 28 45 15
> nathan@pensionarchitects.be
>
> Follow us on Web <http://www.pensionarchitects.be> | Twitter<http://www.twitter.com/pen_arch>|
> LinkedIn <http://www.linkedin.com/company/pension-architects> | RSS<http://feeds.feedburner.com/pensionarchitects>|
> YouTube <http://www.youtube.com/pensionarchitects>
>
>


-- 
BR
Ivan