st.never
st.never

Reputation: 11753

@PostConstruct annotation on Weblogic 10.3.4 not being called

(This seems a duplicate of https://stackoverflow.com/questions/5862085/weblogic10-3-ignores-postconsturt-method, but that has little details and is not answered).

I have a ManagedBean like this:

public class TestBean {
    private String greeting = "Hello, World!";

    public TestBean() {
    }

    public String getGreeting() {
      System.out.println( "getGreeting called, returning " + this.greeting );
      return greeting;
}

public void setGreeting( String message ) {
      this.greeting = message;
}


    @PostConstruct
    public void prepareSomething() {
        System.out.println( "\n\nPostConstruct called.\n\n" );
        this.greeting += " (PostConstruct was called)";
    }
}

and in my xhtml, I have simply Bean Message: #{TestBean.greeting}. When accessing the page, however, the method is not called, and what I get is

Bean Message: Hello, World!

instead of the expected

Bean Message: Hello, World! (PostConstruct was called)

Console does display sysout's from the getGreeting() method, but not from prepareSomething():

INFO: Added Library from: zip:/data/java/wl1034/user_projects/domains/wlrep1034/autodeploy/PCTest.ear/PCTest.war/WEB-INF/lib/jsf-facelets.jar!/META-INF/jstl-fn.taglib.xml
getGreeting called, returning Hello, World!
2011-05-12 10:36:11,720 DEBUG org.richfaces.skin.SkinFactoryImpl - Create new Skin instance for name DEFAULT 

Further info: I am using JSF 1.2 (using the jars from Weblogic 10.3.4's MW_HOME/common/deployable-libs/jsf-1.2.war!/WEB-INF/lib), Facelets 1.1.14, RichFaces 3.3.2. I have the following jars on WEB-INF/lib:

commons-beanutils-1.7.0.jar
commons-digester-1.8.jar
commons-logging-1.1.1.jar
glassfish.jsf_1.0.0.0_1-2-15.jar
glassfish.jstl_1.2.0.1.jar
javax.jsf_1.1.0.0_1-2.jar
jsf-facelets.jar
log4j-1.2.16.jar
richfaces-api-3.3.2.SR1.jar
richfaces-impl-3.3.2.SR1.jar
richfaces-ui-3.3.2.SR1.jar
SimpleJSF.jar
wls.jsf.di.jar

I have tried placing/removing annotations-api.jar as well, same symptoms.

I may post other files if necessary.

Upvotes: 0

Views: 2291

Answers (2)

st.never
st.never

Reputation: 11753

Answering my own question again... Seems that, although you can embed Weblogic's JSF libraries into your own app (this is desirable for our company because we develop a product that should have little installation impact on several customers), the dependency injection and post-construct mechanisms only work if you actually deploy the library and refer to it.

This site helped me out: http://blog.eisele.net/2009/02/jsf-versions-and-weblogic-server.html

In a nutshell, I had to deploy Weblogic's JSF war as a library, remove its jars from my own app (also removed annotations-api), and add the following to my WEB-INF/weblogic.xml:

<library-ref>
  <library-name>jsf</library-name>
  <specification-version>1.2</specification-version>
  <implementation-version>1.2</implementation-version>
  <exact-match>false</exact-match>
</library-ref>

I also had to rewrite a couple beans which used @PostConstruct more than once. This works in Websphere, Jetty, and Tomcat, but Weblogic explicitly forbids using it more that once:

http://download.oracle.com/docs/cd/E12840_01/wls/docs103/programming/annotate_dependency.html

Upvotes: 0

BalusC
BalusC

Reputation: 1108722

I don't use Weblogic, but if I am not wrong, Weblogic already ships with its own JSTL/JSF libraries. So you don't need to supply them yourself at all.

But if I am wrong and Weblogic don't ship with them, then those libraries doesn't look quite right. What versions exactly are those?

glassfish.jsf_1.0.0.0_1-2-15.jar
glassfish.jstl_1.2.0.1.jar
javax.jsf_1.1.0.0_1-2.jar

The @PostConstruct works on JSF 1.2 or newer only. You can download JSF 1.2 here. It exist of two JAR files

jsf-api.jar
jsf-impl.jar

You only need to ensure that your faces-config.xml is declared conform JSF 1.2 specification and also that web.xml is declared conform at least Servlet 2.5 specification.

Finally, the JSTL library should be this one.

Upvotes: 1

Related Questions