我正在使用:Wildfly 8.2,JSF 2.2(Mojarra 2.2.8),Omnifaces 2.1和java 7.
问题在于我创建了一些对象以及重新创建的每个请求(null)。 我也试过使用conversationScope,但同样的事情发生了。
使用sessionScope可以正常工作。
控制器:
@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;
}
}
每次回发passwordReminderUsers
为null
,导致NPE。
查看:
<h:form id="form-login" prependId="false">
<h:inputText value="#{teste.key}" />
<h:commandButton value="add" action="#{teste.add()}" />
</h:form>
我做了一些测试,没有使用primefaces,f:ajax,还有其他几个,没有任何作用。
此代码:JSF view scoped bean: #{authenticator}
显示重新创建bean的每个请求。
也许相关: 我们使用JSF 2.0并在几个月前更新到JSF 2.2。 我必须使用这些命名空间:
<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">
因为新的xmlns.jcp.org
不起作用并开始破坏页面而不渲染jsf组件。
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登录启动
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
答案 0 :(得分:2)
也许相关:我们使用JSF 2.0并在几个月前更新到JSF 2.2。我必须使用这些命名空间[snip]因为新的xmlns.jcp.org不起作用并开始破坏页面而不渲染jsf组件
这绝对是一个强有力的线索,你实际上没有使用JSF 2.2,但仍旧版本。如果在WildFly上运行时发生了这种情况,它应该已经提供了JSF 2.2,那么这意味着您的运行时类路径被多个不同的JSF版本污染,或者WildFly实例被修改。
它应该在库存和未修改的WildFly实例上正常工作。