@Component vs @InjectComponent
文章来源: 随便回复2008-09-29 02:45:59
What's the difference between the @Component and @InjectComponent annotations?

The @Component annotation is used to define the type of component, and its parameter bindings. When using @Component, the template must not define the type, and any parameter bindings are merged in:

Back to home
...

@Component(parameters={ "page=index" })
private PageLink home;

Here the type of component is defined by the field type. The field name is matched against the t:id in the template. The page parameter is set in the Java class, and the informal class parameter is set in the template. If the tag in the template was , or if the template tag included the attribute t:type="pagelink", then you would see an exception.

By contrast, @InjectComponent expects the component to be already defined, and doesn't allow any configuration of it:

...

@InjectComponent
private Form login;

Again, we're matching the field name to the component id, and you would get an error if the component is not defined in the template.



refer:
1. http://tapestry.apache.org/injection-faq.html


2. http://tapestry.formos.com/nightly/tapestry5/faq/general.html#component-vs-injectcomponent