2014-09-22 27 views
-1

我開始JSF 2,我創建了一個XHTML頁面是index.xhtml,該頁面有一個按鈕:瞭解JSF動作

<h:commandButton value="Submit" action="welcome" /> 

而且我創建了一個頁面welcome.xhtml

但是,當我查看index.xhtml的來源時,我沒有看到從index.xhtml文件到welcome.xhtml文件的任何「鏈接」,jsf如何從索引傳遞到歡迎頁面?

當我查看源代碼,源頁是:

<!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"><head></head><body lang="en"> 
<form id="j_idt5" name="j_idt5" method="post" action="/Test/index.xhtml" enctype="application/x-www-form-urlencoded"> 
<input type="hidden" name="j_idt5" value="j_idt5" /> 
<input type="submit" name="j_idt5:j_idt6" value="Submit" /><input type="hidden" name="javax.faces.ViewState" id="javax.faces.ViewState" value="-5517223312856481273:-1605099621977497303" autocomplete="off" /> 
</form></body> 
</html> 

我真的沒有看到一個「鏈接」或行動,「歡迎」,在隱藏字段,我看到ViewState但它自動生成和變化當我refesh頁面。我也沒有看到任何加載歡迎頁面的JavaScript代碼。

<h:link>運行後,我想,當第一次,jsf讀取index.xhtml並顯示它,提交後按,jsf讀取index.xhtml並獲取該按鈕的動作並顯示歡迎頁面。

+0

你看到一個''

和'',對不對?在深入研究JSF之前,最好學習一些[基本HTML](http://htmldog.com/guides/html/beginner/)。對於初學者來說:這種方法是不好的設計。相關閱讀:http://stackoverflow.com/questions/15521451/how-to-make-url-reflect-the-current-page-and-not-the-previous-one,http://stackoverflow.com/questions/ 4317684/when-should-i-use-houtputlink-instead-of-hcommandlink/and http://stackoverflow.com/questions/3909267/differences-between-action-and-actionlistener/ – BalusC 2014-09-22 08:06:25

回答

0

從Mkyong網站 - http://www.mkyong.com/jsf2/jsf-2-0-hello-world-example/

在JSF 1.x中,你不得不宣佈在「faces-config.xml中」的「導航規則」,告訴按鈕被點擊時顯示的頁面。在JSF 2.0中,您可以將頁面名稱直接放在按鈕的「action」屬性中。對於簡單的導航,這已經綽綽有餘了,但是對於複雜的導航,建議您仍然使用「faces-config.xml」中的「導航規則」。

我建議閱讀JSF 2一些教程或買書 - >Give me a JSF 2.0 tutorial