You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Stephanos Piperoglou <st...@db.com> on 2006/10/30 13:02:52 UTC

Using java 1.5 enums as property selection models

Apparently there was an EnumPropertySelectionModel in Tapestry 3 that was 
dropped in version 4 due to namespace conflicts. Is there any contributed 
or official replacement or should I just roll my own (and possibly submit 
it)? To clarify, I need an implementation of IPropertySelectionModel that 
uses a Java 1.5 enum as a data source and a resource bundle for string 
labels.

---

This e-mail may contain confidential and/or privileged information. If you 
are not the intended recipient (or have received this e-mail in error) 
please notify the sender immediately and destroy this e-mail. Any 
unauthorized copying, disclosure or distribution of the material in this 
e-mail is strictly forbidden.

Re: Using java 1.5 enums as property selection models

Posted by Stephanos Piperoglou <st...@db.com>.
"Martin Strand" <ma...@entcap.se> wrote on 30/10/2006 17:33:32:

> On Mon, 30 Oct 2006 18:24:27 +0100, Stephanos Piperoglou <stephanos.
> piperoglou@db.com> wrote:
> 
> > I was kind of expecting to be able to use a generic type (T
> > above) as an instance of java.lang.Class. Unsurprisingly, I can't.
> > Surprisingly, I can't find a way to work around it!
> 
> Afaik, the type info isn't available at runtime for generic classes 
> so it can't be done.

You're absolutely right; I was forgetting that generics in 1.5 are nothing 
but glorified syntactic sugar; the compiler does the type checking and 
then throws it all away. You need the class in the constructor for runtime 
availability.

On the other hand, I'm still miffed that I have to use 
java.lang.Class.getEnumConstants() (which I had to dig through the API to 
find, and seems a bit inelegant even though the generic definition for the 
class guarantees type safety) when all the tutorials mention the 
<EnumType>.values() static method, which is defined for every subtype of 
java.lang.Enum but not Enum itself! Of course it's because you can't have 
abstract static methods in Java anyway... it just looks a bit ugly

Still, why am I complaining? It's a hell of a lot better than public 
static final int CITY_NYC = 1... :)

Thanks for the timely response to the initial query and humoring my aside 
guys!

---

This e-mail may contain confidential and/or privileged information. If you 
are not the intended recipient (or have received this e-mail in error) 
please notify the sender immediately and destroy this e-mail. Any 
unauthorized copying, disclosure or distribution of the material in this 
e-mail is strictly forbidden.

Re: Using java 1.5 enums as property selection models

Posted by Martin Strand <ma...@entcap.se>.
Afaik, the type info isn't available at runtime for generic classes so it can't be done.

On Mon, 30 Oct 2006 18:24:27 +0100, Stephanos Piperoglou <st...@db.com> wrote:

> andyhot <an...@di.uoa.gr> wrote on 30/10/2006 16:30:08:
>
>> However, Daniel has recently added this in the BeanForm.sourceforge.net
>> project.
>> See
>> http://beanform.sourceforge.net/beanform-
>> core/xref/net/sf/beanform/util/EnumPropertySelectionModel.html
>>
>> or get the beanform jar and add it in your classpath
>
> Efxaristo :)
>
> Interestingly I had arrived at almost the exact same code by the time you
> answered. This is the first time I've really used Java 1.5 in a production
> environment and I was still struggling to find a way to shorten:
>
> public class EnumPropertySelectionModel<T extends Enum<T>> implements
> IPropertySelectionModel {
>         public EnumPropertySelectionModel(Class<T> type, boolean
> includeEmptyOption, Messages messages)
>
> ... so that the constructor doesn't need the class passed explicitly.
> Surely the wonders of generics should allow such repetition to be made
> redundant? I was kind of expecting to be able to use a generic type (T
> above) as an instance of java.lang.Class. Unsurprisingly, I can't.
> Surprisingly, I can't find a way to work around it! I just spent half a
> day worrying about this inelegant solution so seeing that somebody else
> seems to have used it did a lot to help me move on to actually writing
> some code... but anybody have any ideas?
>
> Maybe this is a bit off-topic, so please tell me to fly off to
> comp.lang.java if you must :)

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


Re: Using java 1.5 enums as property selection models

Posted by Stephanos Piperoglou <st...@db.com>.
andyhot <an...@di.uoa.gr> wrote on 30/10/2006 16:30:08:

> However, Daniel has recently added this in the BeanForm.sourceforge.net
> project.
> See
> http://beanform.sourceforge.net/beanform-
> core/xref/net/sf/beanform/util/EnumPropertySelectionModel.html
> 
> or get the beanform jar and add it in your classpath

Efxaristo :)

Interestingly I had arrived at almost the exact same code by the time you 
answered. This is the first time I've really used Java 1.5 in a production 
environment and I was still struggling to find a way to shorten:

public class EnumPropertySelectionModel<T extends Enum<T>> implements 
IPropertySelectionModel {
        public EnumPropertySelectionModel(Class<T> type, boolean 
includeEmptyOption, Messages messages)

... so that the constructor doesn't need the class passed explicitly. 
Surely the wonders of generics should allow such repetition to be made 
redundant? I was kind of expecting to be able to use a generic type (T 
above) as an instance of java.lang.Class. Unsurprisingly, I can't. 
Surprisingly, I can't find a way to work around it! I just spent half a 
day worrying about this inelegant solution so seeing that somebody else 
seems to have used it did a lot to help me move on to actually writing 
some code... but anybody have any ideas?

Maybe this is a bit off-topic, so please tell me to fly off to 
comp.lang.java if you must :)

---

This e-mail may contain confidential and/or privileged information. If you 
are not the intended recipient (or have received this e-mail in error) 
please notify the sender immediately and destroy this e-mail. Any 
unauthorized copying, disclosure or distribution of the material in this 
e-mail is strictly forbidden.

Re: Using java 1.5 enums as property selection models

Posted by andyhot <an...@di.uoa.gr>.
The v.3 implementation is at
http://svn.apache.org/viewvc/tapestry/tapestry4/branches/branch-3-0/framework/src/org/apache/tapestry/form/EnumPropertySelectionModel.java?view=markup

However, Daniel has recently added this in the BeanForm.sourceforge.net
project.
See
http://beanform.sourceforge.net/beanform-core/xref/net/sf/beanform/util/EnumPropertySelectionModel.html

or get the beanform jar and add it in your classpath

Stephanos Piperoglou wrote:
> Apparently there was an EnumPropertySelectionModel in Tapestry 3 that was 
> dropped in version 4 due to namespace conflicts. Is there any contributed 
> or official replacement or should I just roll my own (and possibly submit 
> it)? To clarify, I need an implementation of IPropertySelectionModel that 
> uses a Java 1.5 enum as a data source and a resource bundle for string 
> labels.
>
> ---
>
> This e-mail may contain confidential and/or privileged information. If you 
> are not the intended recipient (or have received this e-mail in error) 
> please notify the sender immediately and destroy this e-mail. Any 
> unauthorized copying, disclosure or distribution of the material in this 
> e-mail is strictly forbidden.
>   


-- 
Andreas Andreou - andyhot@apache.org - http://andyhot.di.uoa.gr
Tapestry / Tacos developer
Open Source / J2EE Consulting 


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