Creating a Custom Dialog- Part 2
March 08, 2009 in Maximo, Maximo 6, Maximo: Programming by Michael Chrisman 14 Comments
Now that we have our dialog box, the next thing is to add some custom functionality to the dialog box. In this example, we will add a button that when the user clicks it, it will call our custom code.
First we are going to create our custom java class. We will extend the DataBean class. In this class, create a method with whatever name you like. Make sure it has no parameters. In the method, do whatever processing you need.
1:2: package myCompany.webclient.beans.asset;3:4: import java.rmi.RemoteException;5: import java.text.ParseException;6:7: import psdi.webclient.system.controller.Utility;8: import psdi.webclient.system.controller.WebClientEvent;9: import psdi.webclient.system.beans.*;10: import psdi.util.logging.FixedLoggerNames;11: import psdi.util.logging.MXLogger;12: import psdi.util.logging.MXLoggerFactory;13:14: import psdi.util.MXException;15:16:17: public class myDialogBox extends DataBean18: {19: MXLogger appLog = MXLoggerFactory.getLogger(FixedLoggerNames.LOGGERNAME_APP + ".myDialogBox");20:21: public int dosomething() throws RemoteException, MXException, ParseException22: {23: appLog.info("myDialogBoxBean :: enter dosomething ……") ;24:25: try26: {27: // Since screen variables are attributes on the MBO, we can use the this.getString28: // to access them (or getBoolean, etc)29: String myVar = this.getString("MY_CUSTOM_VAR");30:31: // Do stuff here…32: }33: catch (Exception e)34: {35: appLog.error("ERROR: " + e + "n" + e.getStackTrace());36: }37:38: // the following line will close the dialog box.39: Utility.sendEvent(new WebClientEvent("dialogclose", app.getCurrentPageId(), null, sessionContext));40:41: appLog.info("myDialogBoxBean :: exit dosomething ……") ;42:43: return EVENT_HANDLED;44: }45:46: }
Since we added fields to the MBO object, we can access fields that users through the MBO.
NOTE: Databean class files need to go into the
Now save, compile, and rebuild/deploy ear.
Now we set the base class for the dialog box. Open the properties page for the dialog box.
In the "Bean Class" field, add the name of your class.
Now we need to edit the properties of the button.
In the 'Event' field, type in the of the method you created. This is Java, so case does matter. Now save the screen, and go test it.
If you have to make a change to your code, you will need to rebuild/deploy the ear to test it.
Your series on customizing dialog boxes is certainly timely! I am working on a customization to the move/modify assets dialog which is contained in the library.xml (version 7.1.) I am adding three new attributes on the Users and Custodians ‘modify all’ tab.
Would I modify the bean class as above, or do I need to modify the mboname referenced in the XML (assetusercustdflt)?