场景如下图:点击接受按钮,关闭子页面,父页面可以正常进行业务操作;点击不接受和右上角叉号,子页面和父页面都需要关闭,不能进行业务操作。
1):父页面插件:show子页面的时候加CloseCallBack参数
FormShowParameter showParameter = new FormShowParameter();
showParameter.setFormId(FORM_ID);
showParameter.getOpenStyle().setShowType(ShowType.Modal);
CloseCallBack callBack = new CloseCallBack(this, KEY_SURE); // 由本插件处理子界面的回调
showParameter.setCloseCallBack(callBack);
this.getView().showForm(showParameter);
2):子页面插件:点击接受按钮,给父页面返回数据sure
@Override
public void click(EventObject evt) {
Control control = (Control) evt.getSource();
String key = control.getKey();
if ("btnok".equals(key)) {
this.getView().returnDataToParent("sure");
this.getView().close();
}
}
3):子页面插件:重写beforeClosed事件,点击不接受和右上角叉号 返回数据cancle (只要不是点击接受关闭的子页面)
@Override
public void beforeClosed(BeforeClosedEvent e) {
super.beforeClosed(e);
AbstractFormView formView = (AbstractFormView) e.getSource();
if (formView != null) {
try {
//反射获取属性值,当属性值为空时,说明点击的不是接受按钮操作
//因为returnToParentData在AbstractFormView 中的访问属性是protected类型
Object returnToParentData = ClassUtil.getPropertyValue(formView, "returnToParentData");
if (returnToParentData == null) {
//关闭页面,默认就是取消操作
this.getView().returnDataToParent("cancle");
}
} catch (IllegalAccessException illegalAccessException) {
illegalAccessException.printStackTrace();
}
}
}
反射工具类:
ClassUtil {
Object (Object objString propertyName) IllegalAccessException {
Class<?> Clazz = obj.getClass()Field field((field = (ClazzpropertyName)) == )
field.setAccessible()field.get(obj)}
Field (Class<?> clazzString propertyName) {
(clazz == )
{
clazz.getDeclaredField(propertyName)} (NoSuchFieldException e) {
(clazz.getSuperclass()propertyName)}
}
}
4):父页面插件:重写closecallback事件,监听子页面返回参数,做对应逻辑处理
@Override
public void closedCallBack(ClosedCallBackEvent closedCallBackEvent) {
super.closedCallBack(closedCallBackEvent);
if (StringUtils.equals(closedCallBackEvent.getActionId(), KEY_SURE)) {
String data = (String) closedCallBackEvent.getReturnData();
if (data != null && !data.isEmpty() && "sure".equals(data)) {//返回字符串为sure时
//点击接受按钮后的处理逻辑
}else if (data != null && !data.isEmpty() && "cancle".equals(data)) {//返回字符串为cancle时
//点击不接受或关闭按钮后的处理逻辑
}
}
}
推荐阅读