I am trying to use a bundle a select component for the specific case
of displaying a list of countries and from the all the documentation
that I have run across and I always get an exception when the page is
rendered. It says:
Component class com.shared.base.CountryEncoder may not be instantiated
directly. You should use an @InjectPage or @InjectComponent annotation
instead.
Code is below, any help is appreciated.
public class CountryEncoder implements ValueEncoder<Country>
{
public String toClient( Country value )
{
if (null == value) return null;
return value.getName();
}
public Country toValue( String clientValue )
{
if (InternalUtils.isBlank(clientValue)) return null;
return DAO.getCountry(clientValue);
}
}
public class CountryOptionModel implements OptionModel
{
Country country;
public CountryOptionModel(Country country)
{
this.country = country;
}
public String getLabel()
{
return country.getName();
}
public Object getValue()
{
return country;
}
public Map<String, String> getAttributes()
{
return null;
}
public boolean isDisabled()
{
return false;
}
}
public class CountrySelectModel implements SelectModel
{
private List<Country> countries;
public CountrySelectModel()
{
countries = DAO.getCountries();
}
public List<OptionGroupModel> getOptionGroups()
{
return null;
}
public List<OptionModel> getOptions()
{
if (null != countries)
{
List<OptionModel> options = new ArrayList<OptionModel>();
for (Country c : countries)
{
options.add(new CountryOptionModel(c));
}
return options;
}
return null;
}
public void visit( SelectModelVisitor visitor )
{
}
}
public class CountrySelect
{
private Country selectedCountry;
public Country getSelectedCountry()
{
return selectedCountry;
}
public void setSelectedCountry(Country country)
{
selectedCountry = country;
}
public CountrySelectModel getCountryModel()
{
return new CountrySelectModel();
}
public CountryEncoder getCountryEncoder()
{
return new CountryEncoder();
}
}
And my template has this.
<t:select t:value="selectedCountry" t:model="countryModel"
t:encoder="countryEncoder"/>
Any ideas?
Keith
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]