2012-07-12 106 views
0

嗨夥計們我在非常奇怪的問題。我已經創建了一個客戶端模板facelet和模板facelet.but當我運行我的網頁時,它不會插入定義的標記。我的意思是不working.Here是我的代碼
insert.xhtml: <ui:insert>標籤不工作在facelets

<html xmlns="http://www.w3.org/1999/xhtml" 
    xmlns:ui="http://java.sun.com/jsf/facelets"> 
<head> 
    <title>facelet example </title> 
</head> 
<body> 
    <ui:insert name="face1"> </ui:insert> 
    <ui:insert name="face2"> </ui:insert> 
    <ui:insert name="face3"> </ui:insert> 
    <ui:insert name="face4"> </ui:insert> 
</body> 
</html> 

compose.xhtml:

<!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:ui="http://java.sun.com/jsf/facelets" 
    xmlns:h="http://java.sun.com/jsf/html"> 
<body> 
    <ui:composition template="insert.xhtml"> 
    <ui:define name="face1"> 
    <center><h2>Facelet</h2></center> 
    <h3>Welcome to the Facelet world..........</h3> 
    </ui:define> 
    <ui:define name="face2">Enter UserID :<br/> 
    <h:inputText id="it" /><br/><br/> 
    </ui:define> 
    <ui:define name="face3">Enter Password :<br/> 
    <h:inputSecret id="is" /><br/><br/> 
    </ui:define> 
    <ui:define name="face4"> 
    <h:commandButton id="b" value="Submit" /> 
    </ui:define> 
    </ui:composition> 
</body> 
</html> 

但是當我使用insert.xhtml <include src="compose.xhtml">標籤則顯示了完整的facelet.But包括標籤只有工作,如果我這樣寫

<insert name="face1"> 
<include src="compose.xhtml"/> 
</insert> 

如果我刪除insert標記之前包括然後也包括不幹活就討厭從JSF 2.0這種奇怪的行爲facelets.Please幫我
感謝

回答

0

你要明白,在標籤的「模板」屬性是可選的,所以這意味着在你的code.As一個小錯誤,你知道的facelet將包括標記,以便

xmlns="http://www.w3.org/1999/xhtml" 
    xmlns:ui="http://java.sun.com/jsf/facelets" 
    xmlns:h="http://java.sun.com/jsf/html" 
之間只有部分的第一

這應該與組成不在HTML標記。
您的問題類似於this question。我希望這也能幫到你。
謝謝

-1

你應該用你的<ui:include />

<ui:composition template="/compose.xhtml"> 
    //your page 
    <ui:include name="face1" /> 
</ui:composition> 
+0

你能解釋一點點嗎?在哪個文件和哪裏?由於我是JSF的新手,所以無法理解您的答案...... – khan 2012-07-12 18:31:19

0

請嘗試關注本教程,如果您是JSF 2模板的新手,這將非常有幫助。 Here is the link

我認爲這個問題是您要使用的模板的路徑:

<ui:composition template="insert.xhtml"> 

應該是:

<ui:composition template="/insert.xhtml"> 

如果模板是在根文件夾中。