JSF 2.0 @ManagedProperty returns null

I have some problems introducing one managed property into another by defining a managed property. But the property is null. can anyone tell me why my property is zero? UserLoginBean.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"); } 

ReclamationMB.java

 @RequestScoped public class ReclamationMB extends AbstractMB implements Serializable { ... @ManagedProperty("#{loginBean}") private UserLoginBean userLogin; /getter and setter 

But in .xhtml it is not null, it returns the username:

 <h:outputText value="#{loginBean.username} 
+4
source share
1 answer

Is userLogin in ReclamationMB null or is null username? If userLogin is not null, the injection works fine, but the bean is re-created, just like Requestscoped. You can put the UserLoginBean in the Viewscope to prevent the bean from being recreated:

 @ViewScoped public class UserLoginBean extends AbstractMB implements Serializable{...} 

Or you can fill in the data that is required for userLogin manually in ReclamationsMB by providing the PostConstruct method

 @RequestScoped public class ReclamationMB extends AbstractMB implements Serializable { ... @ManagedProperty("#{loginBean}") private UserLoginBean userLogin; //getter and setter @PostConstruct public void init() { //Call Bean methods or set variables manually userLogin.setUsername(...); } 
0
source

Source: https://habr.com/ru/post/1482550/


All Articles