使用 JSF RequestScoped Bean 进行确认页面
我有一个 JSF 页面,它加载一个用户并允许我将角色分配给该特定用户。支持 Bean,AssignRolesBean
是 @RequestScoped
,我希望它保持这样。但是,这是我的问题...
当表单提交时,它会调用 AssignRolesBean.execute()
。然后,这将返回确认页面的路径。在此确认页面上,我想显示将分配哪些新角色以及将删除哪些角色。但是,我无法将用户加载到确认页面上。
在初始分配角色页面上,使用 GET 参数设置 userId。然后将其作为 h:inputHidden
元素添加到页面上。它确实被提交了。但是,同样,在下一页上,未设置 userId(这会加载用户)。有什么方法可以保留 RequestScope 而不必将 userId 存储在 SessionMap 中?有人告诉我,使用隐藏输入将允许您跨页面获取数据。但是,我遇到了麻烦。
I have a JSF page that loads a User and allows me to assign Roles to that particular User. The Backing Bean, AssignRolesBean
is @RequestScoped
, and I would like for it to remain so. However, here's my problem...
When the form submits, it calls AssignRolesBean.execute()
. This then returns the path to the confirmation page. On this confirmation page, I want to show what new roles will be assigned and which role will be removed. However, I'm having trouble getting the User loaded on the confirmation page.
On the initial AssignRoles page, the userId is set using a GET parameter. It is then added as an h:inputHidden
element on the page. It does get submitted. But, again, on the next page, the userId is not set (which loads the User). Is there any way I can keep the RequestScope and not have to store the userId in the SessionMap? I've been told that using hidden inputs will allow you to take data across pages. But, I'm having trouble with that.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果你开发jsf2应用程序,你可以使用flashscope来传递参数。
有关 flash 作用域的更多信息,您可以查看 学习 JSF2:使用Flash 范围
或者您可以将参数放入会话映射
代码片段中以获取会话映射:
if you develop jsf2 app, you can use flash scope to pass the parameters.
For more information about flash scope you can look at Learning JSF2: Using Flash scope
or you can put the parameters into session map
code snippet to get sessionMap:
GET 请求执行操作:
将以下内容添加到您的视图中以根据
Add the following to your view to execute an action upon a GET request:
with