jsf
JSF 2의 플래시 스코프
수색…
비고
Flash 개념은 Ruby on Rails에서 가져 와서 얼굴 라이프 사이클에 의해 생성 된 사용자보기간에 임시 객체를 전달하는 방법을 제공합니다. Rails와 마찬가지로 플래시의 한 위치는 동일한 사용자 세션에서 발생한 다음보기에 노출 된 다음 삭제됩니다. "다음보기"는 이전보기와 동일한보기 ID를 가질 수 있습니다.
JSF 구현은 <redirect /> 을 포함하는 <redirect /> <navigation-case> 의 경우에도 플래시의 적절한 동작을 유지해야합니다. 구현은 동일한 세션에서 인접한 GET 요청의 경우에도 플래시의 적절한 동작이 유지되도록해야합니다. 이를 통해 Faces 애플리케이션은 "Post / Redirect / Get"디자인 패턴을 완벽하게 활용할 수 있습니다.
Flash Scope 사용 데모
콩 1
@ManagedBean
@ViewScoped
public class Bean1 implements Serializable {
/**
* Just takes the given param, sets it into flash context and redirects to
* page2
*
* @param inputValue
* @return
*/
public String goPage2(String inputValue) {
FacesContext.getCurrentInstance().getExternalContext().getFlash()
.put("param", inputValue);
return "page2?faces-redirect=true";
}
}
page1.xhtml
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:c="http://java.sun.com/jsp/jstl/core">
<h:head />
<h:body>
<!-- Sets the first flash param at the action method -->
<h:form>
<h:inputText value="#{inputValue}" />
<h:commandButton action="#{bean1.goPage2(inputValue)}"
value="Go Page 2" />
</h:form>
<!-- Sets the second flash param -->
<c:set target="#{flash}" property="param2" value="Myparam2" />
<!-- Tries to retrieve both of the params.
Note none of them is displayed at the first page hit.
If page refreshed, the second param which has been already set, will be displayed -->
<p>Param1: #{flash['param']}</p>
<p>Param2: #{flash['param2']}</p>
</h:body>
</html>
콩 2
@ManagedBean
@ViewScoped
public class Bean2 implements Serializable {
public String getParam() {
/**
* Takes the parameter from the flash context
*/
return (String) FacesContext.getCurrentInstance().getExternalContext()
.getFlash().get("param");
}
}
page2.xhtml
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:f="http://java.sun.com/jsf/core">
<h:head />
<!-- This page just displays the received params -->
<h:body>
<!-- Different ways to retrieve the params from the flash scope -->
<p>Param1: #{bean2.param}</p>
<p>Param1: #{flash.param}</p>
<p>Param1: #{flash['param']}</p>
<p>Param2: #{flash['param2']}</p>
<!-- Keep the first param for next redirection -->
#{flash.keep.param}
<!-- Return to page1 and see how the first param is retained -->
<h:button outcome="page1?faces-redirect=true" value="return to 1" />
</h:body>
</html>
Modified text is an extract of the original Stack Overflow Documentation
아래 라이선스 CC BY-SA 3.0
와 제휴하지 않음 Stack Overflow