On Fri, May 09, 2008 at 03:39:07PM -0700, Michael Mehrle wrote:
> I like your solution, but you are using an IntegerSelectChoice as your
> model, which won't work for me. I need to set my model to a regular
> Integer since that's what's being persisted on the backend.
>
> Michael
Quite right. I really don't like the idea of SelectChoice (a
view-related class) in a business model. Try this, Michael...
public MyBusinessClass {
private int period; // getter/setter omitted for clarity
}
MyBusinessClass myObject = // blah
List periods = Arrays.asList(new Integer[] { 1, 7, 14, 30, 365 });
new DropDownChoice("period",
new PropertyModel(myObject, "period"),
periods,
new ChoiceRenderer() {
public String getDisplayValue(Object object) {
int period = ((Integer) object).intValue();
switch (period) {
case 1: return "Day";
case 7: return "Week";
case 14: return "Fortnight";
case 30: return "Month";
case 365: return "Year";
default: throw new RuntimeException();
}
}
}
);
If like me you have to localize all your strings, it becomes even
simpler...
new DropDownChoice("period",
new PropertyModel(myObject, "period"),
periods,
new ChoiceRenderer() {
public String getDisplayValue(Object object) {
return getString("period_" + object.toString());
}
}
);
...then in your properties file...
period_1=Day
period_7=Week
# ...and so on
jk
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]