Thursday, September 7, 2017

How To: Launch a popup programmatically (ADF)

Create a binding for the popUp in the backing bean and use the following snippet to launch it programmatically






Hope you find this helpful! Please share your feedback below.

CaptiveCode


Monday, September 4, 2017

How To: Access one managed bean from another (ADF, JSF)

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.


Download Sample Code on GitHub


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


How To: Execute View Criteria programmatically

Consider the following view criteria is defined on a view object:




To execute this view criteria programmatically, write the following method in the AMImpl class:
    public void executeInvoiceVOCriteria(String invoiceNum, String poNum){
        ViewObjectImpl vo = getInvoiceVO1();        
        ViewCriteria vc = vo.getViewCriteria("InvoiceVOCriteria");
        vo.applyViewCriteria(vc);
        vo.setNamedWhereClauseParam("p_inv_num", invoiceNum);
        vo.setNamedWhereClauseParam("p_po_num", poNum);
        vo.executeQuery();
    }




Hope you find this helpful! Please share your feedback below.

CaptiveCode


Sunday, September 3, 2017

How To: Pass parameters to action listener in ADF

I have commonly come across the requirement to pass parameters to the managed bean method on a button click. The challenge we normally face here is that, the methods attached to the "action" or "actionListener" have fixed signatures that cannot be changed.

Thus, we have to leverage the "<f:attribute>" tag alongwith a "actionListener"


Hope you find this helpful! Please share your feedback below.
CaptiveCode


How To: Throw an exception in ADF

To show an exception on ADF UI, implement the following in your managed bean:




Hope you find this helpful! Please share your feedback below.

CaptiveCode