Saturday 14 March 2015

Eventing FrameWork Part 2

Using Automatic Events:
Automatic events are the events that occur on when something happen(not usual) like phone ringing,sms e.t.c.There are of two types
  • Pre Event handler: This is called before the execution of method (in a table or a class).
  • Post Event handler:This is called after the execution of method(in a table or a class)
Note:These event handler can be defined against a method in a class or a table.
Here is the example:
I have create a class ‘AsimPrePostHandlerClass’
PrePostHandlerClass
And written Pre/Post Event handler here.
Pre
In Pre Event Handler,I am just intializing customerTable buffer with the sender object which is actually a table buffer,then checking if the custAccount value is ‘4010’then the error should be prompted on inserting.
Post
In the Post Event above, I am just prompting the notification that Account selected has been successfully added.
Also i have create a table conting two fields and created a  validateWrite method
Table
Now subscribe Pre/Post Event handler with the method(see below)
handlerSubcrie

PrePosthandlers
Now associating Pre/Post Event handler to the Pre/Post methods that i have written before in the class
PreHandlerPropert PostHandlerProperty
Finally i have created a simpleListDetails form via table the i have create before
Form
Now lets try a record (let say Cust Account = 4000)
PostEvenHandlerCall
See above the Post Event Handler called.Also pre event handler was also called but my check is for CustAccount = 4000 that why it didn’t show any message
Now lets try to enter Customer Account = 4010)
PreEventPostEventCall
See the Pre Event Handler is called again but now its showing the a message as well(thats was my check) and then post event handler is also called
ValueSave
Also note above that since the pre event handler is called but still value can be saved , which should be not. SO the idea is if we want to cancel all the handlers like
if pre event is failed then method and Post should not be called then we need to throw an exception which apparently aborted all execution.But first let see the sequence of calling.In the validate write method i have added an info
MethodCall
Now lets try so enter a record Customer Account = 4000
PreMethodPost
See so first Pre event called then method ‘validateWrite’ called and finally Post even called
Now if we want to abort things the we need to throw an exception like
Exception
Now i am throwing an exception here in pre event handler.now let c whats happen.Let try to enter a record Customer Account = 4000
ExcpetionThrown
See now the all the executions have been aborted and also it stopping me to enter a record in it as well
Hope this blog may clear Pre and Post Event handler concepts.

No comments:

Post a Comment