Retrieving the Class of an enum backing a Grid column

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

Retrieving the Class of an enum backing a Grid column

Davide Vecchi
Hi everybody,

I'm writing a custom component to be used by the Grid component, such that - in a very few words -  when the user clicks on an icon placed in the header of a column whose datatype is an Enumeration, I show a dropdown containing all the existing members of that enumeration.

Tapestry definitely has great support for this kind of things, see f.ex. the Enum example of the doc for the Select component<http://tapestry.apache.org/current/apidocs/org/apache/tapestry5/corelib/components/Select.html> . However in this case I cannot use that approach because I'm not creating a page but a component that needs to work with specific enums that become known only at runtime.

The part where I'm stuck is that I don't know how to retrieve the java.lang.Class of the enum that is the datatype of my column. Once I have the Class of the enum I can call Class.getEnumConstants(), obtaining a List of the members of that particular enum, and pass that list to SelectModelFactory.create(List<?>, String) to create a SelectModel that I can reference in the t:model attribute of my <t:select> tag in the template.

So, is it possible to retrieve the Class of the enum that is the datatype of a Grid column ?
Reply | Threaded
Open this post in threaded view
|

Re: Retrieving the Class of an enum backing a Grid column

Chris Poulsen
Maybe you can find it in the PropertyModel for the column? (
http://tapestry.apache.org/5.4/apidocs/org/apache/tapestry5/beaneditor/PropertyModel.html#getPropertyType%28%29
)

--
Chris

On Wed, Dec 9, 2015 at 5:10 PM, Davide Vecchi <[hidden email]> wrote:

> Hi everybody,
>
> I'm writing a custom component to be used by the Grid component, such that
> - in a very few words -  when the user clicks on an icon placed in the
> header of a column whose datatype is an Enumeration, I show a dropdown
> containing all the existing members of that enumeration.
>
> Tapestry definitely has great support for this kind of things, see f.ex.
> the Enum example of the doc for the Select component<
> http://tapestry.apache.org/current/apidocs/org/apache/tapestry5/corelib/components/Select.html>
> . However in this case I cannot use that approach because I'm not creating
> a page but a component that needs to work with specific enums that become
> known only at runtime.
>
> The part where I'm stuck is that I don't know how to retrieve the
> java.lang.Class of the enum that is the datatype of my column. Once I have
> the Class of the enum I can call Class.getEnumConstants(), obtaining a List
> of the members of that particular enum, and pass that list to
> SelectModelFactory.create(List<?>, String) to create a SelectModel that I
> can reference in the t:model attribute of my <t:select> tag in the template.
>
> So, is it possible to retrieve the Class of the enum that is the datatype
> of a Grid column ?
>
Reply | Threaded
Open this post in threaded view
|

RE: Retrieving the Class of an enum backing a Grid column

Davide Vecchi
Great, it’s exactly there, thanks a lot.



So here is the code that works for me:


BeanModel dataModel = getDataModel();    // : The data model of the grid.


       PropertyModel pm = dataModel.get(columnName);



Class columnClass = pm.getPropertyType();



Cheers



Davide



-----Original Message-----
From: Chris Poulsen [mailto:[hidden email]]
Sent: Wednesday, December 9, 2015 19:43
To: Tapestry users <[hidden email]>
Subject: Re: Retrieving the Class of an enum backing a Grid column



Maybe you can find it in the PropertyModel for the column? (

http://tapestry.apache.org/5.4/apidocs/org/apache/tapestry5/beaneditor/PropertyModel.html#getPropertyType%28%29

)



--

Chris