You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Angelo Chen <an...@yahoo.com.hk> on 2007/12/02 05:34:36 UTC
T5: Select's model
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/>
--
View this message in context: http://www.nabble.com/T5%3A-Select%27s-model-tf4930588.html#a14112599
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: T5: Select's model
Posted by Kevin Menard <km...@servprise.com>.
I put mine into a selection package, like com.servprise.manager.selection.
These classes are not auto-enhanced, so I provide necessary ASOs and
services through the constructor as demonstrated in my example.
On 12/2/07 9:18 PM, in article 14122898.post@talk.nabble.com, "Angelo Chen"
<an...@yahoo.com.hk> wrote:
>
> Hi,
>
> This works, question now is, where to put this class? I put it under
> components, it works until I inject the hibernate service:
>
> @Inject
> private Session _session;
> public CountrySelectModel() {
> }
>
> _session is always null, any idea? thanks.
--
Kevin Menard
Servprise International, Inc.
Remote reboot & power control for network equipment
www.servprise.com +1 508.892.3823 x308
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re: T5: Select's model
Posted by Angelo Chen <an...@yahoo.com.hk>.
Hi,
This works, question now is, where to put this class? I put it under
components, it works until I inject the hibernate service:
@Inject
private Session _session;
public CountrySelectModel() {
}
_session is always null, any idea? thanks.
nirvdrum wrote:
>
> 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 14112599.post@talk.nabble.com, "Angelo
> Chen"
> <an...@yahoo.com.hk> 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: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>
>
--
View this message in context: http://www.nabble.com/T5%3A-Select%27s-model-tf4930588.html#a14122898
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: T5: Select's model
Posted by Kevin Menard <km...@servprise.com>.
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 14112599.post@talk.nabble.com, "Angelo Chen"
<an...@yahoo.com.hk> 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: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org