[英]FacesContext.getCurrentInstance().getExternalContext().redirect does not redirect immediately
[英]Difference between @ManagedProperty and FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get(“bean”)
之間有什么區別:
public class GameController implements Serializable{
@ManagedProperty(value="#{Gamebean}")
private Game game;
和
public class GameController implements Serializable{
private Game game;
public GameController(){
game =(Game)FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get("Gamebean");
}
如果沒有區別,哪種方法更好? 干杯。
如果@ManagedProperty
方法尚不存在,它將自動創建bean。 如果沒有(自動)創建bean,則getSessionMap()
不會,因此可能返回null
。
用最少的精力和精力就能達到相同目的的代碼更好。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.