开发者

JSF 2.0 pass data between beans (or pages?)

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.

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

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.

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 kno开发者_C百科w about other beans.

Can you please help me? =)

B.R Carl


Several quick things come to mind :

  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)


This how i implemented (used ConversationScoped as @bertie said ).

bean 1:

@Named("conversationBean1")
@ConversationScoped
public class ConversationBean1 implements Serializable {
          //---start conversation----

  }

bean 2:

@Named("conversationBean2")
@ConversationScoped
public class ConversationBean2 implements Serializable 
  {
      @Inject
      private ConversationBean1 conversationBean1;
   }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜