2008-06-20

web dynpro for abap基础知识(3)

web dynpro中controller的方法

在web dynpro中每个controller都有两个默认的方法:

wddoinit():这是一个controller内第一个被调用的方法,常用于初始化数据。

wddoexit():这是一个controller内最后一个被调用的方法,用于做收尾工作。

这两个方法在controller被创建时自动生成,并且都是空的方法。

对于component controller还有两外两个重要的方法:

wddobeforenavigation():
This method is called after the action method has been processed and just before the web dynpro frameworkprocesses the events in the navigation queque.

wddopostprocessing():
This method allows data validation from multiple components, and it's the last controller method that is processed before the UI is sent to the client.

view controller也有自己的两个方法:

wddobeforeaction():
After the web dynpro application has been started and the user has raised a client event, the first methods to be processed in the wda are the wddobeforeaction() methods of all view controllers of the previous rendered view assembly, before the action handler method to the event processed.

webdomodifyview():
用于动态修改UI Element。

对于各类controller,用户都可以创建自己的methods。在创建method时,有三种类型可选:method, event handler和supply function。双击方法名就可以打开一个编辑器,书写实现代码。在一个component内,一个controller可以调用其他controller的方法,只要在这个controller内声明使用了另一个controller即可。如果要让一个controller的自定义方法能被位于component内的另外一个controller调用,那么需要设置该方法的Interface属性。

前面提到了controller的methods,现在轮到controller的attributes。除了interface controller和interface view controller外每个controller都有两个预定义好的attribute:WD_THIS和WD_CONTEXT。WD_THIS指向当前的controller interface, IF_<controller name>;WD_CONTEXT指向controller context下的root node。访问context内的其他node/attribute就是借助它来完成的。

如果一个controller声明使用component controller,那么一个标准attribute WD_COMP_CONTROLLER会被自动创建,以指向component controller,这样component controller内的methods和public attributes就能被调用,wd_comp-controller -> method name 。

如果一个controller A声明使用其他类型的controller B(不是component controller),这时在controller A中不会自动生成一个指向controller B的引用。为了得到指向B的引用需要下面的办法:

DATA: lo_ctrl TYPE REF TO ig_<ctrl>.
lo_ctrl = wd_this->get_<ctrl>_ctrl( ).

用户也可以自定义attribute。如果attribute的public flag被设置,那么这个attribute对于同一个component内的其他controller也是可见的。访问其他controller的public attribute的方式与访问method一样。

没有评论:

发表评论