Re: Easy Way to create a select model?

2010-01-29 Thread Andrew Court

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 getMonthsModel()
{   
Map model = new LinkedHashMap();

model.put(1, "Jan");
model.put(2, "Feb");
model.put(3, "Mar");

return model;

}




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):
> 
> valuelabel
> -
>   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-unsubscr...@tapestry.apache.org
> For additional commands, e-mail: users-h...@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-unsubscr...@tapestry.apache.org
For additional commands, e-mail: users-h...@tapestry.apache.org



Re: Easy Way to create a select model?

2010-01-28 Thread Geoff Callender
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
>>  
>> 
>> 
>> 
>> HTH,
>> 
>> Uli
> 
> 
> -
> To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
> For additional commands, e-mail: users-h...@tapestry.apache.org
> 


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



Re: Easy Way to create a select model?

2010-01-28 Thread Peter Stavrinides
> 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" 
To: "Tapestry users" 
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
>  
>
>
> 
>
> HTH,
>
> Uli


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


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



Re: Easy Way to create a select model?

2010-01-28 Thread Andy Pahne



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 





HTH,

Uli



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



Re: Easy Way to create a select model?

2010-01-28 Thread Ulrich Stärk

You are indeed missing something:

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



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-unsubscr...@tapestry.apache.org
For additional commands, e-mail: users-h...@tapestry.apache.org



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



Re: Easy Way to create a select model?

2010-01-28 Thread Kristian Marinkovic
you have to do it only once! should not be too hard :) 




Andy Pahne  
28.01.2010 15:42
Bitte antworten an
"Tapestry users" 


An
Tapestry users 
Kopie

Thema
Re: Easy Way to create a select model?







Am 28.01.2010 15:32, schrieb Kristian Marinkovic:
> public class SimpleOptionModel  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 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-unsubscr...@tapestry.apache.org
For additional commands, e-mail: users-h...@tapestry.apache.org




Re: Easy Way to create a select model?

2010-01-28 Thread Andy Pahne

Am 28.01.2010 15:32, schrieb Kristian Marinkovic:

public class SimpleOptionModel  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 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-unsubscr...@tapestry.apache.org
For additional commands, e-mail: users-h...@tapestry.apache.org



Re: Easy Way to create a select model?

2010-01-28 Thread Kristian Marinkovic
import static org.apache.tapestry5.ioc.internal.util.CollectionFactory.
newList;




Andy Pahne  
28.01.2010 15:37
Bitte antworten an
"Tapestry users" 


An
Tapestry users 
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  SelectModel toBeanSelectModel(List 
beanList,
> String labelField, String valueField)
>  {
>  return new 
SimpleSelectModel(toBeanOptionModels(beanList,
> labelField, valueField));
>  }
>
>  public static  SelectModel toBeanSelectModel(List  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  List toBeanOptionModels(List
> beanList, String labelField, String valueField)
>  {
>  Defense.notNull(beanList, "beanList");
>
>  List  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  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(value,
> label);
>  }
>  catch (Exception e)
>  {
>  throw new RuntimeException(e);
>  }
>  return new SimpleOptionModel(bean);
>  }
> }
>
>
>
> Andy Pahne
> 28.01.2010 15:14
> Bitte antworten an
> "Tapestry users"
>
>
> 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):
>
>  valuelabel
> -
>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-unsubscr...@tapestry.apache.org
> For additional commands, e-mail: users-h...@tapestry.apache.org
>
>
>
> 


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




Re: Easy Way to create a select model?

2010-01-28 Thread Kristian Marinkovic
just a implementation of the interface with a constructor that accepts the 
value and the label

public class SimpleOptionModel 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.marinko...@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  
28.01.2010 15:34
Bitte antworten an
"Tapestry users" 


An
Tapestry users 
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 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  SelectModel toBeanSelectModel(List 
beanList,
> String labelField, String valueField)
>  {
>  return new 
SimpleSelectModel(toBeanOptionModels(beanList,
> labelField, valueField));
>  }
>
>  public static  SelectModel toBeanSelectModel(List  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  List toBeanOptionModels(List
> beanList, String labelField, String valueField)
>  {
>  Defense.notNull(beanList, "beanList");
>
>  List  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  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(value,
> label);
>  }
>  catch (Exception e)
>  {
>  throw new RuntimeException(e);
>  }
>  return new SimpleOptionModel(bean);
>  }
> }
>
> 


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





Re: Easy Way to create a select model?

2010-01-28 Thread Andy Pahne


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  SelectModel toBeanSelectModel(List  beanList,
String labelField, String valueField)
 {
 return new SimpleSelectModel(toBeanOptionModels(beanList,
labelField, valueField));
 }

 public static  SelectModel toBeanSelectModel(List  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  List  toBeanOptionModels(List
beanList, String labelField, String valueField)
 {
 Defense.notNull(beanList, "beanList");

 List  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  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(value,
label);
 }
 catch (Exception e)
 {
 throw new RuntimeException(e);
 }
 return new SimpleOptionModel(bean);
 }
}



Andy Pahne
28.01.2010 15:14
Bitte antworten an
"Tapestry users"


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):

 valuelabel
-
   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-unsubscr...@tapestry.apache.org
For additional commands, e-mail: users-h...@tapestry.apache.org



   



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



Re: Easy Way to create a select model?

2010-01-28 Thread Andy Pahne



Hi Kristian.

Thanks for the code. It does not compile right now. Do you have the 
source for SimpleOptionModel 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  SelectModel toBeanSelectModel(List  beanList,
String labelField, String valueField)
 {
 return new SimpleSelectModel(toBeanOptionModels(beanList,
labelField, valueField));
 }

 public static  SelectModel toBeanSelectModel(List  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  List  toBeanOptionModels(List
beanList, String labelField, String valueField)
 {
 Defense.notNull(beanList, "beanList");

 List  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  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(value,
label);
 }
 catch (Exception e)
 {
 throw new RuntimeException(e);
 }
 return new SimpleOptionModel(bean);
 }
}

   



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



Re: Easy Way to create a select model?

2010-01-28 Thread 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  SelectModel toBeanSelectModel(List beanList, 
String labelField, String valueField)
{
return new SimpleSelectModel(toBeanOptionModels(beanList, 
labelField, valueField));
}

public static  SelectModel toBeanSelectModel(List 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  List toBeanOptionModels(List 
beanList, String labelField, String valueField)
{
Defense.notNull(beanList, "beanList");

List 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  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(value, 
label);
}
catch (Exception e)
{
throw new RuntimeException(e);
}
return new SimpleOptionModel(bean);
} 
}



Andy Pahne  
28.01.2010 15:14
Bitte antworten an
"Tapestry users" 


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):

valuelabel
-
  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-unsubscr...@tapestry.apache.org
For additional commands, e-mail: users-h...@tapestry.apache.org