• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

@PostConstruct from super-class not working...

 
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Saloon Keeper
Posts: 27808
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I believe it is documented behaviour that @PostConstruct cannot be inherited, so you may just be out of luck.
 
Daniel Platon
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 27808
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 27808
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK. Good. I fought some serious battles with that stuff back then. Glad to see it's fixed now.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic