XWorker
简介
特点
下载

 面向事物
面向事物的概念
面向事物和面向对象对比
面向事物的哲学

 示例
事物的创建过程 
SWT
WEB
代码生成
YahooYUI

 关于
协议
联系我们

 

 WEB编程示例

WEB编程的相关事物

    WEB编程一般会用到WebControl、界面等事物,在XWorker中web应用也很普遍,比如事物管理器中的帮助、信息提示等都使用到web应用。

    这里要讲述的示例是www.xworker.org网站的主页是如何定义的。

认识WebControl

    WebControl是实现了httpDo方法的事物,任何实现了httpDo方法的事物都可以看作是WebControl,其中SimpleControl是用的比较多的一个Webcontrol。

    SimpleControl使用XML表示大致如下:

<thing description="&lt;p&gt;一个简单的WebControl,可以运行脚本并根据脚本返回的结果选择输出。&lt;/p&gt;
&lt;p&gt;SimpleControl的动作名约定为doAction。&lt;/p&gt;" name="SimpleControl" label="SimpleControl" descriptors="core:things:lang.MetaDescriptor3">
    <actions name="scripts">
        <JavaAction code="..." isSynchronized="false" name="httpDo" throwException="true" methodName="run">
            <contexts>
                <PerformanceContext label="HTTP do"/>
            </contexts>
        </JavaAction>
    </actions>
    <thing description="" name="result" label="结果处理" descriptors="core:things:lang.MetaDescriptor3:/@thing">
        <actions name="scripts">
            <JavaAction outerClassName="xworker.ui.http.ResultView" useOuterJava="true" isSynchronized="false" name="doResult" throwException="true" methodName="doResult"/>
            <GroovyAction name="redirect" code="response.sendRedirect(self.value);"/>
            <JavaAction outerClassName="xworker.ui.http.ResultView" useOuterJava="true" isSynchronized="false" name="freemarker" throwException="true" methodName="freemarker"/>
            <JavaAction outerClassName="xworker.ui.http.ResultView" useOuterJava="true" isSynchronized="false" name="form" throwException="true" methodName="form"/>
            <GroovyAction name="excel" code="..."/>
            <GroovyAction name="control" code="..."/>
            <GroovyAction name="template" code="..."/>
        </actions>
        <attribute description="处理类型的名称,是脚本的返回值,通常是success, failuer等字符串。" name="name" label="名称"/>
        <attribute default="form" description="" name="type" label="类型" inputtype="inputSelect">
            <value name="form" value="form" label="表单"/>
            <value name="template" value="template" label="模板"/>
            <value name="freemarker" value="freemarker" label="freemarker模板"/>
            <value name="redirect" value="redirect" label="重定向"/>
            <value name="control" value="control" label="web控制"/>
            <value name="excel" value="excel" label="Excel"/>
            <value name="unset" value="unset" label="未设定"/>
        </attribute>
        <attribute colspan="2" label="ContentType" size="40" inputtype="inputSelect" default="text/html;" description="页面的内容类型。" name="contentType">
            <value name="html" value="text/html;" label="html"/>
            <value name="text" value="text/plain;charset=GBK" label="text"/>
            <value name="word" value="application/msword" label="word"/>
            <value name="excel" value="application/vnd.ms-excel" label="excel"/>
            <value name="pdf" value="application/pdf" label="pdf"/>
        </attribute>
        <attribute colspan="2" inputattrs="type=config" label="值" size="60" inputtype="dataSelector" description="相对于类型的值。" name="value"/>
        <thing description="定义结果处理的参数。" name="param" label="参数" descriptors="core:things:lang.MetaDescriptor3:/@thing">
            <attribute label="参数名" size="10" name="name"/>
            <attribute label="参数值" size="40" inputtype="dataSelector" name="value"/>
        </thing>
        <thing description="" name="region" label="子区域" descriptors="core:things:lang.MetaDescriptor3:/@thing">
            <attribute name="name" label="名称"/>
            <attribute default="form" name="type" label="类型" inputtype="select">
                <value name="form" value="form" label="表单"/>
                <value name="freemarker" value="freemarker" label="freemarker模板"/>
                <value name="control" value="control" label="Web流程定义"/>
                <value name="script" value="script" label="脚本"/>
            </attribute>
            <attribute label="值" size="60" inputtype="dataSelector" name="value"/>
            <actions name="scripts">
                <JavaAction outerClassName="xworker.ui.http.ResultView" useOuterJava="true" isSynchronized="false" name="doRegion" throwException="true" methodName="doRegion"/>
                <JavaAction outerClassName="xworker.ui.http.ResultView" useOuterJava="true" isSynchronized="false" name="form" throwException="true" methodName="form"/>
                <JavaAction outerClassName="xworker.ui.http.ResultView" useOuterJava="true" isSynchronized="false" name="freemarker" throwException="true" methodName="freemarker"/>
                <GroovyAction name="control" code="..."/>
            </actions>
        </thing>
    </thing>
    <actions name="otherScripts">
        <GroovyAction name="init" code="..."/>
    </actions>
    <attribute name="name" label="名称"/>
    <attribute name="label" label="标签"/>
    <attribute colspan="2" label="脚本路径" size="60" inputtype="dataSelector" description="&lt;p&gt;WebControl所执行的脚本,如果是引用其他地方的脚本,那么可以在这里设置,否则可以通过添加脚本子节点来编写脚本,如果没有脚本那么默认的脚本执行结果是success。&lt;/p&gt;" name="scriptPath"/>
    <attribute inputattrs="Width=&apos;480&apos;;Height=&apos;300&apos;;ToolbarSet=&quot;SwtEdit&quot;" label="描述" inputtype="html" name="description"/>
    <thing extends="ui:web:html.base.view" name="forms" label="界面定义" descriptors="core:things:lang.MetaDescriptor3:/@thing"/>
    <thing extends="core:things:lang.MetaDescriptor3:/@actions" description="Control的行为doAction是执行业务的代码。"/>
    <swtMenus/>
</thing>

使用WebControl定义web应用

     使用SimpleContorl来创建WEB应用事物,比如xworker.org网站的主页事物编辑的截图如下:

SimpleControl的表单

SimpleControl的子事物

编辑界面

编辑网页主内容

编辑结果处理

编辑子区域,几个区域凑成一个大网页

    网页事物使用XML表示大致如下:

<SimpleControl name="index">
    <forms otherHeads="..." name="indexPage" belongToHtml="false">
        <htmlCode name="htmlCode" htmlCode="..."/>
    </forms>
    <result name="success" value="core:doc:orgweb.Templates:/@views/@main">
        <region name="head" value="core:doc:orgweb.Templates:/@views/@head"/>
        <region name="menu" value="core:doc:orgweb.Templates:/@views/@menuCommon"/>
        <region name="content" value="core:doc:orgweb.Index:/@index/@indexPage"/>
    </result>
</SimpleControl>

     以上代码中省略了htmlCode的内容,该网页运行效果就是xworker.org的主页效果。

 

Copyright ©  2007-2008 XWorker.org  版权所有

沪ICP备08000575号