JSF 2.0在bean(或页面?)之间传递数据 [英] JSF 2.0 pass data between beans (or pages?)

查看:147
本文介绍了JSF 2.0在bean(或页面?)之间传递数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用JSF 2.0

I'm working with JSF 2.0

我的管理部分中有一个表单,我将在列表中选择一些用户.

I have a form in my admin section where I am going to select some users in a list.

表单(selectusers.xhtml)将这些用户添加到Bean(SelectUsers.java)的列表中.

The form (selectusers.xhtml) is adding these users to a list in a bean (SelectUsers.java).

选择了一些用户之后,我会将用户列表从SelectUsers.java传递到另一个bean(AddAddressBean.java),并继续以另一种形式添加信息(addadress.xhtml),每个用户与AddAddressBean相关的其他属性.

After I have selected some user(s), I will pass the list of the user(s) from SelectUsers.java to another bean (AddAddressBean.java) and continue add information in another form (addadress.xhtml) which set other properties related to AddAddressBean for each user.

我不知道如何实现它.我希望AddAddressBean.java应该是独立的(因此我可以将其与其他bean一起使用),所以我更喜欢AddAddressBean.java将不了解其他bean.

I do not know how to implement it. I would like that AddAddressBean.java shall be independent (so I can use it together with other beans), so I prefer that AddAddressBean.java shall not know about other beans.

你能帮我吗? =)

B.R卡尔

推荐答案

想到了几项快速的事情:

Several quick things come to mind :

  1. 也许您可以使用@SessionScoped或更短的CDI的@ConversationScope为这些相关页面设置一个bean,或者这是三个最好的 @ViewAccessScoped
  2. 单击第1页上的带您进入第2页的按钮时,在第一个bean中,您可以使用Flash对象存储要传递的对象,在第二个bean的@PostConstruct方法中,您可以使用可以从Flash对象中获取所有对象
  3. 如果您不介意使用会话范围,则仍然可以拥有2个bean,并且一个bean可以使用
  1. Perhaps you could have a single bean only for those related pages, using @SessionScoped or the shorter CDI's @ConversationScope, or and this is the best of the three, the DeltaSpike @ViewAccessScoped
  2. When clicking the button on page 1 where it'll take you to page 2, in the 1st bean, you can make use of Flash object to store objects you want to pass, and in the second bean's @PostConstruct method, you could get all the objects from the Flash object
  3. If you dont mind using session scope, you can still have 2 beans, and one bean can refer to another bean using the jsf way(@ManagedProperty), or the Java EE inject way(@Inject) or the spring way if you use spring (@Autowired)

这篇关于JSF 2.0在bean(或页面?)之间传递数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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