2014-04-13 27 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)。它包含一些额外的信息。 –