You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Ivano Luberti <lu...@archicoop.it> on 2014/11/05 10:23:03 UTC

newbie: beaneditForm with drop down list fed by a List

Hi, I'm trying to figure out how to add a PropertyEditBlock to have drop
down lists fed by a List type.
I have found this example:

http://wiki.apache.org/tapestry/Tapestry5HowToCreateAPropertyEditBlock

but I see links to code are not working anymore: can someone tell me if
that is the right approach before I try it out?

BTW: if it is the right approach why not moving that example to official
documentation?
It seems to me that using List for drop down list is quite mandatory to
manage forms in real world applications.

If it is NOT the right approach can someone link me to a proper one?

Thanks in advance for your help


-- 
==================================================
dott. Ivano Mario Luberti
Archimede Informatica societa' cooperativa a r. l.
Sede Operativa
Via Gereschi 36 - 56126- Pisa
tel.: +39-050- 580959
tel/fax: +39-050-9711344
web: www.archicoop.it
==================================================



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


Re: newbie: beaneditForm with drop down list fed by a List

Posted by Thiago H de Paula Figueiredo <th...@gmail.com>.
On Thu, 06 Nov 2014 09:03:38 -0200, Ivano Luberti <lu...@archicoop.it>  
wrote:

> Thanks Thiago, you answer quickly as usually and always providing the
> fishing rod not the fish :-)

:)

> Yes I saw that page, of course but to me, for a newbie it lacks
> indications on how to get together the select model with the bean model.

Actually, you don't associate a SelectModel with BeanModel. You do this in  
your edition block. There, you'll have a Select component. Pass it the  
SelectModel you want.

> In real world scenarios populating a drop down list from an enum is far
> more rare than populating from a Map or a List dynamically generated
> from a data source (DB or web service as in my case).
> So for a newbie to have a BeanEditForm ready to use with this respect
> could be quite important. BeanEditForm in fact is documented in the
> Getting Started guide since is correctly deemed as a Basic funcionality.

Tapestry can figure out the SelectModel for an enum by itself, but, in  
other cases, it doesn't what data it should provide. You are the one who  
does. That's why this isn't built-in in BeanEditor (which is used by  
BeanEditForm). That's why you need to provide your own edition block: so  
you tell Tapestry how to edit the field, including any data needed for  
that. Again, Tapestry is magic, but not psychic.

> Another thing is not mentioned in the BeanEditForm guide is the coercion
> of Map to SelectModel: I guess  this means that if my data provider give
> me Maps I can override the property editor and I'm done.

This should be in Select's documentation, not BeanEditForm's, because  
BeanEditForm doesn't have any notion of SelectModel. As we say here in  
Brazil, one thing is one thing, another thing is another thing. :)

> One more observation on the guide:  BeanModelSource.create is deprecated
> :-) : the guide is outdated.

Just this part is outdated. Good catch.

> However even turning to BeanModelSource.createEditModel doesn't work for
> me because my bean to be created needs the IP address of the client.  I
> will give a try later when I will implement other forms...

What does one thing (BeanModelSource) have with the other (instatiating  
the bean)? Use onPrepare() to set up the object you need to be edited so  
BeanEditForm/BeanEditor doesn't need to instatiate your object. This  
method will be called *before* BeanEditForm/BeanEditor does anything.

public void onPrepare() {
	yourEditedObject = ...;
	// do whatever you need
}

> I fear I will have to use a "normal" Form component.

No, you don't. You said you're a newbie. You just need to learn a bit  
more. ;)

-- 
Thiago H. de Paula Figueiredo
Tapestry, Java and Hibernate consultant and developer
http://machina.com.br

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


Re: newbie: beaneditForm with drop down list fed by a List

Posted by Ivano Luberti <lu...@archicoop.it>.
Thanks Thiago, you answer quickly as usually and always providing the
fishing rod not the fish :-)

Il 05/11/2014 18:21, Thiago H de Paula Figueiredo ha scritto:
> On Wed, 05 Nov 2014 07:23:03 -0200, Ivano Luberti
> <lu...@archicoop.it> wrote:
>
>> Hi, I'm trying to figure out how to add a PropertyEditBlock to have drop
>> down lists fed by a List type.
>
> What do you mean by "a List type"? java.util.List<SomeClass>?
>

Yes I hoped it was clear from the subect

>> I have found this example:
>>
>> http://wiki.apache.org/tapestry/Tapestry5HowToCreateAPropertyEditBlock
>>
>> but I see links to code are not working anymore: can someone tell me if
>> that is the right approach before I try it out?
>
> Thank heavens the link to GenericSelectModel is broken, as it was a
> really bad idea.
>
> I prefer http://tapestry.apache.org/beaneditform-guide.html, which is
> a better description than the page you mentioned above.
>

Yes I saw that page, of course but to me, for a newbie it lacks
indications on how to get together the select model with the bean model.
In real world scenarios populating a drop down list from an enum is far
more rare than populating from a Map or a List dynamically generated
from a data source (DB or web service as in my case).

So for a newbie to have a BeanEditForm ready to use with this respect
could be quite important. BeanEditForm in fact is documented in the
Getting Started guide since is correctly deemed as a Basic funcionality.

Another thing is not mentioned in the BeanEditForm guide is the coercion
of Map to SelectModel: I guess  this means that if my data provider give
me Maps I can override the property editor and I'm done.

One more observation on the guide:  BeanModelSource.create is deprecated
:-) : the guide is outdated.

However even turning to BeanModelSource.createEditModel doesn't work for
me because my bean to be created needs the IP address of the client.  I
will give a try later when I will implement other forms...

I fear I will have to use a "normal" Form component.



> http://wiki.apache.org/tapestry/Tapestry5HowToCreateAPropertyEditBlock
> has something I don't like at all: creating a class (DropDownList)
> just for being used in BeanModel-based components (BeanEditForm,
> BeanEditor, Grid, BeanDisplay), not being the type of the field in
> your domain or entity class, which would be String, int, an enum, some
> other custom class, etc. Instead, I prefer to keep the field in its
> right type, which is the type of the options you want to provide.
>
> The implementation varies a bit depending on what the type of the
> selection is. If it's an enum or some custom class, you can follow the
> http://wiki.apache.org/tapestry/Tapestry5HowToCreateAPropertyEditBlock
> example replacing DropDownList by your class and writing an
> appropriate ValueEncoder for it. You don't need to subclass
> AbstractModel yourself: just use the SelectModelFactory service
> methods instead.


I see your point but I'm not sure I'm totally with you on this.
Of course you are more experienced than me in what the reasons are
beyond tpaestry choices, so I feel quite uncomfortable arguing your
arguments but I try it anyway. I hope you will keep on being patient
answering even if I totally miss the point.

In real world application we will get object from the DB to populate the
drop down list and when an item is selected we will have always an id in
our page class to make it aware what item has been selected .
So there will be always the need to extract from the object a mnemonic
identifier to be showed in the selection for uman reading and an
identifier to indicate the selection to the page.
I believe this is why you need a ValueEncoder, right?



>
>
> If it's something like, for example, an int field with values from 0
> to 10, the only difference would be creating an annotation (@Rating,
> for example), then implementing a DataTypeAnalyzer which retuns "rate"
> when the field has @Rating and contribute your newly-written
> RatingDataTypeAnalyzer to the DataTypeAnalyzer service. The rest stays
> the same.
>
>> It seems to me that using List for drop down list is quite mandatory to
>> manage forms in real world applications.
>
> Yeah, but the way you describe this is too vague to have a single good
> implementation for all cases.
>
>> BTW: if it is the right approach why not moving that example to official
>> documentation?
>
> Because the right approach for adding BeanModel edition and viewing
> blocks is already at
> http://tapestry.apache.org/beaneditform-guide.html, Adding New
> Property Editors section. ;)
>

-- 
==================================================
dott. Ivano Mario Luberti
Archimede Informatica societa' cooperativa a r. l.
Sede Operativa
Via Gereschi 36 - 56126- Pisa
tel.: +39-050- 580959
tel/fax: +39-050-9711344
web: www.archicoop.it
==================================================



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


Re: newbie: beaneditForm with drop down list fed by a List

Posted by Thiago H de Paula Figueiredo <th...@gmail.com>.
On Wed, 05 Nov 2014 07:23:03 -0200, Ivano Luberti <lu...@archicoop.it>  
wrote:

> Hi, I'm trying to figure out how to add a PropertyEditBlock to have drop
> down lists fed by a List type.

What do you mean by "a List type"? java.util.List<SomeClass>?

> I have found this example:
>
> http://wiki.apache.org/tapestry/Tapestry5HowToCreateAPropertyEditBlock
>
> but I see links to code are not working anymore: can someone tell me if
> that is the right approach before I try it out?

Thank heavens the link to GenericSelectModel is broken, as it was a really  
bad idea.

I prefer http://tapestry.apache.org/beaneditform-guide.html, which is a  
better description than the page you mentioned above.

http://wiki.apache.org/tapestry/Tapestry5HowToCreateAPropertyEditBlock has  
something I don't like at all: creating a class (DropDownList) just for  
being used in BeanModel-based components (BeanEditForm, BeanEditor, Grid,  
BeanDisplay), not being the type of the field in your domain or entity  
class, which would be String, int, an enum, some other custom class, etc.  
Instead, I prefer to keep the field in its right type, which is the type  
of the options you want to provide.

The implementation varies a bit depending on what the type of the  
selection is. If it's an enum or some custom class, you can follow the  
http://wiki.apache.org/tapestry/Tapestry5HowToCreateAPropertyEditBlock  
example replacing DropDownList by your class and writing an appropriate  
ValueEncoder for it. You don't need to subclass AbstractModel yourself:  
just use the SelectModelFactory service methods instead.

If it's something like, for example, an int field with values from 0 to  
10, the only difference would be creating an annotation (@Rating, for  
example), then implementing a DataTypeAnalyzer which retuns "rate" when  
the field has @Rating and contribute your newly-written  
RatingDataTypeAnalyzer to the DataTypeAnalyzer service. The rest stays the  
same.

> It seems to me that using List for drop down list is quite mandatory to
> manage forms in real world applications.

Yeah, but the way you describe this is too vague to have a single good  
implementation for all cases.

> BTW: if it is the right approach why not moving that example to official
> documentation?

Because the right approach for adding BeanModel edition and viewing blocks  
is already at http://tapestry.apache.org/beaneditform-guide.html, Adding  
New Property Editors section. ;)

-- 
Thiago H. de Paula Figueiredo
Tapestry, Java and Hibernate consultant and developer
http://machina.com.br

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