Java 无法在JBOSS4.2上部署和运行JSF2.1.6示例
web.xml文件Java 无法在JBOSS4.2上部署和运行JSF2.1.6示例,java,jsf,jboss,Java,Jsf,Jboss,web.xml文件 <?xml version="1.0" encoding="UTF-8"?> <web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.co
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<!-- <context-param>
<description />
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Development</param-value>
</context-param>-->
<listener>
<listener-class>com.sun.faces.config.ConfigureListener</listener-class>
</listener>
<context-param>
<description/>
<param-name>javax.faces.CONFIG_FILES</param-name>
<param-value>/WEB-INF/faces-config.xml</param-value>
</context-param>
<context-param>
<param-name>com.sun.faces.enableRestoreView11Compatibility</param-name>
<param-value>true</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.PROJECT_STAGE</param-name>
<param-value>Development</param-value>
</context-param>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>addUser.jsp</welcome-file>
</welcome-file-list>
</web-app>
addUser.jsp
<%@taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
<%@taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
<html>
<head>
<title>Add New User Form</title>
</head>
<body>
<f:view>
<p>
<h:message id="errors" for="User_Id"></h:message>
</p>
<h:form>
<h:panelGrid border="1" columns="2">
<h:outputText value="ID"></h:outputText>
<h:inputText id="User_ID" value="#{userBean.id}" required="true">
<f:validateLongRange minimum="1" maximum="500"></f:validateLongRange>
</h:inputText>
<h:outputText value="Name"></h:outputText>
<h:inputText value="#{userBean.name}"></h:inputText>
<h:commandButton action="#{userBean.addUser}" value="Add Customer"> </h:commandButton>
</h:panelGrid>
</h:form>
</f:view>
</html>
<%@taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
<%@taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
<html>
<head>
<title>List of Users</title>
</head>
<body>
<f:view>
<h:form>
<h:outputText value="User #{userBean.name} is added succesfully"> </h:outputText>
</h:form>
</f:view>
</body>
</html>
添加新用户表单
ListUser.jsp
<%@taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
<%@taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
<html>
<head>
<title>Add New User Form</title>
</head>
<body>
<f:view>
<p>
<h:message id="errors" for="User_Id"></h:message>
</p>
<h:form>
<h:panelGrid border="1" columns="2">
<h:outputText value="ID"></h:outputText>
<h:inputText id="User_ID" value="#{userBean.id}" required="true">
<f:validateLongRange minimum="1" maximum="500"></f:validateLongRange>
</h:inputText>
<h:outputText value="Name"></h:outputText>
<h:inputText value="#{userBean.name}"></h:inputText>
<h:commandButton action="#{userBean.addUser}" value="Add Customer"> </h:commandButton>
</h:panelGrid>
</h:form>
</f:view>
</html>
<%@taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
<%@taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
<html>
<head>
<title>List of Users</title>
</head>
<body>
<f:view>
<h:form>
<h:outputText value="User #{userBean.name} is added succesfully"> </h:outputText>
</h:form>
</f:view>
</body>
</html>
用户名单
这是通过以下链接完成的示例
但是我无法在jboss上部署它。您使用的是JSF 2.1实现,但您已经将faces-config.xml文件配置为旧的JSF 1.2:
^这是主要问题
只需将faces-config.xml文件更新到JSF的正确版本:
或者更好的方法是,如果要使用任何特定的配置,比如注册一个阶段侦听器,只需删除它并添加它。您可以在此处找到此文件的更多用例:
除此之外,还有其他主要问题:
- JSF2.x至少需要Servlet2.5,它从JBoss5开始就可用。有关此主题的更多信息,请参阅
- 您所遵循的当前教程参考了JSF1.2,它非常古老。JSF2.0从2009年开始发布。我建议您不要再学习本教程,转而学习新的教程,比如
如果你真的想坚持使用JSF 1.2来满足遗留应用程序的维护等特定需求,那么就将JSF库从2.1替换为1.2。你说使用JSF 2.16(好吧,我们使用的是JSF 2.2.x版本,除非你来自未来)但是您的faces-config.xml文件与JSF1.2相关。您在服务器日志中得到了哪些错误?@luigimendoza我是说2.1。6@Jay-我在日志里什么也没看到