JSF does not populate @Named @RequestScoped bean with submitted input values

你离开我真会死。 提交于 2019-11-27 05:30:54

From your bean:

import javax.faces.bean.RequestScoped;
import javax.inject.Named;

@Named("loginRequest")
@RequestScoped
public class LoginRequest {

You're mixing CDI and JSF annotations. You can and should not do that. Use the one or the other. I don't know what's the book is telling you, but most likely you have chosen the wrong autocomplete suggestion during the import of the @RequestScoped annotation. Please pay attention to if whatever the IDE suggests you matches whatever the book tells you.

So, you should be using either CDI annotations only

import javax.enterprise.context.RequestScoped;
import javax.inject.Named;

@Named("loginRequest")
@RequestScoped
public class LoginRequest {

or JSF annotations only

import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;

@ManagedBean(name="loginRequest")
@RequestScoped
public class LoginRequest {

Otherwise the scope defaults to "none" and every single EL expression referring the bean would create a brand new and separate instance of the bean. With three EL expressions referring to #{loginRequest} you would end up with 3 instances. One where name is been set, one where password is been set and one where action is been invoked.


Unrelated to the concrete problem, the managed bean name already defaults to the classname with 1st character lowercased conform Javabean specification. You could just omit the ("loginRequest") part altogether.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!