1
EVENT HANDLING WITH ACTION INSTANCES FOR EVENT-DRIVEN SOFTWARE APPLICATION
BACKGROUND 5
The present invention relates to data processing by digital computer, and more particularly to event handling.
In the model-view-controller (MVC) design pattern used for developing software applications, the model represents 10 the core of an application. The model can have multiple views, where each view displays information about the model to a user. A controller of the model receives events—for example, from a user through a user interface—to manipulate the model. The model and the controller typically include 15 application code. When changes occur in the model, the model updates all of its views. Data binding is used for decoupling controller and view with regards to data flow. For example, a table view can be defined to display data of a corresponding table that is stored in the model or controller. 20 The table is used as data source for the table view (data binding). The table view can be replaced by a different view, such as a link list, that binds against the same table. In this case the new view displays the table data without changing anything in the controller or the model. When the table view 25 initiates an event (e.g., "onClick"), the event is processed by the controller. Typically, the controller includes an event handler that expects a specific signature (e.g., a specific list of parameters), such as "onClick(tableViewCell)", for a given event. However, when the table view is replaced by the link 30 list view, the signature of the event is likely to change. For example, a different parameter may be passed to controller (e.g., "onClick(LinkListltem)"). Without further modification the controller may not be able to process the event that is initiated by the link list view of the event handler. 35
SUMMARY OF THE INVENTION
The present invention provides methods and apparatus, including computer program products, for decoupling system 40 events from application events handling in an event-driven software application. In general, in one aspect, the invention features methods and apparatus, including computer program products, implementing techniques for event handling. The techniques include receiving an event request specifying an 45 event and values for one or more event parameters; identifying an action associated with the specified event, the action specifying a required set of parameters and an event handling function specifying one or more operations that can be performed on data; generating an instance of the identified action 50 by mapping the event parameter values to the required set of parameters; and calling the event handling function with the generated instance of the identified action.
The invention can be implemented to provide one or more of the following features. The event request can be a request 55 for an event initiated in response to user input. The user input can be received in an interface defined in a view of a modelview-controller design pattern. The specified event can include information identifying one or more manipulations to be performed on data in a model associated with the view. The 60 event handling function can specify one or more operations required to carry out the identified manipulations. The action can be defined in a controller associated with the view. The action can be associated in the view with the specified event. The controller can implement an event handler associated 65 with the action. The event handler can include an implementation of the event handling function. The event handling
2
function can call application code in the model or the controller. The application code can implement the specified operations.
Receiving an event request can include receiving an event request in a first event handler and extracting a representation of the event from the request. The techniques can include determining whether the generated instance of the identified action is a valid instance of the identified action. The event handling function can be called only if the generated instance of the identified action is determined to be valid. The techniques can include determining whether the specified action is enabled. The event handling function can be called only if the action is determined to be enabled. The specified action can include an enabled attribute having a value indicating whether the action is enabled or disabled. Determining whether the specified action is enabled can include accessing the value for the enabled attribute.
In general, in another aspect, the invention features a computer system for event handling. The system includes a system event handler operable to perform an analysis to determine whether a system event received by the system event handler triggers an application event; and an application event handler operable to call application code if the application event is triggered and invokes the application event handler.
The invention can be implemented to provide one or more of the following features. The system event handler, when performing the analysis, can determine whether the system event includes a valid representation of an action associated with the application event. The system event handler, when performing the analysis, can determine whether the action is enabled. The action can be defined in a controller of a model. The controller can implement an application event handler associated with the action. The application event handler can implement an event handling function to call the application code. The system can include a phase handler operable to control a plurality of phases of the computer system. The plurality of phases can include a request handling phase, a system event handling phase, a data validation and transport phase and an application event handling phase. The phase handler can receive a request in the request handling phase. The phase handler can extract the system event from the request. After extracting the system event from the request, the phase handler can start the system event handling phase. After receiving a valid representation of an action, the phase handler can start the data validation and transport phase. The phase handler can call validation services during the data validation and transport phase to convert non-typed values of the request into typed values and to validate the typed values. The phase handler can start the application event handling phase after successful completion of the data validation and transport phase by initiating the application event associated with the action.
In general, in another aspect, the invention features a computer system for event handling. The system includes a model; a view operable to present the model and initiate a system event, the view being further operable to associate the system event with an action; and a controller operable to manipulate the model in response to the system event, the controller being operable to provide the action and to call application code through an event handling function associated with the action.
The invention can be implemented to provide one or more of the following features. The system event can be received by a system event handler that returns a representation of the action to a framework. In response to receiving the representation of the action, the framework can invoke an application event handler that implements the event handling function.
In general, in still another aspect, the invention features methods and apparatus, including computer program products, implementing event handling techniques. The techniques include providing a model, a view operable to present the model and initiate a system event, and a controller oper- 5 able to manipulate the model in response to the system event; providing an action in the controller; associating the system event with the action; and calling application code through an event handling function associated with the action to manipulate the model in response to the system event. 10
In general, in another aspect, the invention features methods and apparatus, including computer program products, implementing event handling techniques. The techniques include performing an analysis of a system event in a system event handler to determine whether the system event triggers 15 an application event; initiating the application event in response to the analysis of the system event; and processing the application event by an application event handler to call application code.
The invention can be implemented to provide one or more 20 of the following features. The techniques can include receiving a request in a phase handler, and extracting the system event from the request. The techniques can include returning from the system event handler to the phase handler a valid representation of an action associated with the system event. 25 The application event can be associated with the action. The phase handler can initiate the application event if the action is enabled.
The invention can be implemented to realize one or more of 3Q the following advantages. Decoupling system events from the corresponding application events by using event binding separates the system event handling level from the application event handling level. The system event handler need not implement application logic for event handling, but simply 35 invokes the corresponding application event handler. This allows an application developer (or user) to replace views in an extended MVC design pattern without modifying the corresponding controller or model.
The details of one or more implementations of the inven- 40 tion are set forth in the accompanying drawings and the description below. Other features and advantages of the invention will become apparent from the description, the drawings, and the claims.
BRIEF DESCRIPTION OF THE DRAWINGS
FIG. 1 is a diagram of an extended model-view-controller design pattern according to one implementation of the present invention. 50
FIG. 2 illustrates one example of a visualization of a view suitable for use in the extended model-view-controller design pattern of FIG. 1.
FIG. 3 illustrates a mapping scheme for decoupling system events and application events by using mapping tables for event binding according to one implementation of the present invention.
FIG. 4 is a diagram illustrating a computer program product including a system event handler and an application event handler according to one implementation of the present invention.
FIG. 5 is a flow diagram illustrating a method for event handling according to one implementation of the present invention.
Like reference numbers and designations in the various drawings indicate like elements.
DETAILED DESCRIPTION
As shown in FIG. 1, an exemplary computer system 900 in accordance with the invention stores a model 301, a view 303 of the model 301, and a corresponding controller 302. The model 301 and the controller 302 can include application code 200 that defines an application. The view 303 presents data of the model 301 and/or controller 302 to the user. The model 301 can have multiple views that can be represented to the user as different presentations of the application (model 301/controller 302). When the user interacts with the computer system 900 through a graphical user interface that includes a presentation of the model 301/controller 302, the user 10 uses the controller 302 to manipulate the model 301, which updates its views (e.g., view 303) to reflect the results of the user's actions.
The computer system 900 includes a system event handler 100-1 to receive and process system events that result, for example, from user interactions. The system event handler 100-1 canbe implemented as a method of a specific controller class. For example, if the user 10 selects a specific user interface (UI) element, such as an OK button, displayed in one of the views of the model 301, and if selection of the UI element initiates a system event (e.g., "onClick"), the system event handler 100-1 receives the system event. Additional examples of UI elements include links, menu items, toolbars or leaves of a tree. Additional examples of system events include scroll events or help request events. Not every system event triggers an application event. For example, system events that are initiated by scrolling a table can be handled by the system event handler 100-1 without an application.
After the system event handler 100-1 receives a system event, it analyzes the system event to determine whether the system event triggers an application event, and provides the analysis result to a framework in the computer system 900. Examples of application events include "CheckAvailibility", "CheckValidBusinessPartner" and "SaveOrder". If the system event handler determines that the system event triggers an application event, the framework invokes a corresponding application event handler 100-2 by initiating an application event that corresponds to the system event. In one implementation, the application event handler 100-2 is a method that is implemented in the controller 302. In other implementations, the application event handler 100-2 can be located in any controller. The application event handler 100-2 calls application code 200 that is associated with the application event and that is implemented by the model 301 (as shown in the example of FIG. 1) or the controller 302.
Thus, the system event (e.g. "onClick") that is initiated by a particular UI element is decoupled from the corresponding application event (e.g., "SaveOrder"). In other words, the system event handler 100-1 does not need to implement application logic for event handling, but simply invokes the corresponding application event handler 100-2.
FIG. 2 illustrates one example of a visualization of a view 303 that is presented to the user 10 as a graphical user interface (GUI) 955 of an application. In this example, the user is a sales person of a specific sales organization SOI, and uses the GUI 955 to create new customers in a customer relationship management (CRM) system of the sales organization SOI. GUI 955 includes fourUI elements: a title 955-1 (CREATE NEW CUSTOMER) for displaying the title of the application; a first input field 955-2 (CUSTOMER NUMBER) for entering a customer number; a second input field 955-3 (CUSTOMER NAME) for entering a customer name; and a SAVE button 955-4 for saving the values of the input fields (e.g., in a corresponding portion of a database). In the
« 上一頁繼續 » |