You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Andy Pahne <an...@gmail.com> on 2010/01/28 15:14:17 UTC

Easy Way to create a select model?

I feel a little dumb, because for years I have been using Tapestry.

Is there an _easy_ way og creating a SelectModel like this one (not so 
uncommon one):

    value    label
---------------------
      1         Jan
      2         Feb
      ...


I had a look at the documentation. But I cannot believe I have to deal 
with SelectModel, OptionModel, OptionGroupModel and whatelse for this 
simple usecase.

I also had a look at the Wiki. I found four pages about selects. I 
cannot believe that I have to use such bloat for my usecase.

I surely must be missing something, or not?

Andy




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


Re: Easy Way to create a select model?

Posted by Andrew Court <an...@gmail.com>.
Hi Andy,

I find the easiest way to populate a select list is just to pass it a Map of
values. Something like the following:

	public Map<Integer,String> getMonthsModel()
	{		
		Map<Integer,String> model = new LinkedHashMap<Integer,String>();
		
		model.put(1, "Jan");
		model.put(2, "Feb");
		model.put(3, "Mar");
		
		return model;
		
	}


<select t:type="Select" t:model="monthsModel" />

Andrew





Andy Pahne-7 wrote:
> 
> 
> I feel a little dumb, because for years I have been using Tapestry.
> 
> Is there an _easy_ way og creating a SelectModel like this one (not so 
> uncommon one):
> 
>     value    label
> ---------------------
>       1         Jan
>       2         Feb
>       ...
> 
> 
> I had a look at the documentation. But I cannot believe I have to deal 
> with SelectModel, OptionModel, OptionGroupModel and whatelse for this 
> simple usecase.
> 
> I also had a look at the Wiki. I found four pages about selects. I 
> cannot believe that I have to use such bloat for my usecase.
> 
> I surely must be missing something, or not?
> 
> Andy
> 
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
> 
> 
> 

-- 
View this message in context: http://old.nabble.com/Easy-Way-to-create-a-select-model--tp27356514p27379053.html
Sent from the Tapestry - User mailing list archive at Nabble.com.


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


Re: Easy Way to create a select model?

Posted by Geoff Callender <ge...@gmail.com>.
And for an example:

	http://jumpstart.doublenegative.com.au:8080/jumpstart/examples/select/select/$N/$N/$N/$N

Cheers,

Geoff

On 29/01/2010, at 2:08 AM, Andy Pahne wrote:

> 
> 
> Yeah, that's it. Thanks a lot.
> 
> 
> 
> 
> Am 28.01.2010 15:50, schrieb Ulrich Stärk:
>> You are indeed missing something:
>> 
>> http://tapestry.apache.org/tapestry5.1/tapestry-core/ref/org/apache/tapestry5/corelib/components/Select.html 
>> 
>> <t:select t:id="months" model="literal:1=Jan,2=Feb,3=Mar,..."/>
>> 
>> HTH,
>> 
>> Uli
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
> 


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


Re: Easy Way to create a select model?

Posted by Peter Stavrinides <P....@albourne.com>.
> I feel a little dumb, because for years I have been using Tapestry...
Well that makes two of us Andy, from my point of view its nice to see Kristians example, and I am sure for others too. 

cheers,
Peter




-- 
If you are not an intended recipient of this e-mail, please notify the sender, delete it and do not read, act upon, print, disclose, copy, retain or redistribute it. Please visit http://www.albourne.com/email.html for important additional terms relating to this e-mail.

----- Original Message -----
From: "Andy Pahne" <an...@gmail.com>
To: "Tapestry users" <us...@tapestry.apache.org>
Sent: Thursday, 28 January, 2010 17:08:21 GMT +02:00 Athens, Beirut, Bucharest, Istanbul
Subject: Re: Easy Way to create a select model?



Yeah, that's it. Thanks a lot.




Am 28.01.2010 15:50, schrieb Ulrich Stärk:
> You are indeed missing something:
>
> http://tapestry.apache.org/tapestry5.1/tapestry-core/ref/org/apache/tapestry5/corelib/components/Select.html 
>
>
> <t:select t:id="months" model="literal:1=Jan,2=Feb,3=Mar,..."/>
>
> HTH,
>
> Uli


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


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


Re: Easy Way to create a select model?

Posted by Andy Pahne <an...@gmail.com>.

Yeah, that's it. Thanks a lot.




Am 28.01.2010 15:50, schrieb Ulrich Stärk:
> You are indeed missing something:
>
> http://tapestry.apache.org/tapestry5.1/tapestry-core/ref/org/apache/tapestry5/corelib/components/Select.html 
>
>
> <t:select t:id="months" model="literal:1=Jan,2=Feb,3=Mar,..."/>
>
> HTH,
>
> Uli


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


Re: Easy Way to create a select model?

Posted by Ulrich Stärk <ul...@spielviel.de>.
You are indeed missing something:

http://tapestry.apache.org/tapestry5.1/tapestry-core/ref/org/apache/tapestry5/corelib/components/Select.html

<t:select t:id="months" model="literal:1=Jan,2=Feb,3=Mar,..."/>

HTH,

Uli

On 28.01.2010 15:14 schrieb Andy Pahne:
>
> I feel a little dumb, because for years I have been using Tapestry.
>
> Is there an _easy_ way og creating a SelectModel like this one (not so
> uncommon one):
>
> value label
> ---------------------
> 1 Jan
> 2 Feb
> ...
>
>
> I had a look at the documentation. But I cannot believe I have to deal
> with SelectModel, OptionModel, OptionGroupModel and whatelse for this
> simple usecase.
>
> I also had a look at the Wiki. I found four pages about selects. I
> cannot believe that I have to use such bloat for my usecase.
>
> I surely must be missing something, or not?
>
> Andy
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>

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


Re: Easy Way to create a select model?

Posted by Kristian Marinkovic <kr...@porsche.co.at>.
import static org.apache.tapestry5.ioc.internal.util.CollectionFactory.
newList;




Andy Pahne <an...@gmail.com> 
28.01.2010 15:37
Bitte antworten an
"Tapestry users" <us...@tapestry.apache.org>


An
Tapestry users <us...@tapestry.apache.org>
Kopie

Thema
Re: Easy Way to create a select model?








It also contains a function call newList(), but this method isn't there.




Am 28.01.2010 15:17, schrieb Kristian Marinkovic:
> something like this:
>
> usage:
> SelectModel m = SelectModelUtils.toBeanSelectModel(someList, "name", 
"id"
> );
>
> explanation:
> use the value of the property "name" as label, the value of the "id"
> property as value;
> assuming that the bean within the list contains this properties
> (RuntimeException otherwise)
>
> code:
> public class SelectModelUtils
> {
>          private static final BeanUtilsBean beanUtil = BeanUtilsBean.
> getInstance();
>
>      /**
>       * Converts a list of beans to a {@link SelectModel} using the 
values
> of labelField and valueField.
>       */
>          public static<E>  SelectModel toBeanSelectModel(List<E> 
beanList,
> String labelField, String valueField)
>          {
>                  return new 
SimpleSelectModel(toBeanOptionModels(beanList,
> labelField, valueField));
>          }
>
>          public static<E>  SelectModel toBeanSelectModel(List<E>  input,
> String labelField)
>          {
>                  return toBeanSelectModel(input, labelField, null);
>          }
>
>      /**
>       * Converts a list of beans to a list of {@link OptionModel}s using
> getters for label and value.
>       */
>          private static<E>  List<OptionModel> toBeanOptionModels(List<E>
> beanList, String labelField, String valueField)
>      {
>          Defense.notNull(beanList, "beanList");
>
>          List<OptionModel>  result = newList();
>
>          for (E bean : beanList)
>              result.add(toBeanOptionModel(bean, labelField, 
valueField));
>
>          return result;
>      }
>
>      /**
>       * Converts an bean to an {@link OptionModel} using getters for 
label
> and value.
>       */
>      private static<E>  OptionModel toBeanOptionModel(E bean, String
> labelField, String valueField)
>      {
>                  if(bean != null) try
>                  {
>                          String label = beanUtil.getProperty(bean,
> labelField);
>                          Object value = valueField == null ? bean :
> beanUtil.getPropertyUtils().getProperty(bean, valueField);
>                          return new SimpleOptionModel<Object>(value,
> label);
>                  }
>                  catch (Exception e)
>                  {
>                          throw new RuntimeException(e);
>                  }
>                  return new SimpleOptionModel<E>(bean);
>      }
> }
>
>
>
> Andy Pahne<an...@gmail.com>
> 28.01.2010 15:14
> Bitte antworten an
> "Tapestry users"<us...@tapestry.apache.org>
>
>
> An
> users@tapestry.apache.org
> Kopie
>
> Thema
> Easy Way to create a select model?
>
>
>
>
>
>
>
>
> I feel a little dumb, because for years I have been using Tapestry.
>
> Is there an _easy_ way og creating a SelectModel like this one (not so
> uncommon one):
>
>      value    label
> ---------------------
>        1         Jan
>        2         Feb
>        ...
>
>
> I had a look at the documentation. But I cannot believe I have to deal
> with SelectModel, OptionModel, OptionGroupModel and whatelse for this
> simple usecase.
>
> I also had a look at the Wiki. I found four pages about selects. I
> cannot believe that I have to use such bloat for my usecase.
>
> I surely must be missing something, or not?
>
> Andy
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>
>
> 


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



Re: Easy Way to create a select model?

Posted by Andy Pahne <an...@gmail.com>.
It also contains a function call newList(), but this method isn't there.




Am 28.01.2010 15:17, schrieb Kristian Marinkovic:
> something like this:
>
> usage:
> SelectModel m = SelectModelUtils.toBeanSelectModel(someList, "name", "id"
> );
>
> explanation:
> use the value of the property "name" as label, the value of the "id"
> property as value;
> assuming that the bean within the list contains this properties
> (RuntimeException otherwise)
>
> code:
> public class SelectModelUtils
> {
>          private static final BeanUtilsBean beanUtil = BeanUtilsBean.
> getInstance();
>
>      /**
>       * Converts a list of beans to a {@link SelectModel} using the values
> of labelField and valueField.
>       */
>          public static<E>  SelectModel toBeanSelectModel(List<E>  beanList,
> String labelField, String valueField)
>          {
>                  return new SimpleSelectModel(toBeanOptionModels(beanList,
> labelField, valueField));
>          }
>
>          public static<E>  SelectModel toBeanSelectModel(List<E>  input,
> String labelField)
>          {
>                  return toBeanSelectModel(input, labelField, null);
>          }
>
>      /**
>       * Converts a list of beans to a list of {@link OptionModel}s using
> getters for label and value.
>       */
>          private static<E>  List<OptionModel>  toBeanOptionModels(List<E>
> beanList, String labelField, String valueField)
>      {
>          Defense.notNull(beanList, "beanList");
>
>          List<OptionModel>  result = newList();
>
>          for (E bean : beanList)
>              result.add(toBeanOptionModel(bean, labelField, valueField));
>
>          return result;
>      }
>
>      /**
>       * Converts an bean to an {@link OptionModel} using getters for label
> and value.
>       */
>      private static<E>  OptionModel toBeanOptionModel(E bean, String
> labelField, String valueField)
>      {
>                  if(bean != null) try
>                  {
>                          String label = beanUtil.getProperty(bean,
> labelField);
>                          Object value = valueField == null ? bean :
> beanUtil.getPropertyUtils().getProperty(bean, valueField);
>                          return new SimpleOptionModel<Object>(value,
> label);
>                  }
>                  catch (Exception e)
>                  {
>                          throw new RuntimeException(e);
>                  }
>                  return new SimpleOptionModel<E>(bean);
>      }
> }
>
>
>
> Andy Pahne<an...@gmail.com>
> 28.01.2010 15:14
> Bitte antworten an
> "Tapestry users"<us...@tapestry.apache.org>
>
>
> An
> users@tapestry.apache.org
> Kopie
>
> Thema
> Easy Way to create a select model?
>
>
>
>
>
>
>
>
> I feel a little dumb, because for years I have been using Tapestry.
>
> Is there an _easy_ way og creating a SelectModel like this one (not so
> uncommon one):
>
>      value    label
> ---------------------
>        1         Jan
>        2         Feb
>        ...
>
>
> I had a look at the documentation. But I cannot believe I have to deal
> with SelectModel, OptionModel, OptionGroupModel and whatelse for this
> simple usecase.
>
> I also had a look at the Wiki. I found four pages about selects. I
> cannot believe that I have to use such bloat for my usecase.
>
> I surely must be missing something, or not?
>
> Andy
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>
>
>    


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


Re: Easy Way to create a select model?

Posted by Kristian Marinkovic <kr...@porsche.co.at>.
you have to do it only once! should not be too hard :) 




Andy Pahne <an...@gmail.com> 
28.01.2010 15:42
Bitte antworten an
"Tapestry users" <us...@tapestry.apache.org>


An
Tapestry users <us...@tapestry.apache.org>
Kopie

Thema
Re: Easy Way to create a select model?







Am 28.01.2010 15:32, schrieb Kristian Marinkovic:
> public class SimpleOptionModel<T>  implements OptionModel
> {
>          private final T value;
>          private final String label;
>
>          public SimpleOptionModel(T value, String label)
>          {
>                  this.label = label;
>                  this.value = value;
>          }
> 



Unfortunatly this interface has some more functions to implement. My 
point is: isn't this all a bit to complicated? Just in order to show a 
model like the one I was referring to in my first mail?



     @Override
     public Map<String, String> getAttributes() {
         // TODO Auto-generated method stub
         return null;
     }

     @Override
     public String getLabel() {
         // TODO Auto-generated method stub
         return null;
     }

     @Override
     public Object getValue() {
         // TODO Auto-generated method stub
         return null;
     }



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



Re: Easy Way to create a select model?

Posted by Andy Pahne <an...@gmail.com>.
Am 28.01.2010 15:32, schrieb Kristian Marinkovic:
> public class SimpleOptionModel<T>  implements OptionModel
> {
>          private final T value;
>          private final String label;
>
>          public SimpleOptionModel(T value, String label)
>          {
>                  this.label = label;
>                  this.value = value;
>          }
>    



Unfortunatly this interface has some more functions to implement. My 
point is: isn't this all a bit to complicated? Just in order to show a 
model like the one I was referring to in my first mail?



     @Override
     public Map<String, String> getAttributes() {
         // TODO Auto-generated method stub
         return null;
     }

     @Override
     public String getLabel() {
         // TODO Auto-generated method stub
         return null;
     }

     @Override
     public Object getValue() {
         // TODO Auto-generated method stub
         return null;
     }



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


Re: Easy Way to create a select model?

Posted by Kristian Marinkovic <kr...@porsche.co.at>.
just a implementation of the interface with a constructor that accepts the 
value and the label

public class SimpleOptionModel<T> implements OptionModel
{
        private final T value;
        private final String label;
 
        public SimpleOptionModel(T value, String label)
        {
                this.label = label;
                this.value = value;
        }
..........

        



Telefon +43 (0)662 4670-6676
Fax +43 (0)662 4670-16676
kristian.marinkovic@porsche.co.at

Porsche Informatik Gesellschaft m.b.H. | A – 5101 Bergheim | 
Handelszentrum 7 
Sitz: Salzburg | FN 72830 d / Landesgericht Salzburg | DVR 88439 | UID ATU 
36773309
http://www.porsche-informatik.at




Andy Pahne <an...@gmail.com> 
28.01.2010 15:34
Bitte antworten an
"Tapestry users" <us...@tapestry.apache.org>


An
Tapestry users <us...@tapestry.apache.org>
Kopie

Thema
Re: Easy Way to create a select model?









Hi Kristian.

Thanks for the code. It does not compile right now. Do you have the 
source for SimpleOptionModel<T> also available?

Thnak you,
Andy




Am 28.01.2010 15:17, schrieb Kristian Marinkovic:
> something like this:
>
> usage:
> SelectModel m = SelectModelUtils.toBeanSelectModel(someList, "name", 
"id"
> );
>
> explanation:
> use the value of the property "name" as label, the value of the "id"
> property as value;
> assuming that the bean within the list contains this properties
> (RuntimeException otherwise)
>
> code:
> public class SelectModelUtils
> {
>          private static final BeanUtilsBean beanUtil = BeanUtilsBean.
> getInstance();
>
>      /**
>       * Converts a list of beans to a {@link SelectModel} using the 
values
> of labelField and valueField.
>       */
>          public static<E>  SelectModel toBeanSelectModel(List<E> 
beanList,
> String labelField, String valueField)
>          {
>                  return new 
SimpleSelectModel(toBeanOptionModels(beanList,
> labelField, valueField));
>          }
>
>          public static<E>  SelectModel toBeanSelectModel(List<E>  input,
> String labelField)
>          {
>                  return toBeanSelectModel(input, labelField, null);
>          }
>
>      /**
>       * Converts a list of beans to a list of {@link OptionModel}s using
> getters for label and value.
>       */
>          private static<E>  List<OptionModel> toBeanOptionModels(List<E>
> beanList, String labelField, String valueField)
>      {
>          Defense.notNull(beanList, "beanList");
>
>          List<OptionModel>  result = newList();
>
>          for (E bean : beanList)
>              result.add(toBeanOptionModel(bean, labelField, 
valueField));
>
>          return result;
>      }
>
>      /**
>       * Converts an bean to an {@link OptionModel} using getters for 
label
> and value.
>       */
>      private static<E>  OptionModel toBeanOptionModel(E bean, String
> labelField, String valueField)
>      {
>                  if(bean != null) try
>                  {
>                          String label = beanUtil.getProperty(bean,
> labelField);
>                          Object value = valueField == null ? bean :
> beanUtil.getPropertyUtils().getProperty(bean, valueField);
>                          return new SimpleOptionModel<Object>(value,
> label);
>                  }
>                  catch (Exception e)
>                  {
>                          throw new RuntimeException(e);
>                  }
>                  return new SimpleOptionModel<E>(bean);
>      }
> }
>
> 


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




Re: Easy Way to create a select model?

Posted by Andy Pahne <an...@gmail.com>.

Hi Kristian.

Thanks for the code. It does not compile right now. Do you have the 
source for SimpleOptionModel<T> also available?

Thnak you,
Andy




Am 28.01.2010 15:17, schrieb Kristian Marinkovic:
> something like this:
>
> usage:
> SelectModel m = SelectModelUtils.toBeanSelectModel(someList, "name", "id"
> );
>
> explanation:
> use the value of the property "name" as label, the value of the "id"
> property as value;
> assuming that the bean within the list contains this properties
> (RuntimeException otherwise)
>
> code:
> public class SelectModelUtils
> {
>          private static final BeanUtilsBean beanUtil = BeanUtilsBean.
> getInstance();
>
>      /**
>       * Converts a list of beans to a {@link SelectModel} using the values
> of labelField and valueField.
>       */
>          public static<E>  SelectModel toBeanSelectModel(List<E>  beanList,
> String labelField, String valueField)
>          {
>                  return new SimpleSelectModel(toBeanOptionModels(beanList,
> labelField, valueField));
>          }
>
>          public static<E>  SelectModel toBeanSelectModel(List<E>  input,
> String labelField)
>          {
>                  return toBeanSelectModel(input, labelField, null);
>          }
>
>      /**
>       * Converts a list of beans to a list of {@link OptionModel}s using
> getters for label and value.
>       */
>          private static<E>  List<OptionModel>  toBeanOptionModels(List<E>
> beanList, String labelField, String valueField)
>      {
>          Defense.notNull(beanList, "beanList");
>
>          List<OptionModel>  result = newList();
>
>          for (E bean : beanList)
>              result.add(toBeanOptionModel(bean, labelField, valueField));
>
>          return result;
>      }
>
>      /**
>       * Converts an bean to an {@link OptionModel} using getters for label
> and value.
>       */
>      private static<E>  OptionModel toBeanOptionModel(E bean, String
> labelField, String valueField)
>      {
>                  if(bean != null) try
>                  {
>                          String label = beanUtil.getProperty(bean,
> labelField);
>                          Object value = valueField == null ? bean :
> beanUtil.getPropertyUtils().getProperty(bean, valueField);
>                          return new SimpleOptionModel<Object>(value,
> label);
>                  }
>                  catch (Exception e)
>                  {
>                          throw new RuntimeException(e);
>                  }
>                  return new SimpleOptionModel<E>(bean);
>      }
> }
>
>    


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


Re: Easy Way to create a select model?

Posted by Kristian Marinkovic <kr...@porsche.co.at>.
something like this:

usage:
SelectModel m = SelectModelUtils.toBeanSelectModel(someList, "name", "id"
);

explanation:
use the value of the property "name" as label, the value of the "id" 
property as value;
assuming that the bean within the list contains this properties 
(RuntimeException otherwise)

code:
public class SelectModelUtils
{
        private static final BeanUtilsBean beanUtil = BeanUtilsBean.
getInstance();
 
    /**
     * Converts a list of beans to a {@link SelectModel} using the values 
of labelField and valueField.
     */ 
        public static <E> SelectModel toBeanSelectModel(List<E> beanList, 
String labelField, String valueField)
        {
                return new SimpleSelectModel(toBeanOptionModels(beanList, 
labelField, valueField));
        }

        public static <E> SelectModel toBeanSelectModel(List<E> input, 
String labelField)
        {
                return toBeanSelectModel(input, labelField, null);
        }
 
    /**
     * Converts a list of beans to a list of {@link OptionModel}s using 
getters for label and value.
     */
        private static <E> List<OptionModel> toBeanOptionModels(List<E> 
beanList, String labelField, String valueField)
    {
        Defense.notNull(beanList, "beanList");

        List<OptionModel> result = newList();

        for (E bean : beanList)
            result.add(toBeanOptionModel(bean, labelField, valueField));

        return result;
    }

    /**
     * Converts an bean to an {@link OptionModel} using getters for label 
and value.
     */
    private static <E> OptionModel toBeanOptionModel(E bean, String 
labelField, String valueField)
    {
                if(bean != null) try
                {
                        String label = beanUtil.getProperty(bean, 
labelField);
                        Object value = valueField == null ? bean : 
beanUtil.getPropertyUtils().getProperty(bean, valueField);
                        return new SimpleOptionModel<Object>(value, 
label);
                }
                catch (Exception e)
                {
                        throw new RuntimeException(e);
                }
                return new SimpleOptionModel<E>(bean);
    } 
}



Andy Pahne <an...@gmail.com> 
28.01.2010 15:14
Bitte antworten an
"Tapestry users" <us...@tapestry.apache.org>


An
users@tapestry.apache.org
Kopie

Thema
Easy Way to create a select model?








I feel a little dumb, because for years I have been using Tapestry.

Is there an _easy_ way og creating a SelectModel like this one (not so 
uncommon one):

    value    label
---------------------
      1         Jan
      2         Feb
      ...


I had a look at the documentation. But I cannot believe I have to deal 
with SelectModel, OptionModel, OptionGroupModel and whatelse for this 
simple usecase.

I also had a look at the Wiki. I found four pages about selects. I 
cannot believe that I have to use such bloat for my usecase.

I surely must be missing something, or not?

Andy




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