The moose likes JSF and the fly likes @ManagedProperty set in subclass Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "@ManagedProperty set in subclass" Watch "@ManagedProperty set in subclass" New topic

@ManagedProperty set in subclass

Jina Lu

Joined: Jul 09, 2010
Posts: 26

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

Joined: Jun 25, 2001
Posts: 17410

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.

An IDE is no substitute for an Intelligent Developer.
I agree. Here's the link:
subject: @ManagedProperty set in subclass
It's not a secret anymore!