I use JSF 2.0 and the Apache Tomcat Server version 8. I have a simple JSF program that consists of two pages. In the first one the user enters his name and click a button which takes the user to the second page which displays "welcome" and the name that user entered in the first page. The key point here is that I'm trying to use regular html tags instead of JSF tags. So, I'm using:
<input type="text" id="myname" class="form-control" jsf:id="myname" jsf:value="#{testBean.name}">
instead of:
<h:inputText value="#{testBean.name}" />
But, executing the program, the only thing I see in the second page is "welcome", the name does not appear.
Does anyone have an idea why it is not working? Did I use "jsf:id and jsf:value" properly?
The code is below:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:jsf="http://xmlns.jcp.org/jsf"
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:pe="http://primefaces.org/ui/extensions"
lang="en">
<h:head>
<meta charset="utf-8"></meta>
<meta http-equiv="X-UA-Compatible" content="IE=edge"></meta>
<meta name="viewport" content="width=device-width, initial-scale=1"></meta>
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<title> Faculty </title>
<title>Bootstrap 101 Template</title>
<link href="bootstrap/css/bootstrap.css" rel="stylesheet" type="text/css" />
<link href="arabicfonts/arabicfont.css" rel="stylesheet" type="text/css" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script type="text/javascript" src="bootstrap/js/bootstrap.js"></script>
</h:head>
<f:view>
<h:body>
<h:form>
<div class="container-fluid">
<div class="row">
<div class="col-md-4 col-md-offset-4">
<div class="panel panel-primary">
<div class="panel-heading text-center">
Updating Faculty
</div>
<div class="panel-body">
<div class="form-group">
<label for="myname" class="control-label"> My name is </label>
<div>
<input type="text" id="myname" class="form-control" jsf:id="myname" jsf:value="#{testBean.name}">
</input>
</div>
</div>
</div>
<div class="panel-footer">
<div class="text-center">
<h:commandButton class="btn btn-success" value="Do it" action="welcome"/>
</div>
</div>
</div>
</div>
</div>
</div>
</h:form>
</h:body>
</f:view>
</html>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html">
<h:head>
<title>Welcome</title>
</h:head>
<h:body>
<h3>Welcome #{testBean.name}</h3>
</h:body>
</html>
import java.io.Serializable;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
@ManagedBean(name="testBean")
@SessionScoped
public class TestBean implements Serializable
{
private String name;
public String getName() { return name; }
public void setName(String newValue) { name = newValue; }
}