java - Unable to deploy and run JSF2.1.6 example on JBOSS4.2 -
web.xml file
<?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> faces-config.xml
<?xml version="1.0" encoding="utf-8"?> <faces-config 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-facesconfig_1_2.xsd" version="1.2"> <managed-bean> <managed-bean-name>userbean</managed-bean-name> <managed-bean-class>com.test.userbean </managed-bean-class> <managed-bean-scope>session</managed-bean-scope> </managed-bean> <navigation-rule> <display-name>adduser</display-name> <from-view-id>/adduser.jsp</from-view-id> <navigation-case> <from-outcome>success</from-outcome> <to-view-id>/listuser.jsp</to-view-id> </navigation-case> </navigation-rule> </faces-config> userbean class
package com.test; public class userbean{ private int id; private string name; //action method add user public string adduser() { return "success"; } public int getid() { return id; } public void setid(int id) { this.id = id; } public string getname() { return name; } public void setname(string name) { this.name = name; } } 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> 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>list of users</title> </head> <body> <f:view> <h:form> <h:outputtext value="user #{userbean.name} added succesfully"> </h:outputtext> </h:form> </f:view> </body> </html> this example done follwoing link
but how unable deploy on jboss.
you're using jsf 2.1 implementation have configured faces-config.xml file old jsf 1.2:
<faces-config 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-facesconfig_1_2.xsd" version="1.2"> ^here's main problem just update faces-config.xml file right version of jsf:
<faces-config 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-facesconfig_2_0.xsd" version="2.0"> or better, remove , add only if you're going use specific configuration registering phase listener. can find more use cases file here: what use of faces-config.xml in jsf 2?.
apart of this, there other main issues:
- jsf 2.x requires @ least servlet 2.5, available since jboss 5. refer stackoverflow jsf wiki more info on topic.
- the current tutorial you're following refers jsf 1.2, pretty old. jsf 2.0 has been released since 2009. recommend stop following tutorial , move newer 1 mkyong's tutorial on jsf 2.
if want stick jsf 1.2 specific requirements maintenance of legacy applications, replace jsf libraries 2.1 1.2.
Comments
Post a Comment