You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Chris Mylonas <ch...@opencsta.org> on 2013/10/31 11:51:34 UTC

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

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";
    }
}

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

Posted by Thiago H de Paula Figueiredo <th...@gmail.com>.
On Thu, 31 Oct 2013 08:51:34 -0200, Chris Mylonas <ch...@opencsta.org>  
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: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


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

Posted by Chris Mylonas <ch...@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, mailinglist@j-b-s.de <mailinglist@j-b-s.de
> 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 <ch...@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";
> >    }
> > }
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>

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

Posted by "mailinglist@j-b-s.de" <ma...@j-b-s.de>.
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 <ch...@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";
>    }
> }

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