JSF 1.2中的会话处理 [英] session handling in JSF 1.2

查看:144
本文介绍了JSF 1.2中的会话处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们如何处理JSF 1.2中的会话变量(添加/获取)?

How do we handle session variables (add/fetch) in JSF 1.2?

方案:考虑用户成功登录的登录界面,用户模型存储在会话中。用户模式包含用户角色。下次,对于每个用户操作,检查用户模型中的用户角色并相应地显示表单。在这种情况下如何在会话中添加用户odel以及如何从会话中每次执行它?

A scenario: Consider a login screen where the user logs in successfully, the user model is stored in session. The user modes contains the user role. Next time onwards, for every user action, check the user role from the user model and display the form accordingly. In such a case how to add the user odel in session and how to etrieve it every time from the session?

之前我曾在Struts 1.2中工作过<$ p

c $ c>执行方法,我们有一个请求 e =用于获取会话并访问会话变量。但我不知道如何在JSF 1.2中实现相同目的。

Previously I have worked in Struts 1.2 where in the execute method, we have a request e=which is used to get the session and access the session variables also. But I am not sure how to achieve th same in JSF 1.2.

唯一可行的方法是在faces-config中的会话范围中添加托管bean。 xml文件?

Is the only way achieveable is to add the managed bean in the session scope in the faces-config.xml file?

请帮我解决JSF 1.2中的会话处理概念。

Please help me out with the session handling concepts in JSF 1.2.

推荐答案

会话范围以编程方式提供 ExternalContext#getSessionMap() ,它将封底委托给 HttpSession#get / setAttribute()

The session scope is programmatically available by ExternalContext#getSessionMap() which delegates under the covers to HttpSession#get/setAttribute().

Map<String, Object> sessionMap = FacesContext.getCurrentInstance().getExternalContext().getSessionMap();
// ...

您当然也可以将托管bean放入会话范围。可以通过< managed-property> 从其他托管bean访问它(或者只使用托管bean名称作为映射键遍历会话映射)。

You can of course also just put a managed bean in the session scope. It's accessible from other managed beans by <managed-property> (or just a traversal of the session map using the managed bean name as map key).

这篇关于JSF 1.2中的会话处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆