Windchill 10,11最简单的MVC例子
为了赚点积分,教程和原文件在
https://download.csdn.net/download/leiqianhong/16752540
目标
- 增加了一二级菜单,菜单增加了图标,汉字等。
- 使用MVC产生了JSP,TABLE,
- 使用搜索字段,产生搜索结果
大概的过程是
- 增加菜单:修改codebase/config/actions/custom_models.xml和custom_actions.xml
- 定义MVC和builder: 修改 codebase/config/mvc/custom.xml
- Eclipse中编写资源文件
- Eclipse中编写编写MVC中的View 也是Builder
- NotePad+ 编写对应的jsp
是直接编写codebase/config/ 下面的文件,
还是使用src还是wtSafeArea还是wtCustom方式,自己决定。
结果图
对于一二级菜单的XML和分析
CUSTOM_MODELS.XML需要增加的地方,,红字部份,不要直接就用,要放到自己需要的地方.
<model name="main navigation" id="browseActions" resourceBundle="com.ptc.core.ui.navigationRB">
<description>
Main navigation (tabs)
</description>
<action name="LeiqhReport" type="navigation"/>
</model>
<model name="LeiqhReport navigation" resourceBundle="ext.leiqh.resource.LeiqhResourceRB">
<action name="LeiqhSearch01" type="LeiqhFirst" />
<action name="LeiqhSearch02" type="LeiqhFirst" />
<submodel name="LeiqhSub"/>
</model>
<model name="LeiqhSub" resourceBundle="ext.leiqh.resource.LeiqhResourceRB">
<action name="LeiqhSub01Action01" type="LeiqhSub01"/>
<action name="LeiqhSub01Action02" type="LeiqhSub01"/>
<action name="LeiqhSub01Action03" type="LeiqhSub01"/>
</model>
custom_actions.xml需要增加的地方
<objecttype name="navigation" class="" resourceBundle="ext.leiqh.resource.LeiqhResourceRB">
<action name="LeiqhReport"></action>
</objecttype>
<objecttype name="LeiqhFirst" class="" resourceBundle="ext.leiqh.resource.LeiqhResourceRB">
<action name="LeiqhSearch01" >
<command url="/netmarkets/jsp/ext/leiqh/leiqhfirst/LeiqhSearch01.jsp" windowType="page" />
</action>
<action name="LeiqhSearch02" >
<command url="/netmarkets/jsp/ext/leiqh/leiqhfirst/LeiqhSearch02.jsp" windowType="page" />
</action>
</objecttype>
<objecttype name="LeiqhSub01" class="" resourceBundle="ext.leiqh.resource.LeiqhResourceRB">
<action name="LeiqhSub01Action01" >
<command url="/netmarkets/jsp/ext/leiqh/leiqhsub01/LeiqhSub01Action01.jsp" windowType="page" />
</action>
<action name="LeiqhSub01Action02" >
<command url="/netmarkets/jsp/ext/leiqh/leiqhsub01/LeiqhSub01Action02.jsp" windowType="page" />
</action>
<action name="LeiqhSub01Action03" >
<command url="/netmarkets/jsp/ext/leiqh/leiqhsub01/LeiqhSub01Action03.jsp" windowType="page" />
</action>
</objecttype>
MODELS.XML的分析
<model name="main navigation" id="browseActions" resourceBundle="com.ptc.core.ui.navigationRB">
<description>
Main navigation (tabs)
</description>
<action name="LeiqhReport" type="navigation"/>
</model>
Type为navigation ,action name 是LeiqhReport 这是进行定义
再来看
<model name="LeiqhReport navigation" resourceBundle="ext.leiqh.resource.LeiqhResourceRB">
<action name="LeiqhSearch01" type="LeiqhFirst" />
<action name="LeiqhSearch02" type="LeiqhFirst" />
<submodel name="LeiqhSub"/>
</model>
所以产生的model name 是LeiqhReport navigation 即第1级的actionname+空格+类型
定义自己的资源文件ext.leiqh.resource.LeiqhResourceRB
再增加了2个导航LeiqhSearch01和LeiqhSearch02,类型都是 LeiqhFirst
<submodel name="LeiqhSub"/> 是一个折叠菜单,名称是LeiqhSub
<model name="LeiqhSub" resourceBundle="ext.leiqh.resource.LeiqhResourceRB">
<action name="LeiqhSub01Action01" type="LeiqhSub01"/>
<action name="LeiqhSub01Action02" type="LeiqhSub01"/>
<action name="LeiqhSub01Action03" type="LeiqhSub01"/>
</model>
对这个LeiqhSub 再进行注解,资源文件也是ext.leiqh.resource.LeiqhResourceRB
增加了3个菜单LeiqhSub01Action01, LeiqhSub01Action02, LeiqhSub01Action03,类型是LeiqhSub01
再来对cutome_actions.xml进行分析。
<objecttype name="navigation" class="" resourceBundle="ext.leiqh.resource.LeiqhResourceRB">
<action name="LeiqhReport"></action>
</objecttype>
由于增加的第1级是LeiqhReport 类型是 navigation ,所以要这样定义
资源文件是ext.leiqh.resource.LeiqhResourceRB
<objecttype name="LeiqhFirst" class="" resourceBundle="ext.leiqh.resource.LeiqhResourceRB">
<action name="LeiqhSearch01" >
<command url="/netmarkets/jsp/ext/leiqh/leiqhfirst/LeiqhSearch01.jsp" windowType="page" />
</action>
<action name="LeiqhSearch02" >
<command url="/netmarkets/jsp/ext/leiqh/leiqhfirst/LeiqhSearch02.jsp" windowType="page" />
</action>
</objecttype>
由于 类型是LeiqhFirst ,再定义 action name和它们指向的command路径
资源文件也是ext.leiqh.resource.LeiqhResourceRB
<objecttype name="LeiqhSub01" class="" resourceBundle="ext.leiqh.resource.LeiqhResourceRB">
<action name="LeiqhSub01Action01" >
<command url="/netmarkets/jsp/ext/leiqh/leiqhsub01/LeiqhSub01Action01.jsp" windowType="page" />
</action>
<action name="LeiqhSub01Action02" >
<command url="/netmarkets/jsp/ext/leiqh/leiqhsub01/LeiqhSub01Action02.jsp" windowType="page" />
</action>
<action name="LeiqhSub01Action03" >
<command url="/netmarkets/jsp/ext/leiqh/leiqhsub01/LeiqhSub01Action03.jsp" windowType="page" />
</action>
</objecttype>
同样,有折叠菜单的,也同样定义
类型LeiqhSub01 ,再是各个菜单和执行的路径
对于资源文件的说明
名称分别是
LeiqhResourceRB和LeiqhResourceRB_zh_CN 简体中文
简体中文多了_zh_CN
import wt.util.resource.RBEntry;
import wt.util.resource.WTListResourceBundle;
public class LeiqhResourceRB extends WTListResourceBundle
{
@RBEntry("Leiqh的导航条")
public static final String navigation_LeiqhReport_title = "navigation.LeiqhReport.title";
@RBEntry("Leiqh的导航条")
public static final String navigation_LeiqhReport_tooltip = "navigation.LeiqhReport.tooltip";
@RBEntry("Leiqh的导航条")
public static final String navigation_LeiqhReport_description = "navigation.LeiqhReport.description";
@RBEntry("spatial_filter_proximity_82x82.png")
public static final String navigation_LeiqhReport_icon = "navigation.LeiqhReport.icon";
}
@RBEntry("Leiqh的导航条")
说明返回的汉字或是英文字符或是图片
navigation_LeiqhReport_title 进行区分的字符,最好要有意义
navigation.LeiqhReport.title
表名是
类型.actionname.+title或是tooltip或是description 或是icon
图标文件的路径问题
如果什么都不写同则指向的是netmarkets/images/ 这个路径,注意是/
@RBEntry("add16x16.gif")
对应的路径是 netmarkets/images/add16x16.gif
@RBEntry("test/navigationList.png"
则对应的是 netmarkets/images/test/ navigationList.gif
包的路径定义
Ext开头,leiqh本人,以免与系统本有的包区分
资源包的是ext.leiqh.resource
Mvc的view包是ext.leiqh.mvc.view
MVC的定义
在codebase/config/mvc/custom.xml中则要增加CLASS的定义
<bean class="ext.leiqh.mvc.view.LeiqhSearch01Builder"/>
Mvc的一个builder是
@ComponentBuilder(value = "ext.leiqh.mvc.view.LeiqhSearch01")
public class LeiqhSearch01Builder extends AbstractComponentBuilder
定义了value是ext.leiqh.mvc.view.LeiqhSearch01
JSP调用时,要用到这个
@Override
public Object buildComponentData(ComponentConfig arg0, ComponentParams param) throws Exception
{
// TODO Auto-generated method stub
ArrayList<WTPart> returnList = new ArrayList<WTPart>();
String partNumber = (String) param.getParameter("partNumber");
if (partNumber != null && (partNumber.length() > 0))
{
partNumber = partNumber.trim();
// 再查询
returnList = getPartByNumber(partNumber);
}else
{
returnList = getPartByNumber("0");
}
return returnList;
}
返回的对象是ArrayList<WTPart> 这个集合。
String partNumber = (String) param.getParameter("partNumber");
这里用于从JSP搜索传过来的参数.
默认或是空值时,显示所有PART对象
getPartByNumber(partNumber)
是自己定义的一个搜索函数。
public ArrayList getPartByNumber(String number)
{
ArrayList<WTPart> returnList = new ArrayList<WTPart>();
try
{
QuerySpec qs = new QuerySpec(WTPart.class);
SearchCondition sc = new SearchCondition(WTPart.class, WTPart.NUMBER, SearchCondition.LIKE, "%" + number + "%");
qs.appendWhere(sc);
QueryResult qr1 = PersistenceHelper.manager.find(qs);
while (qr1.hasMoreElements())
{
WTPart part = null;
part = (WTPart) qr1.nextElement();
returnList.add(part);
}
} catch (Exception e)
{
e.printStackTrace();
}
return returnList;
}
对WTPart.class 进行搜索,字段是WTPart.NUMBER,方式是 模糊
即: 编号中 含有搜索的。 要使用%% 进行包裹。
JSP的说明
LeiqhSearch01.jsp
<%@ taglib prefix="jca" uri="http://www.ptc.com/windchill/taglib/components"%>
<%@ include file="/netmarkets/jsp/util/begin.jspf"%>
<%@ taglib prefix="mvc" uri="http://www.ptc.com/windchill/taglib/jcaMvc"%>
<%@ taglib prefix="wrap" uri="http://www.ptc.com/windchill/taglib/wrappers"%>
<%@ taglib tagdir="/WEB-INF/tags" prefix="wctags"%>
<%@ page import="java.util.ArrayList"%>
<%@ page import="java.util.ResourceBundle"%>
LeiqhSearch01
<%
String str="\u6b65\u9aa41";
%>
<%=str%>
<fieldset class="x-fieldset x-form-label-left"
id="Visualization_and_Attributes" style="width: 1024px;">
<table>
<tr>
<td height="25" width="180" align="right" >
<font size="3" color="red">*partNumber</font>
</td>
<td><input type="text" id="partNumber" name="partNumber" /></td>
</tr>
<tr>
<td height="25" width="180" align="right" >
<font size="3" color="blue">Commit</font>
</td>
<td colspan="22" align="right">
<wrap:button name="search"
value='Start Search'
οnclick="submitDocSearch();" />
</td>
</tr>
</table>
</fieldset>
<mvc:tableContainer compId="ext.leiqh.mvc.view.LeiqhSearch01" height="600" />
<script>
function submitDocSearch(){
submitParameters();
}
function submitParameters() {
var partNumber = document.getElementById('partNumber').value;
var params = {
partNumber : partNumber};
PTC.jca.table.Utils.reload('ext.leiqh.mvc.view.LeiqhSearch01', params, true);
}
</script>
<%@ include file="/netmarkets/jsp/util/end.jspf"%>
分析
<%@ taglib prefix="jca" uri="http://www.ptc.com/windchill/taglib/components"%>
<%@ include file="/netmarkets/jsp/util/begin.jspf"%>
<%@ taglib prefix="mvc" uri="http://www.ptc.com/windchill/taglib/jcaMvc"%>
<%@ taglib prefix="wrap" uri="http://www.ptc.com/windchill/taglib/wrappers"%>
<%@ taglib tagdir="/WEB-INF/tags" prefix="wctags"%>
<%@ page import="java.util.ArrayList"%>
<%@ page import="java.util.ResourceBundle"%>
这是WINDCHILL的JSP差不多需要引用的部份
<%@ taglib prefix="jca" uri="http://www.ptc.com/windchill/taglib/components"%>
<%@ taglib prefix="mvc" uri="http://www.ptc.com/windchill/taglib/jcaMvc"%>
<%@ taglib prefix="wrap" uri="http://www.ptc.com/windchill/taglib/wrappers"%>
注意这3条是<jca,<mvc和 <wrap要用到申义。
定义一个输入框
<input type="text" id="partNumber" name="partNumber" />
这个 id和name最好一致。它要到用JAVASCRIP传参给VIEW的类
<wrap:button name="search"
value='Start Search'
οnclick="submitDocSearch();" />
增加了一个按钮,触发submitDocSearch()
function submitDocSearch(){
submitParameters();
执行函数submitParameters
}
function submitParameters() {
var partNumber = document.getElementById('partNumber').value;
从页面中得到partNumber ,它要传给VIEW中的Builder类
var params = {
partNumber : partNumber};
把参数打包,好像是 JSON字符串
PTC.jca.table.Utils.reload('ext.leiqh.mvc.view.LeiqhSearch01', params, true);
类似AJAX,通过 "ext.leiqh.mvc.view.LeiqhSearch01" 找到定义的类LeiqhSearch01Builder
刷新JSP中的表格
}