2015-06-08 68 views
1

我用鑽嘴魚科2.1.29,有一個會話範圍的JSF託管bean重新創建會話範圍的JSF託管bean編程

@ManagedBean 
@SessionScoped 
public class UserContext{ 

    //staff 

} 

和一個Spring bean:

public class UserReproducer{ 
    private User user; 

    public void reporoduce(){ 
     if(user == null){ 
      //Here I need to recreate the userContext managed bean 
      //do some other staff 
     } 
    } 
} 

事實上,我需要JSF中的某種自定義作用域,即在條件滿足時重新創建userContext bean。有可能以某種方式做到嗎?通過重新創建,我的意思是清理所有屬性,因爲它是第一次創建。

回答

-1

無效會話,摧毀一個會話範圍的bean:

FacesContext.getCurrentInstance().getExternalContext().invalidateSession(); 

從春季安全註銷另一種選擇是疏通脈絡:

SecurityContextHolder.clearContext(); 
+0

我怎樣才能做到這一點? – user3663882

+0

會議是否與春季安全會議相關?我的意思是說同樣的事情? – user3663882

+0

SecurityContext對象保存在http會話中是。 – Stefan