Tapestry SelectModel

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Tapestry SelectModel

Christopher
Hi team,

Just a quick question: When using Tapestry's SelectModel to create a drop
down list of String options, is it possible to enforce this at the 'model'
tier through the use of an annotation?

With Java enumerations this is possible:

    @Enumerated(EnumType.STRING)
    private String country;

The Tapestry 'Hotel' demo app introduces an alternative to plain
enumerations: (Abstract)SelectModel.  But I notice that it is only 'wired
up' at the 'view' tier:

    <select t:type="select" t:id="roomPreference" t:value="booking.beds"
t:model="bedType">
    </select>

Without the SelectModel being 'wired' to the model tier (an entity), it
would mean BeanEditForm would allow the user to type directly into a
String field.  Ideally, I'd like this also to be a drop down selection.

Thanks for any suggestions,

Chris.


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

"A designer knows he has achieved perfection not when there is nothing left to add, but when there is nothing left to take away." - Antoine de Saint-Exupéry.
Reply | Threaded
Open this post in threaded view
|

Re: Tapestry SelectModel

Thiago H de Paula Figueiredo
Hello!

IMHO, if you don't want arbitrary strings in a field, you should create an
enum for that (in this case, Country) and use it as the type of your field
instead of String. Tapestry should automatically use a <select> for editing
that.

But, even leaving your code the way it is, and I strongly recommend you
don't, you can contribute a DataTypeAnalyzer implementation to the
DataTypeAnalyzeer so you tell Tapestry which Tapestry type (which is just a
name in a String) your property should have. After that, you'll contribute
an edition block to
The other step would be contributing an edition block to BeanBlockSource.
Then, when using BeanEditor or BeanEditForm, Tapestry will use that block
to render the HTML form field for your field/property.

Or, inside your BeanEditForm or BeanEditor, just use a <p:country> block to
manually create the template that will edit your field.

On Tue, Jan 23, 2018 at 10:19 PM, Christopher Dodunski <
[hidden email]> wrote:

> Hi team,
>
> Just a quick question: When using Tapestry's SelectModel to create a drop
> down list of String options, is it possible to enforce this at the 'model'
> tier through the use of an annotation?
>
> With Java enumerations this is possible:
>
>     @Enumerated(EnumType.STRING)
>     private String country;
>
> The Tapestry 'Hotel' demo app introduces an alternative to plain
> enumerations: (Abstract)SelectModel.  But I notice that it is only 'wired
> up' at the 'view' tier:
>
>     <select t:type="select" t:id="roomPreference" t:value="booking.beds"
> t:model="bedType">
>     </select>
>
> Without the SelectModel being 'wired' to the model tier (an entity), it
> would mean BeanEditForm would allow the user to type directly into a
> String field.  Ideally, I'd like this also to be a drop down selection.
>
> Thanks for any suggestions,
>
> Chris.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>


--
Thiago