来自一个托管bean的属性作为空引用注入另一个托管bean

时间:2012-04-29 07:37:25

标签: java-ee-6 managed-bean

我有会话范围的LoginController bean:

@ManagedBean(name = "loginController")
@SessionScoped
public class LoginController implements Serializable {

private static final long serialVersionUID = 1L;
private String login;
private String password;
private UIComponent mybutton;
@EJB
private EmployeeEJB empejb;


public String validate() {

    AuthenticationResult res = getUsejb().FindUser(login, password);
    if (res == AuthenticationResult.SUCCESS) {
        return "mainpage?faces-redirect=true";
    } else {
        FacesMessage message = new FacesMessage();
        message.setDetail(res.getResult());
        FacesContext context = FacesContext.getCurrentInstance();
        context.addMessage(mybutton.getClientId(context), message);
        return "login";
    }


}


public String getLogin() {
    return login;
}

public void setLogin(String login) {
    this.login = login;
}

public String getPassword() {
    return password;
}

public void setPassword(String password) {
    this.password = password;
}

//etc.....
}

我想在请求作用域的TravelManagerCustomBeanbean中使用LoginController bean的属性:

@ManagedBean(name = "TMcustomBean")
@RequestScoped
public class TravelManagerCustomBean implements Serializable{

private List<CustomTrfBean> inProgressTRFs = new ArrayList();

@ManagedProperty(value = "#{loginController}")
private LoginController loginController;

@EJB
private TrfsEJB trfsejb;   

public TravelManagerCustomBean() {
}

@PostConstruct
public void init() {
    List<Trfs> inProcessTrfs = getTrfsejb().getReadyTrfs();
    List<Trfs> trfsFromCurrUserCountry = getTrfsejb().getTRFSFromCurrentUserCountry(loginController.getLogin(),loginController.getPassword());                   
    inProcessTrfs.addAll(trfsFromCurrUserCountry);
    //etc...
}

public List<CustomTrfBean> getInProgressTRFs() {
    return inProgressTRFs;
}

public TrfsEJB getTrfsejb() {
    return trfsejb;
}

public void setInProgressTRFs(List<CustomTrfBean> inProgressTRFs) {
    this.inProgressTRFs = inProgressTRFs;
}

public void setTrfsejb(TrfsEJB trfsejb) {
    this.trfsejb = trfsejb;
}     


public LoginController getLoginController() {
    return loginController;
}

public void setLoginController(LoginController loginController) {
    this.loginController = loginController;
}

}

我需要当前的用户密码并登录特定的数据库查询,但它们在此处作为空引用传递:

   List<Trfs> trfsFromCurrUserCountry = getTrfsejb().getTRFSFromCurrentUserCountry(loginController.getLogin(),loginController.getPassword());   

我认为这是LoginController bean注入的一些错误......

0 个答案:

没有答案