我有ManagedBean用于应用程序登录,它是SessionScoped。
@ManagedBean(name="loginBean")
@SessionScoped
public class LoginBean implements Serializable {
private static final long serialVersionUID = 7765876815540798583L;
private String username;
private String password;
...
// getters and setters
有一个FileUploadController
,这可以正常工作,包括loginBean
注入:
@ManagedBean(name="fileUploadController")
public class FileUploadController implements Serializable {
private static final long serialVersionUID = 7765485215540798583L;
@ManagedProperty(value="#{loginBean}")
private LoginBean loginBean;
// getters and setters
但我有另一个bean的问题,类似于这个。它被称为FileDownloadController
package com.simulacije.csis.beans;
import java.io.InputStream;
import java.io.Serializable;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.RequestScoped;
import javax.faces.context.FacesContext;
import javax.servlet.ServletContext;
import org.primefaces.model.DefaultStreamedContent;
import org.primefaces.model.StreamedContent;
@ManagedBean(name="fileDownloadController")
@RequestScoped
public class FileDownloadController implements Serializable {
private static final long serialVersionUID = 7765876811740798583L;
private StreamedContent file;
@ManagedProperty(value="#{loginBean}")
private LoginBean loginBean;
public FileDownloadController() {
// File download logic
}
public StreamedContent getFile() {
return file;
}
public LoginBean getLoginBean() {
return loginBean;
}
public void setLoginBean(LoginBean loginBean) {
this.loginBean = loginBean;
}
}
它会不断触发loginBean
的空例外。否则,如果我删除loginBean,下载工作正常,但我需要使其工作。
我错过了什么吗?
谢谢!