aspose file tools*
The moose likes JSF and the fly likes @PostConstruct from super-class not working... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "@PostConstruct from super-class not working..." Watch "@PostConstruct from super-class not working..." New topic
Author

@PostConstruct from super-class not working...

Daniel Platon
Ranch Hand

Joined: Oct 10, 2005
Posts: 42
Hello everyone,

Here's the problem - we have two classes:

class SuperBean, that has an init() method annotated with @PostConstruct

class NormalBean has no method whatsoever but extends SuperBean. NormalBean will just override some methods from the superclass

The jspx page displays the motd attribute using something like

Using the setting above the output in the browser is
This clearly means that the motd property is not set, i.e. the SuperBean.init() method does not run.

However, if I alter the NormalBean class like this:


The message in the browser displays correctly.

Why is this happening? I need the init() method to be only in the superclass, so the developer doesn't have to bother with the initialization stuff...
Actually, the original bug(?) is in IceFaces 1.8, but I tested it in a plain JSF1.2 application and I get the same behaviour, as you can see.

Thank you very much,
Dan
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16305
    
  21

I believe it is documented behaviour that @PostConstruct cannot be inherited, so you may just be out of luck.


Customer surveys are for companies who didn't pay proper attention to begin with.
Daniel Platon
Ranch Hand

Joined: Oct 10, 2005
Posts: 42
I believe it is documented behaviour that @PostConstruct cannot be inherited, so you may just be out of luck.


Actually... I have performed the same test using a simple Spring application, with no JSF involved. The @PostConstruct annotation worked as expected, and the init() method of the superclass was called immediately after the constructor. This means that is really a JSF "bug" (or should I say... bad implementation).
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16305
    
  21

I didn't appreciate it either, but if you do a little web searching, you'll probably uncover the discussion on the matter. For what it's worth. At the moment, the practical aspect of it all is you're out of luck, though.
Daniel Platon
Ranch Hand

Joined: Oct 10, 2005
Posts: 42
I did a little research and came up with this issue. Turns out it's a Tomcat issue, for any versions prior to 6.0.18. I upgraded to 6.0.32 and everything works fine.

Thank you Tim for pointing me to the right direction!
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16305
    
  21

OK. Good. I fought some serious battles with that stuff back then. Glad to see it's fixed now.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: @PostConstruct from super-class not working...