How - to launch print dialog when showing printable page in Oracle ADF

1.1k views Asked by At

Hello I am developing an ADF Web application. In this I have test.jsf page and a showPrintablePage behaviour command button. When user click the button adf just shows a printable page in new window. But when the user clicks on the button it should directly show in print window of browser. For this I got the following code from ADF Code Corner.

public void beforePhaseMethod(PhaseEvent phaseEvent) {
    if (phaseEvent.getPhaseId() == PhaseId.RENDER_RESPONSE) {
        FacesContext fctx = FacesContext.getCurrentInstance();
        AdfFacesContext adfFacesContext = AdfFacesContext.getCurrentInstance();
        if (adfFacesContext.getOutputMode() == OutputMode.PRINTABLE) {
            ExtendedRenderKitService erks = null;
            erks = Service.getRenderKitService(fctx, ExtendedRenderKitService.class);
            erks.addScript(fctx, "window.print();");
        }
    }
}

I have follwed the process specified in the document. And the follwoing is the test.jsf page code.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ page contentType="text/html;charset=UTF-8"%>
<%@ taglib uri="http://xmlns.oracle.com/adf/faces/rich" prefix="af"%>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
<f:view beforePhase="#{viewScope.PieBean.beforePhaseMethod}">
    <af:document title="printTest" id="d1">
        <af:form id="f1">
            <af:commandButton text="commandButton 1" id="cb1">
                <af:showPrintablePageBehavior/>
            </af:commandButton>
            <af:goButton text="goButton 1" id="gb1"/>
        </af:form>
    </af:document>
</f:view>

but it is showing in test.jsf property inspector beforePhaseMethod is an unknown property.

And the final out is as follows enter image description here Please help. Thanks in advance.

1

There are 1 answers

0
Ramandeep Nanda On

Did you register the bean in adfc-config or if you are using the taskflow, then in taskflow configuration. Also from the screenshot, it seems you are getting the desired output.