How to display a YES/NO dialog and get user input

This entry is part of the Maximo Java Development series.

In this little article I’m going to show how to display a dialog box with Yes/No or OK/Cancel buttons and how to capture the user’s input to execute some custom logic. For example, you have a Java method attached to a button on the toolbar or to an action menu entry as described in this article and you want to display a warning message asking for confirmation before executing some processing.

This can be easily achieved extending the application AppBean class.
The following snippet is an extension of the WOTRACK app bean that declares a method that displays a custom message box (MyGroup/YesNoDialog) and performs some action if the users clicks the Yes button.

package cust.psdi.webclient.beans.workorder;

public class CustWorkorderAppBean extends psdi.webclient.beans.workorder.WorkorderAppBean
{
public int RUNJAVA() throws MXException, RemoteException
{
WebClientEvent event = clientSession.getCurrentEvent();
int msgRet = event.getMessageReturn();
if (msgRet < 0)
{
throw new MXApplicationException("MyGroup", "YesNoDialog");
}
else if (msgRet == WebClientRuntime.MSG_BTNYES)
{
// Implement your logic here
return EVENT_HANDLED;
}
return EVENT_HANDLED;
}
}

Refer to this article about how to define a custom Yes/No dialog box.
Refer to this article for attaching a Java method to a button or menu entry.
This article explains how to achieve a similar goal in MBO code.

How to display a YES/NO dialog and get user input

8 thoughts on “How to display a YES/NO dialog and get user input

  1. Hi Bruno,

    I want to achieve a similar goal in MBO code at the click of change status of workorder(in toolbar).
    The link above is not working, could you please help.
    The requirement is : There are 2 button: YES,NO
    At click of YES, status of Workorder should not be changed.
    At click of NO, status of workorder should be changed.
    However, i tried the following:
    if(getUserInfo().isInteractive())
    {
    int userinput = MXApplicationYesNoCancelException.getUserInput("abc", MXServer.getMXServer(),getUserInfo());

    switch (userinput)
    {
    case MXApplicationYesNoCancelException.NULL:
    if (wonums != "" ) {
    Object[] params = {wonums};
    throw new MXApplicationYesNoCancelException("abc", "workorder", "validateLimitPOContract",params);
    }
    case MXApplicationYesNoCancelException.NO:break;
    case MXApplicationYesNoCancelException.YES:
    }
    }

    But ,at the click of YES,status is changing,it would be great if you can guide me.
    And moreover,i guess it is calling changestatus twice.

    Regards,
    Aparna

  2. if(getUserInfo().isInteractive()){

    int userInput = MXApplicationYesNoCancelException.getUserInput(getClass().getName(),MXServer.getMXServer(), getUserInfo());

    switch (userInput) {
    case MXApplicationYesNoCancelException.NULL :
    throw new MXApplicationYesNoCancelException(getClass().getName(), "workorder", "youDisplayMsg");
    case MXApplicationYesNoCancelException.NO :
    break;
    case MXApplicationYesNoCancelException.YES :
    return 2;
    }

    // You block of code here for workorder status to be chaged

    }

  3. Hi Bruno,

    I am using similar code to achive YES/NO dialog box functionality, but after clicking Yes or No, control is not passed to code and nothing is happened. Please help me on this,
    Code:
    public int load()
    { System.out.println("#########################File : starts#################################");
    {
    WebClientEvent event = clientSession.getCurrentEvent();
    int msgRet = event.getMessageReturn();
    System.out.println("msgRet:"+msgRet);
    if (msgRet < 0)
    {
    System.out.println("————————–in case null————————-");
    throw new MXApplicationException("upload", "validsuccess");
    }
    else if (msgRet == WebClientRuntime.MSG_BTNYES)
    {
    System.out.println("—————-In insertion process—————————-");
    System.out.println("————————–End: load method—————————");

    throw new MXApplicationException("upload", "success");

    }
    return EVENT_HANDLED;
    }
    }

  4. Hi Aparna,

    I am facing almost same issue. Plus I am getting the error in logs as, Control XXX could not be found in order to process execute.

  5. Hi Aparna,

    I am facing almost same issue. Plus I am getting the error in logs as, Control XXX could not be found in order to process execute.

  6. Bruno first of all I want to thank you for your blog. It is very helpful.
    I'm trying to show a dialog box after clicking on a button. I added the button but I do not know how should be the Java code to open the dialog. Could you please give some example? thank you very much.

  7. For MXApplicationYesNoCancelException to work in DATABEAN you can use the following code
    int userInput= MXApplicationYesNoCancelException.getUserInput("msgkey", MXServer.getMXServer(), getMbo().getUserInfo()); if(userInput==-1){
    System.out.println("Before throwing the messaged>>"+userInput);
    throw new MXApplicationYesNoCancelException("msgKey", "msggroup", "msgkey")
    //yes will give you 2 Cancel Will you give you 4 \

    }
    if(userInput == 4){
    //CancelCOde}
    if(userInput==2){
    //yes Code}

    //For No you can check the Check box for No in Max Messages(Application Designer -> Messages dailogue box) and see what value it returns Most probably its 16

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll to top