创建表单委派 (步骤 5)
大多数更改管理向导步骤在步骤中显示的表和步骤本身之间存在一一映射关系。更改任务向导不同,因为它存在两个表格。每个表格都由其自有的唯一表单委派进行处理。下面列出了表格所支持的表单委派列表。
表名称/步骤名称
支持类名称
受影响对象 (更改任务)
受影响对象 (问题报告、更改报告和超差)
ChangeTaskAffectedItemsFormDelegate
AffectedDataFormDelegate
受影响的成品
AffectedEndItemsFormDelegate
产生的对象
ChangeTaskResultingItemsFormDelegate
关联更改
RelatedChangeItemFormDelegate
受影响的/产生的对象
AffectedAndResultingItemsFormDelegate
建议使用单一表单委派/表格。这样可保持清晰区分步骤与表功能。如果您拥有已嵌入的对象、多个表格或其他使用步骤表单委派的其他方案,则建议将其委派给表格/组件子表单委派。
处理链接的全局属性
要处理更改链接表格的属性 (全局属性或模型化属性),需要以下内容:
1. 扩展预设表单委派。这为扩展提供了大量 API 和插件点,并处理所有现有属性 (说明、批准的数量、处置等)。
2. 覆盖 processLinkAttributes()。在发生以下事件后调用此方法:
a. 已创建二进制链接。
b. 在链接上设置了类型定义参考。
c. 链接与更改对象一起保存。
* 
此方法的用途是检测需要针对链接修改的属性,执行这些属性更新并返回已修改的所有链接的集合。这些链接随后会保留为集合。
* 
只有在检测到已修改 (或已清除) 时,才需要更新属性,这一点非常重要。
一个新对象 PersistableAdapter,可显著减少处理全局属性所需代码数量。下面的代码示例使用此 API。
ChangeLinkAttributeHelperChangeManagementClientHelper 中的几种方法可能在处理属性和使用可更改参考提取表单数据时很有用。
示例代码
public class DistributingResultingItemsFormDelegate extends
ChangeTaskResultingItemsFormDelegate {
/**
* This method is used to post-process attributes on the change activity
* and change records.
* Note: In the example below we are not checking whether the change
* record is of the type DistributingChangeRecord. This could be done
* by comparing the Type Definition reference of the change record.
* However since this demo is focused on attribute manipulation using the
* new code>LWCNormalzedObject we have left it out for brevity.
*/
@SuppressWarnings("unchecked")
@Override
protected WTCollection processLinkAttributes(ChangeItemIfc item,
WTCollection binaryLinks) throws WTException {
WTCollection modifiedLinks = super.processLinkAttributes(item,
binaryLinks);
if (binaryLinks != null && !binaryLinks.isEmpty() && item instanceof
WTChangeActivity2) {
// The link bean has knowledge of how of link attributes and supports
the JCA interfaces.
ChangeLinkAttributeBean linkBean = ChangeLinkAttributeHelper.
getChangeLinkAttributeBean();
linkBean.setFormData(getObjectBean());
for(Iterator<ChangeRecord2> iter = binaryLinks.persistableIterator(ChangeRecord2.class, true); iter.hasNext(); ) {
ChangeRecord2 record = iter.next();
// The getTableDataValue() will get the attribute from the FORM data
supporting any specific change table handlers
String value = ChangeLinkAttributeHelper.getTableDataValue
(DistributingChangeRecordConstants.DISTRIBUTION_ATTRIBUTE,
ChangeManagementClientHelper.getReference(record.getChangeable2()), linkBean);
// The new LWC API for getting and setting attributes.
PersistableAdapter lwc = new PersistableAdapter(record, null, null, new UpdateOperationIdentifier());
lwc.load(DistributingChangeRecordConstants.DISTRIBUTION_ATTRIBUTE);
Object currentValue = lwc.get(DistributingChangeRecordConstants.
DISTRIBUTION_ATTRIBUTE);
// Only set the attribute if it is different than the current value
if(( value != null && currentValue != null && !value.equals
(currentValue.toString())) || (value == null && currentValue != null) ) {
lwc.set(DistributingChangeRecordConstants.DISTRIBUTION_ATTRIBUTE, value);
lwc.apply();
// calling apply() will require verification, however since this form
delegate is setting the changes we can set it as verified.
try {
record.getPersistInfo().setVerified(true);
} catch (WTPropertyVetoException e) {
e.printStackTrace();
}
modifiedLinks.add(record);
}
}
}
return modifiedLinks;
}
}
覆盖步骤表单委派
要覆盖受影响的/产生的对象向导步骤表单委派:
1. 扩展类 AffectedAndResultingItemsFormDelegate
2. 覆盖方法 getAffectedDataFormDelegate()getResultingDataFormDelegate(),并返回表格的自定义表单委派。
public class CustomAffectedAndResultingItemsFormDelegate extends
AffectedAndResultingItemsFormDelegate {
@Override
public ObjectFormProcessorDelegate getResultingDataFormDelegate() {
return new DistributingResultingItemsFormDelegate();
}
}
这对您有帮助吗?