Skip to Main Content

Java Development Tools

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Popup giving a null pointer exception

AnuannDec 12 2015 — edited Mar 7 2016

Hai all,

Jdev 12.2.1

I have a template JSF page in which I have included a popup which needs to be shown when a set of declarative buttons is clicked. So inside the bean java class file, the methods of those buttons are written and inside of which the popup is called. But when popup is called it is giving a null value. I checked the value of the binding variable and it is getting a null value.

Caused by: java.lang.NullPointerException

Both file's source code is given below:::

----------------------------------------JSF file-----------------------------------------------------

<?xml version='1.0' encoding='UTF-8'?>

<af:pageTemplateDef xmlns:af="http://xmlns.oracle.com/adf/faces/rich" var="attrs"

                    xmlns:afc="http://xmlns.oracle.com/adf/faces/rich/component" xmlns:f="http://java.sun.com/jsf/core"

                    xmlns:c="http://java.sun.com/jsp/jstl/core">

    <af:xmlContent>

        <afc:component>

            <afc:description/>

            <afc:display-name>PageTemplate</afc:display-name>

            <afc:facet>

                <afc:description>Main</afc:description>

                <afc:facet-name>Main</afc:facet-name>

            </afc:facet>

            <afc:attribute>

                <afc:attribute-name>

                    saveSuccessMessage

                </afc:attribute-name>

            </afc:attribute>

        </afc:component>

        <c:set var="commonuiBundle" value="#{adfBundle['com.tech.commonlabel.CommonUI']}"/>

    </af:xmlContent>

    <af:subform id="pt_s1" default="true">

        <af:panelStretchLayout id="pt_psl1" startWidth="15px">

            <f:facet name="center">

                <af:facetRef facetName="Main"/>

            </f:facet>

            <f:facet name="bottom">

               <af:popup childCreation="deferred" id="p2"

                          binding="#{backingBeanScope.PageTemplateBean.saveChangesPopup}" autoCancel="disabled">

                    <af:dialog id="d3" title="Save Changes?" type="yesNoCancel"

                               dialogListener="#{backingBeanScope.PageTemplateBean.saveChangesDialogListener}"

                               closeIconVisible="false">

                        <af:outputText value="Do you want to save the changes before you proceed ?" id="ot8"/>

                    </af:dialog>

                </af:popup>

            </f:facet>

            <f:facet name="start">

                <af:popup childCreation="deferred" autoCancel="disabled" id="pt_p1"

                          binding="#{backingBeanScope.PageTemplateBean.saveSuccessPopup}">

                    <af:dialog id="pt_d1" title="#{commonuiBundle.SAVE_ACTION}">

                        <f:facet name="buttonBar"/>

                        <af:outputText value="#{commonuiBundle.RECORD_SAVED_SUCCESSFULLY}" id="pt_ot1"/>

                        <af:outputText value="#{attrs.saveSuccessMessage}" id="pt_ot2"/>

                    </af:dialog>

                </af:popup>

            </f:facet>

        </af:panelStretchLayout>

    </af:subform>

</af:pageTemplateDef>

------------------Bean -----------------------------------------------

package com.tech.commonui.bean;

import com.tech.commonui.interfaces.ActionInterface;

import com.tech.commonui.utils.JSFUtils;

import com.tech.commonui.utils.ADFLogger;

import java.util.Collection;

import javax.el.ELContext;

import javax.el.ExpressionFactory;

import javax.el.ValueExpression;

import javax.faces.context.FacesContext;

import oracle.adf.model.BindingContext;

import oracle.adf.model.DataControlFrame;

import oracle.adf.model.binding.DCDataControl;

import oracle.adf.view.rich.component.rich.RichPopup;

import oracle.adf.view.rich.event.DialogEvent;

public class PageTemplateBean {

    private static ADFLogger _logger = ADFLogger.createAdfLogger(PageTemplateBean.class);

    ActionInterface templateBean = null;

    private RichPopup saveSuccessPopup;

    private RichPopup saveFailedPopup;

    private RichPopup saveChangesPopup;

    public PageTemplateBean() {

        super();

    }

    /**

     * @return

     */

    public String createInsert() {

        // Add event code here...

        _logger.info("entering");

        if (JSFUtils.pendingChangesExists()) {

             JSFUtils.setPageFlowScope("UserAction", "createInsert");

            _logger.info("=================calling popup=================");

           JSFUtils.showPopUp(getSaveChangesPopup());

        } else {

            ActionInterface bean = getBean();

            return bean.createInsert();

        }

        _logger.info("exiting");

        return null;

    }

    /**

     * @return

     */

    public String delete() {

        // Add event code here...

        _logger.info("entering");

        if (JSFUtils.pendingChangesExists()) {

            JSFUtils.setPageFlowScope("UserAction", "delete");

            JSFUtils.showPopUp(getSaveChangesPopup());

        } else {

            ActionInterface bean = getBean();

            return bean.delete();

        }

        _logger.info("exiting");

        return null;

    }

    /**

     * @return

     */

    public String save() {

        // Add event code here...

        _logger.info("entering");

        ActionInterface bean = getBean();

        Object saveAcionSuccess = bean.save();

        _logger.info("exiting");

        return null;

    }

    /**

     * @return

     */

    public String rollback() {

        // Add event code here...

        _logger.info("entering");

        ActionInterface bean = getBean();

        _logger.info("exiting");

        return bean.rollback();

    }

  

    /**

     * @return

     */

    public String edit() {

        // Add event code here...

        _logger.info("entering");

        if (JSFUtils.pendingChangesExists()) {

            _logger.info("setting scope");

            JSFUtils.setPageFlowScope("UserAction", "edit");

            _logger.info("=================calling popup=================");

            JSFUtils.showPopUp(getSaveChangesPopup());

        } else {

            ActionInterface bean = getBean();

            return bean.edit();

        }

        _logger.info("exiting");

        return null;

    }

  

    /**

     * Method for getting the subapplication's managed bean from

     * Template attribute "attrs.applnManagedBean"

     * @return :- Managed bean of subapplicaton.

     */

    private ActionInterface getBean() {

        _logger.info("entering");

        if (templateBean == null) {

            FacesContext fctx = FacesContext.getCurrentInstance();

            ELContext elctx = fctx.getELContext();

            ExpressionFactory exprFactory = fctx.getApplication().getExpressionFactory();

            ValueExpression ve = exprFactory.createValueExpression(elctx, "#{attrs.ManagedBean}", Object.class);

            Object valueObject = ve.getValue(elctx);

            if (valueObject != null) {

                templateBean = (ActionInterface) valueObject;

                ValueExpression ve1 = exprFactory.createValueExpression(elctx, "#{attrs.IteratorName}", Object.class);

                String itratorName = (String) ve1.getValue(elctx);

                if (itratorName != null && !itratorName.equals("")) {

                    templateBean.setIteratorName(itratorName);

                } else {

                    _logger.info("=======IteratorName Not Found=======");

                }

            } else {

                // log message here

            }

        }

        _logger.info("exiting");

        return templateBean;

    }

    public void setSaveFailedPopup(RichPopup saveFailedPopup) {

        this.saveFailedPopup = saveFailedPopup;

    }

    public RichPopup getSaveFailedPopup() {

        return saveFailedPopup;

    }

public void setSaveSuccessPopup(RichPopup saveSuccessPopup) {

        this.saveSuccessPopup = saveSuccessPopup;

    }

    public RichPopup getSaveSuccessPopup() {

        return saveSuccessPopup;

    }

    public void setSaveChangesPopup(RichPopup saveChangesPopup) {

        this.saveChangesPopup = saveChangesPopup;

    }

    public RichPopup getSaveChangesPopup() {

        _logger.info("popup====================" +saveChangesPopup);

        return saveChangesPopup;

    }

    public void saveChangesDialogListener(DialogEvent dialogEvent) {

        // Add event code here...

        _logger.info("entering");

        ActionInterface bean = getBean();

        if (dialogEvent.getOutcome().equals(DialogEvent.Outcome.yes)) {

            _logger.info("outcome yes");

            bean.save();

            if (JSFUtils.getPageFlowScope("UserAction").equals("createInsert")) {

                bean.createInsert();

            }

            if (JSFUtils.getPageFlowScope("UserAction").equals("delete")) {

                bean.delete();

            }

            if (JSFUtils.getPageFlowScope("UserAction").equals("edit")) {

                bean.edit();

            }

        } else if (dialogEvent.getOutcome().equals(DialogEvent.Outcome.no)) {

            _logger.info("outcome no");

            bean.rollback();

            if (JSFUtils.getPageFlowScope("UserAction").equals("createInsert")) {

                bean.createInsert();

            }

            if (JSFUtils.getPageFlowScope("UserAction").equals("delete")) {

                bean.delete();

            }

            if (JSFUtils.getPageFlowScope("UserAction").equals("edit")) {

                bean.edit();

            }

        } else {

            _logger.info("outcome no");

        }

        _logger.info("exiting");

    }

}

Is it because of any component specified in the jsf page?

Thanks and regards

Anu

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 4 2016
Added on Dec 12 2015
4 comments
1,281 views