通过定义托管属性将一个托管bean注入另一个托管bean时遇到了一些麻烦。但是该属性为空。谁能告诉我,为什么我的财产是空的?用户登录Bean.java
@RequestScoped
public class UserLoginBean extends AbstractMB implements Serializable{
private static final long serialVersionUID = 1L;
private String username;
private String password;
//getter and setter
public void login() throws ServletException, IOException{
try
{
ExternalContext context = FacesContext.getCurrentInstance().getExternalContext();
HttpServletRequest request = ((HttpServletRequest)context.getRequest());
ServletResponse resposnse = ((ServletResponse)context.getResponse());
RequestDispatcher dispatcher = request.getRequestDispatcher("/j_spring_security_check");
dispatcher.forward(request, resposnse);
FacesContext.getCurrentInstance().responseComplete();
}
catch (Exception ex) {
ex.printStackTrace();
displayErrorMessageToUser("Login or Password Failed");
}
回收MB.java
@RequestScoped
public class ReclamationMB extends AbstractMB implements Serializable {
...
@ManagedProperty("#{loginBean}")
private UserLoginBean userLogin;
/getter and setter
但在 .xhtml 中它不为空,它返回用户名:
<h:outputText value="#{loginBean.username}