You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by "Erkki Lindpere (JIRA)" <ji...@apache.org> on 2010/03/13 20:10:27 UTC

[jira] Commented: (WICKET-2781) Support @SpringBean injection into generic superclass

    [ https://issues.apache.org/jira/browse/WICKET-2781?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12844940#action_12844940 ] 

Erkki Lindpere commented on WICKET-2781:
----------------------------------------

Just realized this doesn't support multiple bounds on the type variable, as the proxy is created for what is returned by Field.getType() and a ClassCastException will be thrown if a method is called that is only on one of the secondary bounds of the type variable.

Supporting that might require changes to wicket-ioc, I think?

> Support @SpringBean injection into generic superclass
> -----------------------------------------------------
>
>                 Key: WICKET-2781
>                 URL: https://issues.apache.org/jira/browse/WICKET-2781
>             Project: Wicket
>          Issue Type: Improvement
>          Components: wicket-spring
>    Affects Versions: 1.4.7
>            Reporter: Erkki Lindpere
>            Priority: Minor
>         Attachments: wicket-spring-inject-patch.txt
>
>
> It's possible to inject Spring Beans into a generic superclass, if the field type to be injected is a type variable. I will attach a patch that does this (I don't know if it's the best or most general implementation, but it works in my case). This allows us to reduce code in a wicket-spring project and it would be great if you could integrate this change into wicket-spring.
> This also allows better integration with Scala because it seems Scala initialization order is different enough from Java that it seems impossible to make a variable injected into a subclass of a generic superclass available to the generic superclass's constructor.
> Simplified example for the motivation:
> public abstract class EditPage<EntityType, RepoType extends IRepository<EntityType>> {
>   @SpringBean
>   RepoType repository;
>   ...
> }
> Concrete "edit pages" extend this and define EntityType and RepoType. Injecting in the superclass allows the subclasses to be very thin, which is great. I was not able to implement this in Scala (maybe there's some trick but I don't know), even if I replace the repostiory with: protected abstract RepoType getRepository() and implement this in a Scala subclass:
> class UserEditPage extends EditPage<User, UserRepo> {
>   @SpringBean
>   var repo: UserRepo = _
>   def getRepository = repo
> }
> when the superclass' constructor calls getRepository, it will get null (and sometimes method not found getRepository: IRepository, but that might be due to JRebel)

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.