2014-04-13 31 views
0

下頁是我的流量範圍內的最後一頁:如何通過值出臉部的流動範圍,請求範圍的bean

<html xmlns="http://www.w3.org/1999/xhtml" 
     xmlns:f="http://xmlns.jcp.org/jsf/core" 
     xmlns:h="http://xmlns.jcp.org/jsf/html"> 
<head> 
    <title>Last page in the flow</title> 
</head> 
<body> 
<h1>Registration completed!</h1> 
<p>value: #{flowScope.name}</p> 
<p>value: #{flowScope.surname}</p> 
<h:form prependId="false"> 
    <p><h:commandButton id="back" value="back" action="signup2" /></p> 
    <p><h:commandButton id="home" value="home" action="homePage"> 
     <f:setPropertyActionListener value="#{flowScope.name}" 
            target="#{mainController.name}"/> 
    </h:commandButton></p> 
</h:form> 
</body> 
</html> 

我想的名字傳遞給我的mainController。這隻適用於mainController是否是會話作用域,但如果它是請求作用域,則不適用?爲什麼?

問候 羅傑

回答

0

它簡單

@RequestScoped - 豆只要住作爲HTTP請求 - 響應的生活。它根據HTTP請求創建,並在與HTTP請求關聯的HTTP響應完成時被銷燬。

在你的情況下,你需要更長的範圍:@ViewScoped(如果它在同一頁面上),@SessionScoped或@ApplicationScoped用於顯示前一頁的數據。

根據定義,@RequestScopedmainController中的數據被存儲,之後util實現完成並銷燬。

+0

但是,如果我在流程之外這樣做,我不明白爲什麼流量會改變這種行爲。 – rogergl

+0

請參閱[本答案](http://stackoverflow.com/questions/19322364/what-is-the-default-managed-bean-scope-in​​-a-jsf-2-application-in-netbeans)。它包含一些額外的信息。 –