过程 - 创建自定义业务规则结果操作
以下步骤提供了有关如何创建自定义操作的示例,该自定义操作将对更改通告产生的对象执行一组业务规则并显示结果。用于评估业务规则结果的操作将在更改通告操作菜单中提供。
扩展业务规则结果表格
扩展 AbstractBusinessRulesResultsTable 类并覆盖
getRuleValidationResultSet API 以执行所需的规则集。有关执行业务规则集的详细信息,请参阅
自定义业务规则。以下是自定义业务规则结果表构建器的示例,它将针对更改通告生成的对象执行业务规则。
package com.custom.businessRules.mvc.builders;
@ComponentBuilder("CustomBusinessRulesResultsTable")
public class CustomBusinessRulesResultsTable extends
AbstractBusinessRulesResultsTable {
private static final Logger logger =
LogR.getLogger(CustomBusinessRulesResultsTable.
class.getName());
/**
* {@inheritDoc}
*/
@Override
public RuleValidationResultSet
getRuleValidationResultSet(NmCommandBean commandBean)
throws WTException {
RuleValidationResultSet resultSet = new RuleValidationResultSet();
logger.debug("Get context object.");
NmOid contextOid = commandBean.getActionOid();
if(contextOid.isA(WTChangeOrder2.class)) {
logger.debug("Context object is a change notice.");
BusinessRuleSetBean[] ruleSetBeans = new BusinessRuleSetBean[] {
BusinessRuleSetBean.newBusinessRuleSetBean
("CHANGEABLE_PRE_RELEASE",
ChangeRecord2.class.getName())
};
logger.debug("Executing the CHANGEABLE_PRE_RELEASE rule
set for the change notice resulting objects.");
resultSet = BusinessRulesHelper.
engine.execute(contextOid.getRefObject(),
ruleSetBeans);
}
return resultSet;
}
}
注册自定义表构建器
通过添加以下行可注册构建器 \<windchill>\codebase\config\mvc\custom.xml。
<mvc:builder-scan base-package="com.custom.businessRules.mvc.builders"/>
定义操作
• 定义业务规则结果操作
在 <Windchill>\codebase\config\actions\custom-actions.xml 中定义一个新操作,以启动显示业务规则结果的弹出窗口。
<objecttype name="customBusinessRules"
resourceBundle="com.custom.customClientActionsRB">
<action name="customBusinessRulesResultWizard">
<command windowType="popup"/>
</action>
</objecttype>
@RBEntry("View Rule Conflicts")
@RBComment("Title of the wizard that displays business rules results")
public static final String PRIVATE_CONSTANT_0 =
"customBusinessRules.customBusinessRulesResultWizard.description";
@RBEntry("View Rule Conflicts")
@RBComment("Title of the wizard that displays business rules results")
public static final String PRIVATE_CONSTANT_1 =
"customBusinessRules.customBusinessRulesResultWizard.title";
@RBEntry("View Rule Conflicts")
@RBComment("Title of the wizard that displays business rules results")
public static final String PRIVATE_CONSTANT_2 =
"customBusinessRules.customBusinessRulesResultWizard.tooltip";
@RBEntry("width=940,height=600")
@RBPseudo(false)
@RBComment("DO NOT TRANSLATE")
public static final String VIEW_CONFLICTS_MOREURLINFO =
"customBusinessRules.customBusinessRulesResultWizard.moreurlinfo";
• 定义业务规则结果表格步骤操作
使用上文“定义业务规则结果操作”一节在自定义表构建器中定义的组件 ID,定义一个新操作以在 \<windchill>\codebase\config\actions\custom-actions.xml 中显示业务结果表格。
<objecttype name="customBusinessRules" resourceBundle=
"com.custom.customClientActionsRB">
<action name="customBusinessRulesResultStep">
<component name="CustomBusinessRulesResultsTable"/>
</action>
</objecttype>
定义业务规则结果操作 JSP
为了在启动自定义业务规则时显示表格,需要使用 jsp 文件来定义单步向导。jsp 的名称应与操作的名称相匹配,且应该位于 <Windchill>\codebase\netmarkets\jsp 下与操作对象类型的名称相同的包中。对于在上文的“定义业务规则结果操作”一节中定义的操作,包和名称为:
<Windchill>\codebase\netmarkets\jsp\customBusinessRules\customBusinessRulesResultWizard.jsp
以下 jsp 示例介绍了单步向导,其中包括“定义业务规则结果表格步骤操作”一节中定义的操作。有关说明向导的详细信息,请参阅
Windchill 客户端体系结构向导。
<%@ taglib prefix="jca"
uri="http://www.ptc.com/windchill/taglib/components"%>
<%@ include file="/netmarkets/jsp/components/beginWizard.jspf"%>
<!-- Need to set isWizard and popupWindow to false in
order to display links on number and the info
page action icon. -->
<% request.setAttribute("isWizard","false"); %>
<script src="netmarkets/javascript/businessRules/
businessRulesResultsPlugin.js"></script>
<script type="text/javascript">
<!-- Converts all links to open in new window -->
PTC.onReady(function() {
JCAappendFormHiddenInput(getMainForm(), "popupWindow", "false");
});
</script>
<jca:wizard buttonList="OkCancelWizardButtons">
<jca:wizardStep action="customBusinessRulesResultStep"
type="customBusinessRules"/>
</jca:wizard>
<%@include file="/netmarkets/jsp/util/end.jspf"%>
将业务规则结果操作添加到菜单
必须将新的自定义操作添加到对象操作模型中。\<windchill>\codebase\config\actions\custom-actionModels.xml 可用于添加或覆盖操作模型。以下示例将展示如何将自定义操作添加到更改通告的现有操作模型中:
<actionmodels resourceBundle="com.ptc.windchill.enterprise.
change2.changeManagementActionsRB">
<model name="more change notice row actions"
menufor="wt.change2.WTChangeOrder2">
<description>Change notice row actions</description>
<action name="customBusinessRulesResultWizard"
type="customBusinessRules"/>
.
.
<!-- Existing Actions -->
.
.
</model>
</actionmodels>