如何使用HTML标记作为直通元素而不是JSF标记?

时间:2016-07-18 20:17:29

标签: jsf passthrough-elements

我使用JSF 2.0和Apache Tomcat Server版本8.我有一个简单的JSF程序,由两个页面组成。在第一个用户输入他的名字并点击一个按钮,将用户带到第二页,显示" welcome"以及用户在第一页中输入的名称。这里的关键点是我尝试使用常规的html标签而不是JSF标签。所以,我正在使用:

<input type="text" id="myname" class="form-control" jsf:id="myname" jsf:value="#{testBean.name}">

而不是:

<h:inputText value="#{testBean.name}" />

但是,执行程序时,我在第二页中看到的唯一内容是&#34; welcome&#34;,该名称不会出现。

有没有人知道它为什么不起作用?我使用&#34; jsf:id和jsf:value&#34;正常?

代码如下:

<!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; }   
 }

0 个答案:

没有答案