Re: Encoder may not be instantiated directly.

2008-09-27 Thread Ted Steen
You should not put non-component code under component packages.
see http://tapestry.apache.org/tapestry5/guide/component-classes.html
move the CountryEncoder to something like com.shared.util instead.

2008/9/27 Keith Bottner [EMAIL PROTECTED]:
 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 ValueEncoderCountry
 {

  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 MapString, String getAttributes()
  {
return null;
  }

  public boolean isDisabled()
  {
return false;
  }
 }

 public class CountrySelectModel implements SelectModel
 {
  private ListCountry countries;

  public CountrySelectModel()
  {
countries = DAO.getCountries();
  }

  public ListOptionGroupModel getOptionGroups()
  {
return null;
  }

  public ListOptionModel getOptions()
  {
if (null != countries)
{
  ListOptionModel options = new ArrayListOptionModel();
  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]



-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Encoder may not be instantiated directly.

2008-09-27 Thread Keith Bottner

Ted,

Thanks for the pointer, that made it stop giving me the error all  
right and now it displays.


Now all I have to do is figure out why it always comes back as null  
when I include it in my template.


Keith

On Sep 27, 2008, at 1:36 AM, Ted Steen wrote:


You should not put non-component code under component packages.
see http://tapestry.apache.org/tapestry5/guide/component-classes.html
move the CountryEncoder to something like com.shared.util instead.

2008/9/27 Keith Bottner [EMAIL PROTECTED]:
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 ValueEncoderCountry
{

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 MapString, String getAttributes()
{
  return null;
}

public boolean isDisabled()
{
  return false;
}
}

public class CountrySelectModel implements SelectModel
{
private ListCountry countries;

public CountrySelectModel()
{
  countries = DAO.getCountries();
}

public ListOptionGroupModel getOptionGroups()
{
  return null;
}

public ListOptionModel getOptions()
{
  if (null != countries)
  {
ListOptionModel options = new ArrayListOptionModel();
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]




-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Encoder may not be instantiated directly.

2008-09-27 Thread Keith Bottner

Ted,

That worked but I am getting null for the value.

In my page class I have:

@Property
private Country test;

And in my template I have:

t:vf.countrySelect t:id=test /

(It is vf,countrySelect because I have this bundled in a library of  
share components and such.)


No matter what I set it to when the page displays after submission in  
my onSubmit handler test is NULL.


Anyone else had this problem? Is there something undocumented about  
getting this setup properly?


Thanks in advance,

Keith


On Sep 27, 2008, at 1:36 AM, Ted Steen wrote:


You should not put non-component code under component packages.
see http://tapestry.apache.org/tapestry5/guide/component-classes.html
move the CountryEncoder to something like com.shared.util instead.

2008/9/27 Keith Bottner [EMAIL PROTECTED]:
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 ValueEncoderCountry
{

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 MapString, String getAttributes()
{
  return null;
}

public boolean isDisabled()
{
  return false;
}
}

public class CountrySelectModel implements SelectModel
{
private ListCountry countries;

public CountrySelectModel()
{
  countries = DAO.getCountries();
}

public ListOptionGroupModel getOptionGroups()
{
  return null;
}

public ListOptionModel getOptions()
{
  if (null != countries)
  {
ListOptionModel options = new ArrayListOptionModel();
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]




-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]