You can just create an instance of SelectModelImpl. To simplify things a
bit, I've just implemented the interface and delegated to a SelectModelImpl
instance.
public class ProductTypeSelectModel implements SelectModel
{
private final SelectModel model;
public ProductTypeSelectModel(final ObjectContext context)
{
final List<OptionModel> options = new ArrayList<OptionModel>();
final SelectQuery query = new SelectQuery(ProductType.class);
query.addOrdering(ProductType.NAME_PROPERTY, true);
final List<ProductType> productTypes = (List<ProductType>)
context.performQuery(query);
options.add(new OptionModelImpl("None (root level)", false, null));
for (final ProductType pt : productTypes)
{
options.add(new OptionModelImpl(pt.getName(), false, pt));
}
model = new SelectModelImpl(null, options);
}
public List<OptionGroupModel> getOptionGroups()
{
return model.getOptionGroups();
}
public List<OptionModel> getOptions()
{
return model.getOptions();
}
public void visit(final SelectModelVisitor visitor)
{
model.visit(visitor);
}
}
This example uses Cayenne to query for my "product_types" and sorts them by
name. Even if you're not familiar with Cayenne, it should be fairly
straightforward.
On 12/1/07 11:34 PM, in article [EMAIL PROTECTED], "Angelo Chen"
<[EMAIL PROTECTED]> wrote:
>
> Hi,
>
> I use a TreeMap for the 'Select' component, it works but it is always sorted
> in the key order, not the name of country when showing to the user, i read
> somewhere it can be a list, any suggestions, sample codes? thanks.
>
> A.C.
>
> public TreeMap<String, String> getCountryList() {return ...}
>
> <input t:type="select" t:id="country" model="countryList" t:value="country"
> /><br/>
>
--
Kevin Menard
Servprise International, Inc.
Remote reboot & power control for network equipment
www.servprise.com +1 508.892.3823 x308
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]