It is a common requirement to access methods between managed beans defined in varied scopes within ADF. In this post, I am invoking backing bean (method to enable/disable a button) from a request bean. The similar approach can be used for other scopes viz. pageFlow, session, application.
Define your managed beans in your task flow:
<managed-bean id="__1">
<managed-bean-name id="__243">RequestBean</managed-bean-name>
<managed-bean-class id="__244">ui.bean.RequestBean</managed-bean-class>
<managed-bean-scope id="__245">request</managed-bean-scope>
</managed-bean>
<managed-bean id="__2">
<managed-bean-name id="__248">BackingBean</managed-bean-name>
<managed-bean-class id="__246">ui.bean.BackingBean</managed-bean-class>
<managed-bean-scope id="__247">backingBean</managed-bean-scope>
</managed-bean>
BackingBean Definition:
package ui.bean;
import oracle.adf.view.rich.component.rich.nav.RichCommandToolbarButton;
public class BackingBean {
private RichButton submitBtn;
public void setSubmitBtn(RichButton submitBtn) {
this.submitBtn = submitBtn;
}
public RichButton getSubmitBtn() {
return submitBtn;
}
}
RequestBean Definition:
package ui.bean;
import javax.el.ELContext;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;
public class RequestBean {
public BackingBean getBackingBean() {
FacesContext fctx = FacesContext.getCurrentInstance();
ELContext context = fctx.getELContext();
BackingBean backingBean =
(BackingBean) fctx.getApplication().getExpressionFactory()
.createValueExpression(context,"#{backingBeanScope.BackingBean}",BackingBean.class)
.getValue(context);
return backingBean;
}
public void enableSubmit(ActionEvent actionEvent) {
/* Invoke BackingBean method to enable/disable Submit Button */
getBackingBean().getSubmitBtn().setDisabled(false);
}
}
Hope you find this helpful! Please share your feedback below.
CaptiveCode