2

セッション スコープに応じて、ViewPreparer を使用してレイアウト メニューを変更したいと考えています。セッション スコープにアクセスする方法がわかりません。ビュー プリペアラー内で、次のようなメソッドを実装します。

public void execute(Request tilesContext, AttributeContext attributeContext)

セッションにアクセスしようとして多くの時間を費やしましたが、成功しませんでした。私がアクセスできたセッション関連のものは だけですtilesContext.getAvailableScopes()。どんな助けでも感謝します。

4

2 に答える 2

4

これを試してください:

public void execute(Request tilesContext, AttributeContext attributeContext){

HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();

HttpSession session = request.getSession();

// your code here
}
于 2013-03-28T14:06:42.990 に答える
0
public void execute(Request tilesContext, AttributeContext attributeContext){

    Map<String, Object> request = tilesRequest.getContext("request");

    request.get("{attributeName}"); // this will return your object in request

}

セッション属性を取得したい場合は、リクエストをセッションに変更できます。

于 2014-07-08T05:27:53.790 に答える