You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Richard Clark <rd...@nextquestion.net> on 2005/11/01 02:59:58 UTC

@InjectObject and concrete classes

I'm experimenting with Tapestry 4 (not quite ready to apply this to  
the huge production app yet ;) ), and ran into an interesting problem.

I have a Validator that's used in my login process, and a service  
that gives access to the user names & passwords. I would like the  
validator to pick up the service itself, but it's not working right.

When I try:

public abstract LoginValidator implements Validator {

   @InjectObject(UserDataSource.class)
   public abstract UserDataSource getUserInfo();

   ...
}

I get an instantiation exception when trying to use the validator.  
But when I make this concrete (adding a private UserDataSource field  
and changing the above declaration to:

@InjectObject(UserDataSource.class)
   public UserDataSource getUserInfo() {
     return userInfo;
   }

   public void setUserInfo(UserDataSource info) {
     userInfo = info;
   }

userInfo is always null!

So, what's the trick to making this work? Will I always have to  
declare this in a <bean> element and set the user data source from  
the outside, or is there a way to keep it nicely self-contained?

  ...Richard



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


Re: @InjectObject and concrete classes

Posted by Howard Lewis Ship <hl...@gmail.com>.
Sorry, but those annotations are only supported for pages and
components, not for beans or anything else.

However, it easy to define a HiveMind service, inject whats needed
into the service, and then inject that service into your page or
component.


On 10/31/05, Richard Clark <rd...@nextquestion.net> wrote:
> Correction:
>
>    Make that injection call @InjectObject("service:gtd.UserDataSource")
>
>    That's what I get for not just cutting and pasting! (It still
> fails as described)
>
>   ...R
>
> On Oct 31, 2005, at 17:59, Richard Clark wrote:
>
> > I'm experimenting with Tapestry 4 (not quite ready to apply this to
> > the huge production app yet ;) ), and ran into an interesting problem.
> >
> > I have a Validator that's used in my login process, and a service
> > that gives access to the user names & passwords. I would like the
> > validator to pick up the service itself, but it's not working right.
> >
> > When I try:
> >
> > public abstract LoginValidator implements Validator {
> >
> >   @InjectObject(UserDataSource.class)
> >   public abstract UserDataSource getUserInfo();
> >
> >   ...
> > }
> >
> > I get an instantiation exception when trying to use the validator.
> > But when I make this concrete (adding a private UserDataSource
> > field and changing the above declaration to:
> >
> > @InjectObject(UserDataSource.class)
> >   public UserDataSource getUserInfo() {
> >     return userInfo;
> >   }
> >
> >   public void setUserInfo(UserDataSource info) {
> >     userInfo = info;
> >   }
> >
> > userInfo is always null!
> >
> > So, what's the trick to making this work? Will I always have to
> > declare this in a <bean> element and set the user data source from
> > the outside, or is there a way to keep it nicely self-contained?
> >
> >  ...Richard
> >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
> >
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>
>


--
Howard M. Lewis Ship
Independent J2EE / Open-Source Java Consultant
Creator, Jakarta Tapestry
Creator, Jakarta HiveMind

Professional Tapestry training, mentoring, support
and project work.  http://howardlewisship.com

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


Re: @InjectObject and concrete classes

Posted by Richard Clark <rd...@nextquestion.net>.
Correction:

   Make that injection call @InjectObject("service:gtd.UserDataSource")

   That's what I get for not just cutting and pasting! (It still  
fails as described)

  ...R

On Oct 31, 2005, at 17:59, Richard Clark wrote:

> I'm experimenting with Tapestry 4 (not quite ready to apply this to  
> the huge production app yet ;) ), and ran into an interesting problem.
>
> I have a Validator that's used in my login process, and a service  
> that gives access to the user names & passwords. I would like the  
> validator to pick up the service itself, but it's not working right.
>
> When I try:
>
> public abstract LoginValidator implements Validator {
>
>   @InjectObject(UserDataSource.class)
>   public abstract UserDataSource getUserInfo();
>
>   ...
> }
>
> I get an instantiation exception when trying to use the validator.  
> But when I make this concrete (adding a private UserDataSource  
> field and changing the above declaration to:
>
> @InjectObject(UserDataSource.class)
>   public UserDataSource getUserInfo() {
>     return userInfo;
>   }
>
>   public void setUserInfo(UserDataSource info) {
>     userInfo = info;
>   }
>
> userInfo is always null!
>
> So, what's the trick to making this work? Will I always have to  
> declare this in a <bean> element and set the user data source from  
> the outside, or is there a way to keep it nicely self-contained?
>
>  ...Richard
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>
>


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