2

Environment

  • Weblogic 12.1.3.0.0
  • Java 1.7
  • JSF 2.2 (provide libraries from app because of issues with Weblogic Server)
  • Ant-based build tool (huge company means old tools)

Files

Portal.java

@ManagedBean(name="portal")
@ViewScoped
public class Portal {
    public String foo ="foo";

    @PostConstruct
    public void init() {
        System.out.println("instantiated");
    }
}

portal.xhtml

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:c="http://java.sun.com/jsp/jstl/core">

<ui:composition template="/WEB-INF/templates/wide_template.xhtml">
    <ui:define name="mainContent"> 

        <!-- other markup removed -->

        <h:outputText value="hello:#{portal.foo}"></h:outputText>
    </ui:define>
</ui:composition>
</html>

faces-config.xml

<?xml version="1.0" encoding="UTF-8"?>
<faces-config xmlns="http://xmlns.jcp.org/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-facesconfig_2_2.xsd"
    version="2.2">

</faces-config>

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="3.0">
    <context-param>
        <param-name>facelets.REFRESH_PERIOD</param-name>
        <param-value>2</param-value>
    </context-param>
    <context-param>
        <param-name>com.sun.faces.validateXml</param-name>
        <param-value>true</param-value>
    </context-param>
    <context-param>
        <param-name>com.sun.faces.verifyObjects</param-name>
        <param-value>true</param-value>
    </context-param>
    <context-param>
        <param-name>javax.faces.DEFAULT_SUFFIX</param-name>
        <param-value>.xhtml</param-value>
    </context-param>
    <context-param>
        <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
        <param-value>server</param-value>
    </context-param>
    <context-param>
        <param-name>javax.faces.FACELETS_SKIP_COMMENTS</param-name>
        <param-value>true</param-value>
    </context-param>
    <context-param>
        <param-name>com.sun.faces.expressionFactory</param-name>
        <param-value>com.sun.el.ExpressionFactoryImpl</param-value>
    </context-param>
    <context-param> 
        <param-name>javax.faces.PROJECT_STAGE</param-name> 
        <param-value>Development</param-value> 
    </context-param> 

    <welcome-file-list>
        <welcome-file>portal.xhtml</welcome-file>
    </welcome-file-list>

    <servlet>
        <servlet-name>Faces Servlet</servlet-name>
        <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>/skinned/*</url-pattern>
        <url-pattern>*.faces</url-pattern>
        <url-pattern>/faces/*</url-pattern>
        <url-pattern>*.jsf</url-pattern>
    </servlet-mapping>
</web-app>

Problem

My page renders all elements correctly. For example h:selectOneMenu and so on. But it seems that my Managed Bean is never instantiated as i don't see output on the console nor does the page render the content of foo.

I've read some other questions on SO:

Does anyone know about issues with SessionScope maybe?

Is there something I'm missing? Or do I have to provide more, like the app-structure after deployment, more code, screenshots?

Community
  • 1
  • 1
Chiff Shinz
  • 377
  • 2
  • 14
  • do you have getter and setter on foo? – Maciej Kowalski Jan 25 '17 at 11:21
  • @MaciejKowalski of course. But it shouldn't matter anyways as it's public. – Chiff Shinz Jan 25 '17 at 11:22
  • *"But it shouldn't matter anyways as it's public"* That isn't true. *"provide libraries from app because of issues with Weblogic Server"* That'll be the cause of your problem. – BalusC Jan 25 '17 at 13:55
  • Uh, okay thought it doesn't matter. Will check that right now. I also checked the web again right now for JSF 2.2 on Weblogic and it seems that Weblogic 12.1.1+ actually does have the required libraries [see docs.oracle.com](https://docs.oracle.com/cd/E24329_01/web.1211/e21049/configurejsfandjtsl.htm#WBAPP198). So this means I can definitely revert the changes done to weblogic-application.xml. Interesting thing is, that I only used them because it didn't work without providing the libraries from the app. But I'll try again and hope that it will work. Thanks for the input! – Chiff Shinz Jan 25 '17 at 14:16
  • @BalusC I tried again but the server gives me a 404 - not found and in the console I get `There was a failure when processing annotations for application ...` which leads me to [this](http://stackoverflow.com/questions/36835218/there-was-a-failure-when-processing-annotations-for-application) and based on that I researched further and came to the conclusion, that I have to serve the libraries myself. tbc... – Chiff Shinz Jan 25 '17 at 15:10
  • I also get `Failed to initialize the application due to error weblogic.application.ModuleException: java.lang.NullPointerException` and when searching for that I came to [this](http://stackoverflow.com/questions/18983947/nullpointerexception-when-deploy-weblogic-12c-application), which also states more or less the same. And at the end, serving the libraries myself fixed it to the point where my page shows up and the server console does not show any errors. – Chiff Shinz Jan 25 '17 at 15:10

2 Answers2

0

As it is @ViewScoped bean you have to implement Serializable as the implementation may decide to serialize session or view scoped beans whenever there is a need for that.

@ManagedBean(name="portal")
@ViewScoped
public class Portal  implements Serializable{

In theory the NonSerializableException should occur only during the serialization itself, but maybe your environment set-up prevents the creation itself.

Anyway all your @SessionScoped / @ViewScoped should be marked like that by definition anyway.

Maciej Kowalski
  • 25,605
  • 12
  • 54
  • 63
  • I tried it, but it didn't help. Still the same issue. Something came to my mind during lunch: Is it possible, that something is wrong with the Faces Servlet? The page gets converted from JSF to HTML and is the displayed in the browser as expected. But no working functionality, at all. I have an AJAX call when I press a button and I catch the events with the `onevent`attribute. I get status `begin` `complete` and `success`. But no data is returned. And as I said, I don't see any sign of life from my Managed Bean. – Chiff Shinz Jan 25 '17 at 12:30
  • please add your web.xml and faces-config.xml. lets see what is going in there – Maciej Kowalski Jan 25 '17 at 12:32
  • 3
    This isn't an answer. Better post comments as comments instead of answers. – BalusC Jan 25 '17 at 13:55
0

Try using @javax.inject.Named instead of @ManagedBean.

Martín Straus
  • 558
  • 4
  • 7
  • I used faces-config.xml instead of annotations. Now everything works fine. – Chiff Shinz Jan 27 '17 at 10:35
  • That sound's rather unpleasant... Since you did this: "JSF 2.2 (provide libraries from app because of issues with Weblogic Server)", did you also modify weblogic-web-app.xml to declare application packages? – Martín Straus Feb 01 '17 at 17:27