Sunday, October 11, 2009

Accessing JSF Backing Beans From Another JSF Backing Bean

Here is a simple piece of code that lets you access a backing bean from another backing bean. i.e. in the java code of a backing bean in JSF 1.1. A backing bean that exists in the session cannot be directly accessed from the map containing the other session objects. So here is a small workaround.

FacesContext context=FacesContext.getCurrentInstance();
Object obj=context.getApplication().createValueBinding("#{"+ "visit" + "}").getValue(context);

Cast the object to the appropriate backing bean type. That solves the problem.
Hope it helps.

Happy Programming :)

Signing Off
Ryan

No comments: