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!

On button click open popup programmatically and set inputText (ID) value programmatically

Paul SusantoJul 30 2018 — edited Jul 30 2018

Hi All,

JDeveloper Version: Studio Edition Version 12.2.1.3.0

Requirement: I have a demo.jspx page where I have a af:button named "Show Popup". On click of the "Show Popup" button, it should do some processing to generate the ID and set that ID to the ID field inside the popup where there is two input fields to enter the ID(which is autopopulated based on logic written inside the ActionListenere of "Show Popup") and Name both mandatory. Also inside the popup there is a Commit button will will save the changes to the database.

What I have done here is, I drag and drop the button from component pallete, and wrote code to open popup with empty ID and Name fields on click of this button.

Inside popup I have dialog, inside which I have drag and drop the the fields(id and name) from the Data control pallete as a input form.And also, I have dragged and dropped the Commit button, and did binding for CreateInsert.

Thus the complete demo.jspx page is as below:

<?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="demo.jspx" id="d1">

            <af:messages id="m1"/>

            <af:form id="f1">

                <af:button text="Show Popup" id="b1" actionListener="#{pageFlowScope.MyBean.showPopupBtnClicked}"/>

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

                          binding="#{pageFlowScope.MyBean.popupBind}">

                    <af:dialog id="d2" type="none">

                        <af:panelFormLayout id="pfl1">

                            <af:inputText value="#{bindings.Id.inputValue}" label="#{bindings.Id.hints.label}"

                                          required="#{bindings.Id.hints.mandatory}"

                                          columns="#{bindings.Id.hints.displayWidth}"

                                          maximumLength="#{bindings.Id.hints.precision}"

                                          shortDesc="#{bindings.Id.hints.tooltip}" id="it1">

                                <f:validator binding="#{bindings.Id.validator}"/>

                            </af:inputText>

                            <af:inputText value="#{bindings.Name.inputValue}" label="#{bindings.Name.hints.label}"

                                          required="#{bindings.Name.hints.mandatory}"

                                          columns="#{bindings.Name.hints.displayWidth}"

                                          maximumLength="#{bindings.Name.hints.precision}"

                                          shortDesc="#{bindings.Name.hints.tooltip}" id="it2">

                                <f:validator binding="#{bindings.Name.validator}"/>

                            </af:inputText>

                        </af:panelFormLayout>

                        <f:facet name="buttonBar">

                            <af:button actionListener="#{bindings.Commit.execute}" text="Commit" id="b2"/>

                        </f:facet>

                    </af:dialog>

                </af:popup>

            </af:form>

        </af:document>

    </f:view>

</jsp:root>

And the complete MyBean.java code is as below:

package com.susanto.beans;

import javax.faces.event.ActionEvent;

import oracle.adf.model.BindingContext;

import oracle.adf.model.OperationBinding;

import oracle.adf.model.binding.DCBindingContainer;

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

public class MyBean {

    private RichPopup popupBind;

    public MyBean() {

    }

    public void showPopupBtnClicked(ActionEvent actionEvent) {

        DCBindingContainer bindings = (DCBindingContainer) BindingContext.getCurrent().getCurrentBindingsEntry();

        OperationBinding operationBinding = (OperationBinding) bindings.getOperationBinding("CreateInsert");

        operationBinding.execute();

        RichPopup.PopupHints hints = new RichPopup.PopupHints();

        this.getPopupBind().show(hints);

    }

    public void setPopupBind(RichPopup popupBind) {

        this.popupBind = popupBind;

    }

    public RichPopup getPopupBind() {

        return popupBind;

    }

}

Database table:

CREATE TABLE test (

    id     VARCHAR2(20) PRIMARY KEY,

    name   VARCHAR2(20) NOT NULL

);

The above set up works fine but here the ID field is not auto populated.

So in order to autopopulate the ID filed inside the popup I tried the below approach.

1. Added binding for ID field and tried to set the value as bindingName.setValue("123test") - for which i got null pointer exception.

2. I tried to do value binding and set the values of Id field, for which the value is getting set property, But when I click on commit button, it error out saying ID field is mandatory.

Can any one please suggest how I should proceed.

Thanks & Regards,

Susanto Paul

This post has been answered by Timo Hahn on Jul 30 2018
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 27 2018
Added on Jul 30 2018
4 comments
1,000 views