*
The moose likes JSF and the fly likes Managed beans aren't constructed running on JBoss 5.1.0 (works fine with Tomcat 6) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "Managed beans aren Watch "Managed beans aren New topic
Author

Managed beans aren't constructed running on JBoss 5.1.0 (works fine with Tomcat 6)

Max Neves
Greenhorn

Joined: Sep 24, 2009
Posts: 7
Hi everybody,

This is my first post here

I'm migrating an application from Tomcat 6.0.0.20 (working fine) to JBoss 5.1.0 and I'm facing the following problem:
The application starts fine without error but firstly I realized that the functions marked with the notation @PostContruction wasn't being called and then I figured out that the managed beans simply weren't being constructed/initialized.

For example, I have the following managed bean


When doSomeThing() is fired, I checked by logs that Welcome isn't created and init() isn't called.

Extract of my faces-config.xml


The application uses JSF 1.2 (libraries supplied by JBoss) and RichFaces 3.3.1.

Any thoughts?
Hope anyone can help me.
Thanks
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15957
    
  19

Welcome to the JavaRanch, Neves!

There's absolutely no reason I can see why you should have this problem, but that's probably because of the things I'm not seeing.

Given your bean definitions and your faces-config snipper, a commandButton with an 'action="#{welcome.doSomething}"' should see the construction of a request-scope object of type Welcome and the firing of the action method.

The only flaw I can see is that you're using inheritance, and there are issues with inheriting annotations, but I don't think that applies in your case, since the annotation is on the inheriting object class.


Customer surveys are for companies who didn't pay proper attention to begin with.
Max Neves
Greenhorn

Joined: Sep 24, 2009
Posts: 7
Hi Tim,

Thanks for your reply

Tim Holloway wrote:
There's absolutely no reason I can see why you should have this problem, but that's probably because of the things I'm not seeing.


Yes, that's a weird situation...
The worst thing is I've no clue about what's happening here.

Here's my web.xml used to deploy the application on Tomcat 6:



We use the below web.xml to test on JBoss 5:


The thing is: no matter what web.xml we use, we get the same problem on managed-beans: neither constructors nor methods flagged with @PostConstruct aren't called.


Given your bean definitions and your faces-config snipper, a commandButton with an 'action="#{welcome.doSomething}"' should see the construction of a request-scope object of type Welcome and the firing of the action method.


We realized this problem with JBoss exactly because whenever we fire a button or hyperlink (having an action=#{welcome.doSomething} like you said), 'doSomething()' manipulates objects that should be initilized on 'init()' and, since it isn't called, we got exceptions. After analizing the logs, we figured out this problem.


The only flaw I can see is that you're using inheritance, and there are issues with inheriting annotations, but I don't think that applies in your case, since the annotation is on the inheriting object class.


I see your point.
We have a managed-bean called 'Login' (the only one session-scoped) which isn't a subclasse of 'BaseBean':



Well, we runned the application on JBoss, we got the following logs:



Running on Tomcat yields:


What I concluded so far
I said in the title that the managed beans weren't constructed when deploying on Jboss. It's wrong (thinking in terms of Java, it would be a very weird situation...).
However, the methods flagged with the annotation @PostConstruct aren't called. We don't have this problem with Tomcat.

I'm considering to use the "straighforward" workaround: call my @PostConstruct flagged methods in the constructor.

My reformulated question
Does anyone have any idea about what's going on with @PostConstruct and JBoss?

Thanks a lot
Max
Kavita Tipnis
Ranch Hand

Joined: Sep 21, 2008
Posts: 177
Perhaps the JBoss container is expecting a different @PostConstruct method signature
For Instance , instead of



I just remember reading this somewhere, did not have to try it but you can give it a try
Max Neves
Greenhorn

Joined: Sep 24, 2009
Posts: 7
Hi Kavita, thanks for replying

No, you can give the name you want to the method(s) annotated with @PostConstruct, it doesn't matter.

Anyway, I tried your suggestion and it doesn't work:


When executed on JBoss, the application generates the logs below:



Conclusion: the annotation @PostConstruct doesn't work at all

I googled at lot and I wasn't able to find any issue with Jboss and @PostConstruct

Any help will be welcome - I'm confused!
Kavita Tipnis
Ranch Hand

Joined: Sep 21, 2008
Posts: 177
Might sound silly, but do you have an import for PostConstruct?
Max Neves
Greenhorn

Joined: Sep 24, 2009
Posts: 7
Kavita Tipnis wrote:Might sound silly, but do you have an import for PostConstruct?

Hi, sure I do. If I didn't, the application wouldn't have started.
By the way, I'm using Javax annotations:

Does JBoss require another "kind" of annotation?
I mean, has JBoss its own annotations?
Kavita Tipnis
Ranch Hand

Joined: Sep 21, 2008
Posts: 177
Sorry, but happened to read that issue somewhere
here is something that might be helpful
http://www.jboss.org/index.html?module=bb&op=viewtopic&p=4187631#4187631
Kavita Tipnis
Ranch Hand

Joined: Sep 21, 2008
Posts: 177
Ok, it looks like this issue is still prevalent in JBoss, they have suggested an alternate import(org.jboss.seam.annotations.intercept.PostConstruct)
on the one of the issues, but not sure if it resolved the problem, and I don't see the point because you are not using seam anyways.
So you might be better off doing it the old way
Max Neves
Greenhorn

Joined: Sep 24, 2009
Posts: 7
Hi,

Kavita Tipnis wrote:Sorry, but happened to read that issue somewhere
here is something that might be helpful
http://www.jboss.org/index.html?module=bb&op=viewtopic&p=4187631#4187631


I read it but I'm not using EJB, so I don't know if the clue applies to my case.

Kavita Tipnis wrote:Ok, it looks like this issue is still prevalent in JBoss, they have suggested an alternate import(org.jboss.seam.annotations.intercept.PostConstruct)
on the one of the issues, but not sure if it resolved the problem, and I don't see the point because you are not using seam anyways.
So you might be better off doing it the old way


I'm not sure neither that using a Seam annotation will solve this problem.
Anyway, even if it does, I'm not using Seam at all and putting Seam in my application "just" to solve that doesn't sound brilliant to me.

I posted this problem on JBoss forum but I got no answer so far.
I'll code a very simple JSF application to run on JBoss to test the @PostConstruct as soon as I can.

Thank you guys.
Josh Peters
Greenhorn

Joined: Nov 24, 2009
Posts: 4
I've been tackling precisely the same issue; so far I've got nothing too. Please post back if you ever determine your issue.
Josh Peters
Greenhorn

Joined: Nov 24, 2009
Posts: 4
My issue is solved! I had the JSR 250 api listed as a dependency in my Maven build, and I was distributing the JARs with the WAR project. Changing the scope of that dependency to provided solved my issue.

I've been chewing on that stupid issue for days!

Hope this helps someone else.
Max Neves
Greenhorn

Joined: Sep 24, 2009
Posts: 7
Josh Peters wrote:My issue is solved! I had the JSR 250 api listed as a dependency in my Maven build, and I was distributing the JARs with the WAR project. Changing the scope of that dependency to provided solved my issue.

I've been chewing on that stupid issue for days!

Hope this helps someone else.


Hi Josh,
I didn't get it, how have you managed to fix the problem? Just by kicking the jsr250 JAR?
My problem is: I dont use jsr250 at all, and so I continue having any idea about how to solve this silly situation
Josh Peters
Greenhorn

Joined: Nov 24, 2009
Posts: 4
Well, my problem was that both JBoss and my WAR were trying to provide the JSR 250 API. Since I use Maven to build things, my solution was to exclude that JAR from the final result of my build.

Perhaps JBoss doesn't have those jars available to it (are you running on a minimal config server or something more)?

Good luck.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Managed beans aren't constructed running on JBoss 5.1.0 (works fine with Tomcat 6)
 
Similar Threads
Beggining JSF: FaceletViewHandler
App doesn't work
@PostConstruct dont work
h:commond button's action does'nt work
problem on JSF application