2

I store a file into this bean via primefaces fileUpload

@ManagedBean(name = "uploadController")
class UploadController{

private UploadedFile uploadedFile;

public void handleFileUpload(FileUploadEvent event) {
    setUploadedFile(event.getFile());
} 
//getter&setter

Is it possible to access to the field uploadedFile into another bean such as

@SessionScoped
public class BrandController implements Serializable {


private UploadedFile logo;
//getter&setter

and link them in a certain way? I tried this :

@ManagedProperty(value = "#{uploadController.uploadedFile}")
private UploadedFile logo;

But debugging shows that logo is null when I attempt to use methods on it. Thanks for your help.

2 Answers2

0

I think I was using wrong the ManagedProperty.

@ManagedBean(name = "uploadController")
public class UploadController {

@ManagedProperty(value = "#{brandController}")
private BrandController brandController;

public void handleFileUpload(FileUploadEvent event) {
    brandController.setLogo(event.getFile());
}
0

You should read this awesome answer about jsf scopes.

How to choose the right bean scope?

Session and Application scopes allows you to use beans beyond the interaction of the jsf page associated with it, however this could cause you encountered this bean in other places in "unespected" state.

For what has been said previously, for this purposes i used the flash scope, witch is a short living scope, how does it explain in above StackOverflow link as well as in the following:

Pass an object between @ViewScoped beans without using GET params

alvarez
  • 456
  • 3
  • 9