0
私はセッションスコープのマネージドBeanを 'usermanager'という名前で持っています。私はusermanager beanのプロパティに新たにログインしたユーザ情報を保存し、下記の静的metodを使ってアクセスしたい。私はこれらの質問、事前に感謝し、貧しい英語のために申し訳ありません。jsfにログインするには
1-AマネージドBeanを管理します。新しいUserManager()を使用してインスタンスを作成すると、これはマネージドBeanにはなりません。
2 - どのような条件で、以下のコード内のusermanagerはnullでもかまいません。
3 - Javaでユーザ、グループ権限を処理する最も効率的な方法は何ですか?私はこの目的のためにSpring、Seamを使用します。
4 - setParamater(key、Object)を使用してこのユーザー情報をHttpsessionに格納するか、セッションBeanに格納し続ける必要があります。
public static User getUserOfCurrentSession(){
UserManager userManager = (UserManager) ((HttpServletRequest)FacesContext.getCurrentInstance()
.getExternalContext().getRequest()).getSession(true)
.getAttribute("userManager");
if(userManager!=null){
return userManager.getUser();
}
FacesContext c = FacesContext.getCurrentInstance();
HttpServletRequest r = (HttpServletRequest) c.getExternalContext()
.getRequest();
HttpSession s = r.getSession(false);
if(s!=null)
s.invalidate();
try{
FacesContext.getCurrentInstance().getExternalContext().redirect("login.xhtml");
FacesContext.getCurrentInstance().responseComplete();
return null;
}catch(IOException e){
e.printStackTrace();
}
throw new RuntimeException("Un authonticated user action");
}
サーブレットAPIをJSFで取得することは、「コードの匂い」の強い指標です。この特殊なケースでも同様です。マネージドプロパティインジェクションについて学んでください。 – BalusC