How to reference JSF @ManagedBean inside Spring MVC @Controller
From a Spring MVC @Controller, I need to be able to call a JSF @ManagedBean.
The problem seems to be that the @ManagedBean is not visible in the Spring ApplicationContext. Is there any way to do make the following accessible:
Code:
@ManagedBean(name = "jsfService")
@ViewScoped
public class JsfServiceImpl implements JsfService {
@ManagedProperty(value = "#{jsfDao}")
private JsfDao jsfDao;
...
private Long selectedId;
public void setSelectedId(Long selectedId) {
this.selectedId = selectedId;
}
...
public String doStuff() {
FacesContext context = FacesContext.getCurrentInstance();
Flash flash = context.getExternalContext().getFlash();
flash.put("stuffContext", String.valueOf(this.selectedId));
flash.put("backView", context.getViewRoot().getViewId());
return "/do/stuff";
}
}
... so it could be accessed in a @Controller like so:
Code:
@Controller
public class JsfRedirectController implements ApplicationContextAware {
private ApplicationContext applicationContext;
@RequestMapping("/do-jsf-stuff/{id}")
public void doJsfStuffById(@PathVariable("id") long id) {
JsfServiceImpl jsfService = applicationContext.getBean(JsfServiceImpl.class);
jsfService.setSelectedId(id);
jsfService.doStuff();
}
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
this.applicationContext = applicationContext;
}
}
I have set the following in faces-config.xml, but that seems only to make Spring beans available to JSF and not the other way around:
HTML Code:
<application>
<el-resolver>org.springframework.web.jsf.el.SpringBeanFacesELResolver</el-resolver>
</application>