You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Keith Bottner <kb...@gmail.com> on 2008/09/27 08:03:31 UTC

Encoder may not be instantiated directly.

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: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: Encoder may not be instantiated directly.

Posted by Keith Bottner <kb...@gmail.com>.
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 <kb...@gmail.com>:
>> 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: users-unsubscribe@tapestry.apache.org
>> For additional commands, e-mail: users-help@tapestry.apache.org
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: Encoder may not be instantiated directly.

Posted by Keith Bottner <kb...@gmail.com>.
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 <kb...@gmail.com>:
>> 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: users-unsubscribe@tapestry.apache.org
>> For additional commands, e-mail: users-help@tapestry.apache.org
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: Encoder may not be instantiated directly.

Posted by Ted Steen <te...@gmail.com>.
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 <kb...@gmail.com>:
> 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: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org