1

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 to 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} is added succesfully"> </h:outputText>
      </h:form>

      </f:view>
      </body>
      </html>

This is the example done from follwoing link

http://viralpatel.net/blogs/tutorial-creating-javaserver-faces-jsf-application-in-eclipse-jsf-project-jsf-tutorial/

But some how i am unable to deploy it on jboss.

tom
  • 5,114
  • 6
  • 24
  • 36

1 Answers1

0

You're using JSF 2.1 implementation but you have configured your faces-config.xml file to 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 the main problem

Just update your faces-config.xml file to the 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 even better, just remove it and add it only if you're going to use any specific configuration like registering a phase listener. You can find more use cases for this file here: What is the use of faces-config.xml in JSF 2?.

Apart of this, there are other main issues:

  • JSF 2.x requires at least Servlet 2.5, which is available since JBoss 5. Refer to StackOverflow JSF wiki for more info on this topic.
  • The current tutorial you're following refers to JSF 1.2, which is pretty old. JSF 2.0 has been released since 2009. I would recommend stop following this tutorial and move to a newer one like mkyong's tutorial on JSF 2.

If you really want to stick to JSF 1.2 for specific requirements like maintenance of legacy applications, then replace the JSF libraries from 2.1 to 1.2.

Community
  • 1
  • 1
Luiggi Mendoza
  • 85,076
  • 16
  • 154
  • 332