Windchill 10,11最简单的MVC例子

Windchill 10,11最简单的MVC例子

为了赚点积分,教程和原文件在 

https://download.csdn.net/download/leiqianhong/16752540

目标

  1. 增加了一二级菜单,菜单增加了图标,汉字等。
  2. 使用MVC产生了JSP,TABLE,
  3. 使用搜索字段,产生搜索结果

 

大概的过程是

  1. 增加菜单:修改codebase/config/actions/custom_models.xml和custom_actions.xml
  2. 定义MVC和builder: 修改 codebase/config/mvc/custom.xml
  3. Eclipse中编写资源文件
  4. Eclipse中编写编写MVC中的View 也是Builder
  5. 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"%>

这是WINDCHILLJSP差不多需要引用的部份

<%@ 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" />

 

这个 idname最好一致。它要到用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中的表格

        

   } 

 

  • 2
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
Windchill MVC(Model-View-Controller)组件是PTC公司开发的一种用于风寒平台的软件架构模式。MVC是一种常见的软件开发模式,它将一个应用程序分为三个核心部分:模型(Model)、视图(View)和控制器(Controller)。 在Windchill MVC组件中,模型是应用程序的核心部分,负责处理数据和业务逻辑。模型是一个独立于用户界面的组件,它封装了应用程序的核心数据和相关操作。模型通常包含访问数据库、处理数据验证和计算等功能。 视图是用户界面的组件,负责展示模型中的数据给用户。视图向用户提供了一个交互界面,通过它用户可以与模型进行交互。视图通常包含了用户界面的布局、样式和交互元素。 控制器是模型和视图之间的协调者,负责处理用户的输入和响应。控制器接收用户的输入,并将其传递给相应的模型进行处理,然后更新视图以反映模型的状态和结果。控制器还负责将模型和视图解耦,使它们可以独立于彼此进行修改和扩展。 Windchill MVC组件的使用有助于提高软件的可维护性和可扩展性。通过将应用程序分成不同的组件,每个组件都负责特定的功能,便于团队的协作开发和代码重用。此外,MVC的分层结构还能够使软件的不同部分相对独立,使得改变一个组件不会对其他组件造成影响。 总之,Windchill MVC组件是一种软件架构模式,将应用程序分为模型、视图和控制器三个部分,提高了软件的可维护性和可扩展性。它适用于在风寒平台上开发的软件。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值