File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSF and the fly likes Passing object from JSF to MB Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "Passing object from JSF to MB" Watch "Passing object from JSF to MB" New topic
Author

Passing object from JSF to MB

Erick Barreto
Greenhorn

Joined: Aug 04, 2012
Posts: 2
Hello guys.

Well, after struggling a lot against this issue i'm here to ask for some advice.

I have one flash scopped objet that i need to pass to my MB which is view scopped. The problem is how i am going to do that.

First i tried f:param then i realized it is only used for primitive types and Strings basically. Then i tried <f:setPropertyActionListener> but i keep getting null on the MB.

This is how i used it. I was supposed to get 'myObject' set in the submit method.




The only alternative i have now is to use tomahawk <t:saveState> to do that. But i would like to ask you guys if the second alternative can be done with JSF 2 + primefaces with a flash scopped object, or the f:setPropertyActionListener only accepts primitive types like f:param?

Thanks in advance.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15641
    
  15

Welcome to the JavaRanch, Erick!

Go light on the acronyms. I had to do some head-scratching before I realized that "MB" probably meant Managed Bean.

In most cases the recommended way to get a bean accessed by another bean is to inject it as a Managed Property. Flash Scope, however, is so transient that I don't think you'll be allowed to do that, however. I haven't done one recently, but it seems like I recall that for Flash Scope, the target object had to request the source object explicitly. I'd have to RTFM (acronym! ) to be sure, though.

A corollary to this constraint is that the logic that obtains the Flash-scoped information must be located in a method that isn't part of the ongoing postback conversation, since after the handoff occurs, the Flash-scope object is effectively destroyed.


Customer surveys are for companies who didn't pay proper attention to begin with.
Erick Barreto
Greenhorn

Joined: Aug 04, 2012
Posts: 2
Tim Holloway wrote:Welcome to the JavaRanch, Erick!

Go light on the acronyms. I had to do some head-scratching before I realized that "MB" probably meant Managed Bean.

In most cases the recommended way to get a bean accessed by another bean is to inject it as a Managed Property. Flash Scope, however, is so transient that I don't think you'll be allowed to do that, however. I haven't done one recently, but it seems like I recall that for Flash Scope, the target object had to request the source object explicitly. I'd have to RTFM (acronym! ) to be sure, though.

A corollary to this constraint is that the logic that obtains the Flash-scoped information must be located in a method that isn't part of the ongoing postback conversation, since after the handoff occurs, the Flash-scope object is effectively destroyed.


Hello Tim, thanks for the reply.

I'm currently using flash scope to pass one parameter to another bean. I had to put an annotated method on the second bean with @PostConstruction and inside this method i get my object that i've set on the first bean (ELFlash.getFlash().put("key", value)) . I'm a little concerned about flash scope because, as you said, it seems to be transient and i noticed that using ajax it gets clean when i don't want to. Since i'm using @ViewScopped beans i don't think i can use @ManagedProperty, or it isn't true ?

I'll look further into this.

Thanks,
Erick

Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15641
    
  15

Like I said before, I'm too lazy to look it up, but I believe that that Flash-scoped objects are too transitory to inject into any scope and must be located the hard way.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Passing object from JSF to MB
 
Similar Threads
f:param in h:outputFormat interpreting not-null value as null?
Data confusion in dialog after validation
Getting Selection from selectOneMenu
Problem of maintaining reference of an object by the request of same jsf page
How to pass dynamic value to resource bundle param like {0}