2013-10-09 46 views
1

我JSF2.0上項目的工作,我需要支持從以前的屏幕豆獲得價值我在下面保留價值

我的第一個屏幕解釋它

<html xmlns="http://www.w3.org/1999/xhtml" 
xmlns:h="http://java.sun.com/jsf/html" 
> 
<h:body> 
    <h:form> 
     <h:outputText value="LocationID" /> 
     <h:inputText value="#{getDetails.locationID}"/> 
     <h:commandButton value="Add OS" action="#{getDetails.addOSDetails}"/> 
    </h:form> 
</h:body> 
</html> 

當命令按鈕被調用

@ManagedBean(name="getDetails") 
@RequestScoped 
public class GetDetailsBean { 

private String locationID; 

public String getLocationID() { 
    return locationID; 
} 

public void setLocationID(String locationID) { 
    this.locationID = locationID; 
} 

public String addOSDetails(){ 
    return "/app_pages/addOS"; 
} 

} 

我的第二屏幕是addOS我支持bean是

<html xmlns="http://www.w3.org/1999/xhtml" 
xmlns:h="http://java.sun.com/jsf/html" 
> 
<h:body> 
    <h:form> 
     <h:outputText value="Enter Value" /> 
     <h:inputText value="#{addOS.addValue}"/> 
     <h:commandButton value="Add OS" action="#{addOS.save}"/> 
    </h:form> 
</h:body> 
</html> 

我想LocationID在第一屏幕中輸入在支持bean

@ManagedBean(name="addOS") 
@RequestScoped 
public class AddOS { 

private String addValue; 

public String getAddValue() { 
    return addValue; 
} 

public void setAddValue(String addValue) { 
    this.addValue = addValue; 
} 

public String save(){ 
    return "app_pages/success"; 
} 

}

我想DONOT值在session.Can被設置用於可用。

想法和幫助請

謝謝。

+0

如果你想在一個以上的視圖中使用一個屬性,那麼它應該存儲在SessionScope中 – yannicuLar

回答

0

如果你真的打算做向前,當你在你的問題呢,在第一頁的數據提交已經存在時,第二頁呈現:記得,前是一樣的HTTP請求中完成。因此,您最終需要的是保留後繼POST請求的值。你可以這樣做,例如,通過存儲的信息是在第二頁上的隱藏字段:

而這基本上它。

如果您打算做重定向,從而通過附加?faces-redirect=true到導航的情況下的結果,你需要存儲在EL閃光,信息能夠在recepient頁面檢索它:有兩個要求是完成。所以,你的第一個bean的操作方法更改爲以下:

public String action() { 
    ... 
    FacesContext.getCurrentInstance().getExternalContext().getFlash().put("locationID", locationID); 
    return "result?faces-redirect=true"; 
} 

這樣的recepient頁它會在閃圖可上,從而通過

#{flash.locationID} 

在EL範圍和

(String)FacesContext.getCurrentInstance().getExternalContext() 
        .getFlash().get("locationID"); 

Java代碼。

+0

好的,謝謝你讓我試試用flash – user2462959