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 19:40:27 UTC

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

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


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.


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

Posted by "Erkki Lindpere (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/WICKET-2781?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12927615#action_12927615 ] 

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

Is noone intersted in this? In that case, I suggest this be closed as WONTFIX. I'm no longer interested in providing a patch because

1) I no longer work for the project where we used this

2) the logic got even more complicated to support more cases and is kind of hard to follow and may have performance impacts

3) it's usefulness was not very great, instead of injecting generics there are obviously other ways to solve this

> 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.


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

Posted by "Erkki Lindpere (JIRA)" <ji...@apache.org>.
    [ 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.


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

Posted by "Igor Vaynberg (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/WICKET-2781?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Igor Vaynberg resolved WICKET-2781.
-----------------------------------

    Resolution: Won't Fix
      Assignee: Igor Vaynberg

> 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
>            Assignee: Igor Vaynberg
>            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.


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

Posted by "Erkki Lindpere (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/WICKET-2781?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Erkki Lindpere updated WICKET-2781:
-----------------------------------

    Attachment: wicket-spring-inject-patch.txt

A patch against 1.4.7 that allows for injection into a generic superclass where the field type is a type variable.

> 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.


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

Posted by "Erkki Lindpere (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/WICKET-2781?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12844948#action_12844948 ] 

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

So I guess a better solution would be to replace Field.getType everywhere with something like:

Class<?> getFieldType(Object owner, Field field) {
  // try to get "reified" type
  else return field.getType();
}

> 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.


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

Posted by "Erkki Lindpere (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/WICKET-2781?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12845466#action_12845466 ] 

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

I implemented a more generic method[1], but this is currently using some snippets copied from an Artima.com article[2]. It allows even such things as:
abstract class EditPanel<R> {
  @SpringBean
  R repo;
}
class EditPage<Re> {
  new EditPanel<Re>() {};
}
class UserEditPage extends EditPage<UserRepository> {
}

The resolver will first resolve EditPanel's R to EditPage's Re. Then it tries to see if the owner of Re is the enclosing class of the EditPanel instance. It is, so it gets the enclosing instance (UserEditPage) and tries to resolve Re in that hierarchy.

I plan to improve this some more before submitting a new patch and I'll rewrite the pieces taken from Artima a bit differently.

[1] http://gist.github.com/333185
[2] http://www.artima.com/weblogs/viewpost.jsp?thread=208860

> 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.