Saturday, November 30, 2013

ADF Dialog - Return value from a modal dialog

There are two kinds of dialogs modeless where user can work on both the pages and modal dialog user can work on the popup only.For running bounded task flow with dialog the task flow should uses pages instead of the page fragments.

Create a bounded task flow as below:

Call the bounded task flow from an unbounded task flow :

Define input parameters and return value for the bounded task flow.

Specify the parameter for the calling side of the task flow .


Launch.jspx

Note the the af:outputText and af:button properties 

<?xml version='1.0' encoding='UTF-8'?>
<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="2.1" xmlns:f="http://java.sun.com/jsf/core"
          xmlns:af="http://xmlns.oracle.com/adf/faces/rich">
    <jsp:directive.page contentType="text/html;charset=UTF-8"/>
    <f:view>
        <af:document title="launch.jspx" id="d1">
            <af:form id="f1">
                <af:panelGroupLayout id="pgl1">
                    <af:outputText value="outputText1" id="ot1" binding="#{pageFlowScope.DialogBackingbean.outTextBind}"
                                   partialTriggers="#{pageFlowScope.DialogBackingbean.outTextBind}"/>
                    <af:button text="button 1" id="b1" action="edit" useWindow="true"
                               returnListener="#{pageFlowScope.DialogBackingbean.listenerMethod}"/>
                </af:panelGroupLayout>
            </af:form>
        </af:document>
    </f:view>
</jsp:root>

Dialog.jspx

<?xml version='1.0' encoding='UTF-8'?>
<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="2.1" xmlns:f="http://java.sun.com/jsf/core"
          xmlns:af="http://xmlns.oracle.com/adf/faces/rich">
    <jsp:directive.page contentType="text/html;charset=UTF-8"/>
    <f:view>
        <af:document title="dialog.jspx" id="d1">
            <af:form id="f1">
                <af:panelGroupLayout id="pgl1">
                    <af:button text="button 1" id="b1" action="close"/>
                </af:panelGroupLayout>
            </af:form>
        </af:document>
    </f:view>
</jsp:root>

Backing bean
package view.test;

import oracle.adf.view.rich.component.rich.output.RichOutputText;
import oracle.adf.view.rich.context.AdfFacesContext;

import org.apache.myfaces.trinidad.event.ReturnEvent;

public class DialogBackingbean {
    private RichOutputText outTextBind;

    public DialogBackingbean() {
    }

    public void listenerMethod(ReturnEvent returnEvent) {
        System.out.println("Return Listener..");
        // AdfFacesContext.getCurrentInstance().getPageFlowScope().put("testValue", "Testing");
        String retVal = (String) AdfFacesContext.getCurrentInstance().getPageFlowScope().get("retVal");
        System.out.println(retVal);
       
        this.getOutTextBind().setValue(retVal);
        AdfFacesContext.getCurrentInstance().addPartialTarget(this.getOutTextBind());
    }

    public void setOutTextBind(RichOutputText outTextBind) {
        this.outTextBind = outTextBind;
    }

    public RichOutputText getOutTextBind() {
        return outTextBind;
    }
}

1 comment:

  1. If instead of pressing on the command button to close the dialog we cancel the dialog window by pressing on the "X" button would the returnlistener still be invoked?

    ReplyDelete