2

I'm using: Wildfly 8.2, JSF 2.2 (Mojarra 2.2.8) , Omnifaces 2.1 and java 7.

The problem is that I've created some objects and every request they are recreated (null). I also tried using conversationScope but the same thing happens.

Using sessionScope it works.

Controller:

@Named
@ViewScoped
public class Teste implements Serializable {

    private static final long   serialVersionUID = 1L;
    private Map<String, String> passwordReminderUsers;
    private String              key;

    @PostConstruct
    public void init() {
        if (!FacesContext.getCurrentInstance().isPostback())
            passwordReminderUsers = new HashMap<String, String>();
    }

    public void add() {
        passwordReminderUsers.put(key, "b");
    }

    public String getKey() {
        return key;
    }

    public void setKey(String key) {
        this.key = key;
    }
}

The passwordReminderUsers is null on every postback, causing NPE.

View:

    <h:form id="form-login" prependId="false">

        <h:inputText value="#{teste.key}" />
        <h:commandButton value="add" action="#{teste.add()}" />
    </h:form>

I've made some tests doing the request without primefaces, with f:ajax, and several others, nothing works.

this code: JSF view scoped bean: #{authenticator} shows that every request the bean is recreated.

Maybe related: We were using the JSF 2.0 and updated some months ago to JSF 2.2. I have to use these namespaces:

<ui:composition xmlns="http://www.w3.org/1999/xhtml" 
    xmlns:ui="http://java.sun.com/jsf/facelets" 
    xmlns:f="http://java.sun.com/jsf/core" 
    xmlns:h="http://java.sun.com/jsf/html" 
    xmlns:p="http://primefaces.org/ui" 
    xmlns:c="http://java.sun.com/jsp/jstl/core" 
    xmlns:pe="http://primefaces.org/ui/extensions" 
    template="/WEB-INF/templates/default.xhtml">

Because the new xmlns.jcp.org ones didn't work and started to break the pages and not render jsf components.

MAVEN pom:

<properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <!-- maven-compiler-plugin -->
        <maven.compiler.target>1.7</maven.compiler.target>
        <maven.compiler.source>1.7</maven.compiler.source>
    </properties>

    <repositories>
        <repository>
            <id>jvnet-nexus-releases</id>
            <name>jvnet-nexus-releases</name>
            <url>http://maven.java.net/content/repositories/releases/</url>
        </repository>
        <repository>
            <id>jboss-public-repository-group</id>
            <name>JBoss Public Repository Group</name>
            <url>http://repository.jboss.org/nexus/content/groups/public/</url>
            <layout>default</layout>
            <releases>
                <enabled>true</enabled>
                <updatePolicy>never</updatePolicy>
            </releases>
            <snapshots>
                <enabled>true</enabled>
                <updatePolicy>never</updatePolicy>
            </snapshots>
        </repository>
        <repository>
            <id>prime-repo</id>
            <name>Prime Repo</name>
            <url>http://repository.primefaces.org</url>
        </repository>
    </repositories>

    <pluginRepositories>
        <pluginRepository>
            <id>jboss-public-repository-group</id>
            <name>JBoss Public Repository Group</name>
            <url>http://repository.jboss.org/nexus/content/groups/public/</url>
            <releases>
                <enabled>true</enabled>
            </releases>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </pluginRepository>
    </pluginRepositories>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.wildfly.bom</groupId>
                <artifactId>jboss-javaee-7.0-with-hibernate</artifactId>
                <version>8.2.0.Final</version>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <dependencies>
        <dependency>
            <groupId>javax</groupId>
            <artifactId>javaee-web-api</artifactId>
            <version>7.0</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.primefaces</groupId>
            <artifactId>primefaces</artifactId>
            <version>5.2</version>
        </dependency>
        <dependency>
            <groupId>commons-io</groupId>
            <artifactId>commons-io</artifactId>
            <version>1.3.2</version>
        </dependency>
        <dependency>
            <groupId>org.omnifaces</groupId>
            <artifactId>omnifaces</artifactId>
            <version>2.1</version>
        </dependency>
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.17</version>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>commons-logging</groupId>
            <artifactId>commons-logging</artifactId>
            <version>1.1.3</version>
        </dependency>

Wildfly log on start up

java.class.path = C:\wildfly-8.2.0.Final\jboss-modules.jar
    java.class.version = 51.0
    java.endorsed.dirs = C:\Program Files\Java\jre7\lib\endorsed
    java.ext.dirs = C:\Program Files\Java\jre7\lib\ext;C:\windows\Sun\Java\lib\ext
    java.home = C:\Program Files\Java\jre7
    java.io.tmpdir = C:\Users\VICTOR~1.BEL\AppData\Local\Temp\
    java.library.path = C:\Program Files\Java\jre7\bin;C:\windows\Sun\Java\bin;C:\windows\system32;C:\windows;native;C:\Program Files (x86)\Java\jre7\bin;C:\Program Files\Common Files\Microsoft Shared\Windows Live;C:\Program Files (x86)\Common Files\Microsoft Shared\Windows Live;C:\Program Files (x86)\Intel\iCLS Client\;C:\Program Files\Intel\iCLS Client\;C:\windows\system32;C:\windows;C:\windows\System32\Wbem;C:\windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\maven\apache-maven-3.2.1\bin;C:\Program Files (x86)\Microsoft SQL Server\110\Tools\Binn\;C:\Program Files\Microsoft SQL Server\110\Tools\Binn\;C:\Program Files\Microsoft SQL Server\110\DTS\Binn\;C:\Program Files (x86)\Microsoft SQL Server\110\Tools\Binn\ManagementStudio\;C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\PrivateAssemblies\;C:\Program Files (x86)\Microsoft SQL Server\110\DTS\Binn\;c:\Program Files (x86)\Microsoft SQL Server\100\Tools\Binn\;C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\110\Tools\Binn\;C:\Program Files (x86)\Microsoft SQL Server\120\Tools\Binn\;C:\Program Files\Microsoft SQL Server\120\Tools\Binn\;C:\Program Files\Microsoft SQL Server\120\DTS\Binn\;C:\Program Files (x86)\Microsoft SQL Server\120\Tools\Binn\ManagementStudio\;C:\Program Files (x86)\Microsoft SQL Server\120\DTS\Binn\;C:\Program Files (x86)\Java\jre7\bin;C:\Program Files\Common Files\Microsoft Shared\Windows Live;C:\Program Files (x86)\Common Files\Microsoft Shared\Windows Live;C:\Program Files (x86)\Intel\iCLS Client\;C:\Program Files\Intel\iCLS Client\;C:\windows\system32;C:\windows;C:\windows\System32\Wbem;C:\windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\maven\apache-maven-3.2.1\bin;C:\Program Files (x86)\Microsoft SQL Server\110\Tools\Binn\;C:\Program Files\Microsoft SQL Server\110\Tools\Binn\;C:\Program Files\Microsoft SQL Server\110\DTS\Binn\;C:\Program Files (x86)\Microsoft SQL Server\110\Tools\Binn\ManagementStudio\;C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\PrivateAssemblies\;C:\Program Files (x86)\Microsoft SQL Server\110\DTS\Binn\;c:\Program Files (x86)\Microsoft SQL Server\100\Tools\Binn\;c:\Program Files (x86)\Microsoft SQL Se;c:\cvs.exe;C:\Program Files (x86)\IDM Computer Solutions\UltraEdit\;.;;.;;.;;.
    java.net.preferIPv4Stack = true
    java.runtime.name = Java(TM) SE Runtime Environment
    java.runtime.version = 1.7.0_51-b13
    java.specification.name = Java Platform API Specification
    java.specification.vendor = Oracle Corporation
    java.specification.version = 1.7
    java.util.logging.manager = org.jboss.logmanager.LogManager
    java.vendor = Oracle Corporation
    java.vendor.url = http://java.oracle.com/
    java.vendor.url.bug = http://bugreport.sun.com/bugreport/
    java.version = 1.7.0_51
    java.vm.info = mixed mode
    java.vm.name = Java HotSpot(TM) 64-Bit Server VM
    java.vm.specification.name = Java Virtual Machine Specification
    java.vm.specification.vendor = Oracle Corporation
    java.vm.specification.version = 1.7
    java.vm.vendor = Oracle Corporation
    java.vm.version = 24.51-b03
    javax.management.builder.initial = org.jboss.as.jmx.PluggableMBeanServerBuilder
    javax.xml.datatype.DatatypeFactory = __redirected.__DatatypeFactory
    javax.xml.parsers.DocumentBuilderFactory = __redirected.__DocumentBuilderFactory
    javax.xml.parsers.SAXParserFactory = __redirected.__SAXParserFactory
    javax.xml.stream.XMLEventFactory = __redirected.__XMLEventFactory
    javax.xml.stream.XMLInputFactory = __redirected.__XMLInputFactory
    javax.xml.stream.XMLOutputFactory = __redirected.__XMLOutputFactory
    javax.xml.transform.TransformerFactory = __redirected.__TransformerFactory
    javax.xml.validation.SchemaFactory:http://www.w3.org/2001/XMLSchema = __redirected.__SchemaFactory
    javax.xml.xpath.XPathFactory:http://java.sun.com/jaxp/xpath/dom = __redirected.__XPathFactory
    jboss.bind.address = localhost
    jboss.bind.address.management = localhost
    jboss.home.dir = C:\wildfly-8.2.0.Final
    jboss.host.name = wvox-000805
    jboss.modules.dir = C:\wildfly-8.2.0.Final\modules
    jboss.modules.system.pkgs = org.jboss.byteman
    jboss.node.name = wvox-000805
    jboss.qualified.host.name = wvox-000805
    jboss.server.base.dir = C:\wildfly-8.2.0.Final\standalone
    jboss.server.config.dir = C:\wildfly-8.2.0.Final\standalone\configuration
    jboss.server.data.dir = C:\wildfly-8.2.0.Final\standalone\data
    jboss.server.deploy.dir = C:\wildfly-8.2.0.Final\standalone\data\content
    jboss.server.log.dir = C:\wildfly-8.2.0.Final\standalone\log
    jboss.server.name = wvox-000805
    jboss.server.persist.config = true
    jboss.server.temp.dir = C:\wildfly-8.2.0.Final\standalone\tmp
    line.separator = 

    logging.configuration = file:/C:/wildfly-8.2.0.Final/standalone/configuration/logging.properties
    module.path = C:/wildfly-8.2.0.Final/modules
    org.jboss.boot.log.file = C:/wildfly-8.2.0.Final/standalone/log/boot.log
    org.jboss.logmanager.nocolor = true
    org.jboss.resolver.warning = true
    org.xml.sax.driver = __redirected.__XMLReaderFactory
    os.arch = amd64
    os.name = Windows 7
    os.version = 6.1
    path.separator = ;
    program.name = JBossTools: WildFly 8.x
    sun.arch.data.model = 64
    sun.boot.class.path = C:\Program Files\Java\jre7\lib\resources.jar;C:\Program Files\Java\jre7\lib\rt.jar;C:\Program Files\Java\jre7\lib\sunrsasign.jar;C:\Program Files\Java\jre7\lib\jsse.jar;C:\Program Files\Java\jre7\lib\jce.jar;C:\Program Files\Java\jre7\lib\charsets.jar;C:\Program Files\Java\jre7\lib\jfr.jar;C:\Program Files\Java\jre7\classes
    sun.boot.library.path = C:\Program Files\Java\jre7\bin
    sun.cpu.endian = little
    sun.cpu.isalist = amd64
    sun.desktop = windows
    sun.io.unicode.encoding = UnicodeLittle
    sun.java.command = org.jboss.modules.Main -mp C:/wildfly-8.2.0.Final/modules -jaxpmodule javax.xml.jaxp-provider org.jboss.as.standalone -b localhost --server-config=standalone.xml -Djboss.server.base.dir=C:\wildfly-8.2.0.Final\standalone
    sun.java.launcher = SUN_STANDARD
    sun.jnu.encoding = Cp1252
    sun.management.compiler = HotSpot 64-Bit Tiered Compilers
    sun.os.patch.level = Service Pack 1
    sun.rmi.dgc.client.gcInterval = 3600000
    sun.rmi.dgc.server.gcInterval = 3600000
    user.country = US
    user.country.format = BR
    user.dir = C:\wildfly-8.2.0.Final\bin
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Victor Bello
  • 493
  • 1
  • 8
  • 23
  • To exclude one and other, please share HTTP request/response headers and form data of the initial request and the subsequent postback request. – BalusC Sep 01 '15 at 15:20
  • @BalusC I don't get it. I'm instantiating a Map inside the method '@postConstruct'. There is no non-null outcome. Just creating the bean. On the next request, the object is already null (it's before return anything). Am I missing something? – Victor Bello Sep 01 '15 at 16:12
  • @BalusC Edited. Still happen. After postConstruct, when the button is called I got null pointer, where it should'nt happen because I created the instance. – Victor Bello Sep 01 '15 at 16:32
  • Okay. Thanks. I gather that `JSESSIONID` cookie header and `javax.faces.ViewState` request parameter have the same value on every postback. So this can be excluded from being the cause. I reduced the noise in the question. That the `xmlns.jcp.org` XML namespace didn't work is definitely a clue. Do you have any JavaEE/JSF JARs in `/WEB-INF/lib`? A library version conflict in the classpath is recipe for weird side effects, although I haven't seen this one before. – BalusC Sep 01 '15 at 16:37
  • @BalusC I'm using maven, i added the pom code on my last edit. Like I said, this problem started after update from jsf 2.0 to 2.2, maybe the pom has something wrong. – Victor Bello Sep 01 '15 at 16:42
  • @BalusC I haven't tried javax.faces.view.ViewScoped. I tried it now. Didn't work, nor the import. – Victor Bello Sep 01 '15 at 16:57
  • @BalusC That was exactly what I've tried. – Victor Bello Sep 01 '15 at 17:25
  • Ok, `@Named @org.omnifaces.cdi.ViewScoped`, `@Named @javax.faces.view.ViewScoped` and `@ManagedBean @javax.faces.bean.ViewScoped` all behave like request scoped? I.e. the `@PostConstruct` is invoked on every postback and the bean instance is different every time? That's definitely weird. Being unable to use `xmlns.jcp.org` namespace domain is still a strong hint for runtime classpath pollution. What JSF version is logged in webapp startup log? If you let Maven produce a WAR file, and inspect it using a ZIP tool, do you see anything abnormal in `/WEB-INF/lib` folder? – BalusC Sep 01 '15 at 17:29
  • @BalusC the only reference to mojarra: Initializing Mojarra 2.1.7-jbossorg-1 (20120227-1401) for context. I generate the war file and to be honest, I don't know where the mojarra is. There are omnifaces, jboss, hibernate lib, but nothing about mojarra – Victor Bello Sep 01 '15 at 17:51
  • 2
    2.1.7-jbossorg is recognizable as the Mojarra version bundled in JBoss AS 7.1 or EAP 6.0. It's definitely not JSF 2.2. Are you sure you're deploying to WildFly 8.2? Is it a local or remote server? – BalusC Sep 01 '15 at 18:21
  • I'm, @BalusC. Edited.It's local. – Victor Bello Sep 01 '15 at 18:23
  • Okay, you mentioned there are "jboss" libs in `/WEB-INF/lib`. Which JARs exactly? Regardless, this is in first place not right. So I suspect Maven did something wrong there. But I'm not terribly into Maven, so I can't pinpoint the exact cause. At least, I'd try removing the JBoss plugin repositories and the WildFly BOM. In the most minimal working POM I've here ([from OmniFaces showcase](https://github.com/omnifaces/showcase/blob/master/pom.xml), flawlessly running on WildFly), they are absent. – BalusC Sep 01 '15 at 18:29
  • These are jboss libs: jboss-logging-3.1.3.GA.jar, jboss-logging-annotations-1.2.0.Beta1.jar, jboss-transaction-api_1.2_spec-1.0.0.Final.jar. I'll try your advice and then I return. – Victor Bello Sep 01 '15 at 18:44
  • @BalusC removing this, stopped work the application. Anyway, I think I found the problem, just don't know yet how to solve. Inside the wildfly is the lib jsf-impl-2.1.7-jbossorg-2.jar. This is where the wildfly is taking the jsf implementation. I think I have to "override" using maven (that's why there is no jsf impl on .war archive). I just don't know how to do this with maven. – Victor Bello Sep 02 '15 at 11:55
  • Is this a stock or customized WildFly? This isn't normal. – BalusC Sep 02 '15 at 12:01
  • To be honest, I don't remember to change this, I'm almost sure that I haven't. I just downloaded and use it. I downloaded again the version 8.2 final and it has the version 2.2.8. I'll try now. – Victor Bello Sep 02 '15 at 12:07
  • IT WORKED! :D. Thank you so much for you time and attention, @Balusc. It really helped me to have a north. – Victor Bello Sep 02 '15 at 12:21

1 Answers1

2

Maybe related: We were using the JSF 2.0 and updated some months ago to JSF 2.2. I have to use these namespaces [snip] Because the new xmlns.jcp.org ones didn't work and started to break the pages and not render jsf components

This is definitely a strong clue that you are actually not using JSF 2.2, but still an older version. If that happened while running on WildFly, which is supposed to already provide JSF 2.2 out the box, then this means that your runtime classpath is polluted with multiple different JSF versions, or that the WildFly instance is modified.

It should work fine on a stock and unmodified WildFly instance.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555