Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

@ManagedProperty set in subclass

 
Jina Lu
Greenhorn
Posts: 26
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hy,
I want to change this faces-config.xml to annotations, but I do have problems with supperVariable as it's property is different for each sub class. How should @ManagedProperty be declared to achieve this (MyClass extends MyAbstract class which contains variable supperVariable instance of SupperVariableClass, SupperVariableChildClass extends SupperChildClass) :


Thanks in advance
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18218
53
Android Eclipse IDE Linux
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Annotations can be a problem when you subclass, since the annotation in question has to be instructed on whether or not it is inheritable. If it's not, the annotation will simply be ignored.

The primary purpose of annotations is to allow coding with default values and eliminating or reducing the need for an external configuration file. When you have 2 instances of an object (inherited or not) and you need 2 different values injected into it, the best you can do is set one of them via annotation and override the annotation for the other instance using external configuration (XML).

There's really no way an annotation could specify per-instance values without greatly complicating things and probably destroying the POJO characteristics of the object as well.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic