JSF 2.0 : managed bean x does not exist, Check that appropriate getter and/or setter methods exist

Problem

In JSF 2.0, while using the @ManagedProperty annotation to DI the bean into the field of another bean,

HelloBean.java

@ManagedBean
@SessionScoped
public class HelloBean implements Serializable {
 
	@ManagedProperty(value="#{message}")
	private MessageBean messageBean;

MessageBean.java

@ManagedBean(name="message")
@SessionScoped
public class MessageBean implements Serializable {

It hits the following error message.

An Error Occurred:
Unable to create managed bean helloBean. The following problems were found: – Property messageBean for managed bean helloBean does not exist. Check that appropriate getter and/or setter methods exist.

Solution

To inject the “messageBean” into the field of “helloBean”, the messageBean setter method must be supply.

HelloBean.java

@ManagedBean
@SessionScoped
public class HelloBean implements Serializable {
 
	@ManagedProperty(value="#{message}")
	private MessageBean messageBean;
 
	public void setMessageBean(MessageBean messageBean) {
		this.messageBean = messageBean;
	}

Done, the error message should be gone.

Tags :

About the Author

mkyong
Founder of Mkyong.com and HostingCompass.com, love Java and open source stuff. Follow him on Twitter, or befriend him on Facebook or Google Plus. If you like my tutorials, consider make a donation to these charities.

Comments