组件的关系:
几个Controller都需要共同调用的内容可由写在Custom Controller中,例如当一个BAPI被调用时返回的信息需要某种形式的中间处理才可以显示,这个中间处理可由写在Custom Controller中。
如常见的RFC的处理就会在Custom中新建一个RFCController,并创建这三个常用的方法:
//@@begin javadoc:excute_ZTM_RFC_YSQSD_GETORDER()
/** 执行某RFC的方法. */
//@@end
public com.nanchu.ysd.model.Ztm_Rfc_Ysqsd_Getorder_Output excute_ZTM_RFC_YSQSD_GETORDER( com.nanchu.ysd.model.Ztm_Rfc_Ysqsd_Getorder_Input input )
{
//@@begin excute_ZTM_RFC_YSQSD_GETORDER()
Ztm_Rfc_Ysqsd_Getorder_Output output = null;
try {
input.execute();
output = input.getOutput();
} catch (WDDynamicRFCExecuteException e) {
e.printStackTrace();
logger.errorT(e.getLocalizedMessage());
printRFCError(e);
return null;
} finally {
input.modelInstance().disconnectIfAlive();
}
return output;
//@@end
}
//@@begin javadoc:handleBapiret()
/** 处理异常. */
//@@end
public boolean handleBapiret( com.nanchu.ysd.model.Bapiret2 bapiret )
{
//@@begin handleBapiret()
String type = bapiret.getType();
String msg = bapiret.getMessage_V1();
if ("S".equals(type)) {
wdComponentAPI.getMessageManager().reportSuccess(msg);
return true;
} else if ("E".equals(type)) {
wdComponentAPI.getMessageManager().reportException(msg, false);
return false;
} else if ("W".equals(type)) {
wdComponentAPI.getMessageManager().reportWarning(msg);
return true;
}
return true;
//@@end
}
//@@begin javadoc:printRFCError()
/** 打印异常. */
//@@end
public void printRFCError( com.sap.tc.webdynpro.modelimpl.dynamicrfc.WDDynamicRFCExecuteException e )
{
//@@begin printRFCError()
try {
wdComponentAPI.getMessageManager().reportException(
new String(e.getMessage().getBytes("ISO-8859-1"), "GB2312"), false);
} catch (UnsupportedEncodingException e1) {
wdComponentAPI.getMessageManager().reportWarning(e1.toString());
}
//@@end
}
当然这些方法也是可以直接写在Component Controller中,但是方法一多就不好管理。
Custom Controller就相当于定制化的Component Controller,方便了代码的整合优化,并且其生命周期可以修改,而在Component中不能修改。
组件之间的跳转
1)无传值跳转
实现:
分成四个步骤:
1)创建要跳转的两个或多个View
2)在创建window并嵌入要跳转的View
3)在window中设置inbound和outbound插口
4)连接插口
2)有传值跳转
补充两个知识要点:
- 数据绑定(Data Binding):自动将数据从Controller的上下文传递到另一个Controller上下文。
映射可以分为内部映射(同一组件内不同控制器间的映射)和外部映射(不同组件之间的控制器间的映射);上下文节点为数据源时称为映射源节点,其他的成为映射节点。
- 数据绑定(Data Binding):自动将数据从View Controller的上下文传递到其布局的元素。
三个图可以说明其实现:
1)在Component Controller中新建共同使用的数据集,注意要设置Person节点的基数为1:1否则该节点是不活动的
2)让两个互相跳转的View都映射到Component Controller,这样数据就会通过该控制器进行传递。
3)跳转按钮实现的方法如下:返回跳转的按钮同理。
public void onActionGo(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent )
{
//@@begin onActionGo(ServerEvent)
//$$begin ActionButton(956662293)
wdThis.wdFirePlugToDetailView();
//$$end
//@@end
}
有时候需要在Local Dictionaries中新建一个Structure:StructurePerson,然后让Component Controller去绑定(Binding)这个Structure,再去让两个View分别映射Component的节点(即重复上述的操作)。如下面的Begin Date和End Date,可以使用系统自带的类型也可以绑定本地字典的类型:
3、不同Component之间的View跳转
实现:
1)首先准备好两个Component(ExComp、DetailComp)以及View(StartView & DetailView,DetailCompView)
2)Component里面Context内容是通过component Interface暴露给其他component,而使用该外部映射的Component就要通过used Component来引用映射源Component的component interface,从而建立外部映射关系。这里DetailComp和Component Controller(ExComp2)之间的映射成为外部映射。
注意:外部映射的映射节点(本例中指的是Component Interface的Person节点)的isInputElement属性必须设置为true
3)至于示例要实现在同一个页面上显示另一个Component的View,则可以通过Window的ViewSet来实现,如下所示,StartView点击Go后跳转到Interface中去并把页面在空白的View上显示。
图片主要来自:SAP官方文档