Fun with Enums - suggestion wanted for edit subset of enum types (netmask)

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

Fun with Enums - suggestion wanted for edit subset of enum types (netmask)

chris@opencsta.org
Hi Tapestry Users!

I am positive we've all had fun with enums (and netmasks) at some point!!!
I got through the afternoon accomplishing my page rendering *[1]


I now have my entity class with an enum saved.
It is a netmask for an ip address.
So if an IP address belongs in a /24 subnet, I'd like to be able to assign
it to a /32 subnet.

I would like the t:select component to only display this option (or perhaps
a /31 & /32), but not the whole range of available netmasks in my app (/24
/25 /26...../32)


How would I go about doing this (displaying certain enum values from the
type)?

Cheers for any awesome suggestions, ditto for reading!
Chris



[1]
The t:select component reads the message catalog, however rendering in a
table (not a grid) seemed to ignore it.  I progressed with it by calling a
helper method from the template with something like
${convertEnum(passedEnum)}

page class has this method

public String convertEnum(EnumType n){
    switch(n){
       case EnumType.ONE: return "Hooray One";
       case EnumType.TWO: return "Hooray Two";
       default: return "Not Set";
    }
}
Reply | Threaded
Open this post in threaded view
|

Re: Fun with Enums - suggestion wanted for edit subset of enum types (netmask)

Thiago H de Paula Figueiredo
On Thu, 31 Oct 2013 08:51:34 -0200, Chris Mylonas <[hidden email]>  
wrote:

> Hi Tapestry Users!

Hi!

> How would I go about doing this (displaying certain enum values from the
> type)?

Just like the way you'd do with any other Java class: pass a SelectModel  
to it, probably using the SelectModelFactory service.

> The t:select component reads the message catalog, however rendering in a
> table (not a grid) seemed to ignore it.  I progressed with it by calling  
> a helper method from the template with something like
> ${convertEnum(passedEnum)}

Grid uses property viewing blocks and there's one specific for enums that  
looks up the labels in the exact same way as Select does. You can try  
using the PropertyDisplay component to render the enum property with the  
labels coming from app.properties. That's what Grid uses.

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

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

Reply | Threaded
Open this post in threaded view
|

Re: Fun with Enums - suggestion wanted for edit subset of enum types (netmask)

Jens Breitenstein
In reply to this post by chris@opencsta.org
Well, the values shown solely depends on your model. Just filter / sort it accordingly? By default Tapestry adds all enum values to options (see EnumSelectModel). Unfortunately you can not derive from EnumSelectModel, so I would try to start from AbstractSelectModel copy and paste a few lines from EnumSelectModel and provide a filter predicate which filters results in "getOptions" according to your requirements (retrieve all, filter and return the filtered list)

Jens

Von meinem iPhone gesendet

> Am 31.10.2013 um 11:51 schrieb Chris Mylonas <[hidden email]>:
>
> Hi Tapestry Users!
>
> I am positive we've all had fun with enums (and netmasks) at some point!!!
> I got through the afternoon accomplishing my page rendering *[1]
>
>
> I now have my entity class with an enum saved.
> It is a netmask for an ip address.
> So if an IP address belongs in a /24 subnet, I'd like to be able to assign
> it to a /32 subnet.
>
> I would like the t:select component to only display this option (or perhaps
> a /31 & /32), but not the whole range of available netmasks in my app (/24
> /25 /26...../32)
>
>
> How would I go about doing this (displaying certain enum values from the
> type)?
>
> Cheers for any awesome suggestions, ditto for reading!
> Chris
>
>
>
> [1]
> The t:select component reads the message catalog, however rendering in a
> table (not a grid) seemed to ignore it.  I progressed with it by calling a
> helper method from the template with something like
> ${convertEnum(passedEnum)}
>
> page class has this method
>
> public String convertEnum(EnumType n){
>    switch(n){
>       case EnumType.ONE: return "Hooray One";
>       case EnumType.TWO: return "Hooray Two";
>       default: return "Not Set";
>    }
> }

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

Reply | Threaded
Open this post in threaded view
|

Re: Fun with Enums - suggestion wanted for edit subset of enum types (netmask)

chris@opencsta.org
Thanks Jens, that sounds handy.
Between Thiago's and your response I'll be able to build something when I
get around to it today/tomorrow.

Have a good week Tappers
Chris


On Thu, Oct 31, 2013 at 10:15 PM, [hidden email] <[hidden email]
> wrote:

> Well, the values shown solely depends on your model. Just filter / sort it
> accordingly? By default Tapestry adds all enum values to options (see
> EnumSelectModel). Unfortunately you can not derive from EnumSelectModel, so
> I would try to start from AbstractSelectModel copy and paste a few lines
> from EnumSelectModel and provide a filter predicate which filters results
> in "getOptions" according to your requirements (retrieve all, filter and
> return the filtered list)
>
> Jens
>
> Von meinem iPhone gesendet
>
> > Am 31.10.2013 um 11:51 schrieb Chris Mylonas <[hidden email]>:
> >
> > Hi Tapestry Users!
> >
> > I am positive we've all had fun with enums (and netmasks) at some
> point!!!
> > I got through the afternoon accomplishing my page rendering *[1]
> >
> >
> > I now have my entity class with an enum saved.
> > It is a netmask for an ip address.
> > So if an IP address belongs in a /24 subnet, I'd like to be able to
> assign
> > it to a /32 subnet.
> >
> > I would like the t:select component to only display this option (or
> perhaps
> > a /31 & /32), but not the whole range of available netmasks in my app
> (/24
> > /25 /26...../32)
> >
> >
> > How would I go about doing this (displaying certain enum values from the
> > type)?
> >
> > Cheers for any awesome suggestions, ditto for reading!
> > Chris
> >
> >
> >
> > [1]
> > The t:select component reads the message catalog, however rendering in a
> > table (not a grid) seemed to ignore it.  I progressed with it by calling
> a
> > helper method from the template with something like
> > ${convertEnum(passedEnum)}
> >
> > page class has this method
> >
> > public String convertEnum(EnumType n){
> >    switch(n){
> >       case EnumType.ONE: return "Hooray One";
> >       case EnumType.TWO: return "Hooray Two";
> >       default: return "Not Set";
> >    }
> > }
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>