October 11, 2012

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.

6 comments:

  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

    ReplyDelete
    Replies
    1. Your code is very different from the one I have posted.
      You have to check event.getMessageReturn() value to retrieve user's input.

      Delete
    2. 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.

      Delete
    3. 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.

      Delete
  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

    }

    ReplyDelete
  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;
    }
    }

    ReplyDelete