Chapter 3: Screen Widgets

来源:互联网 发布:快速求斗牛的算法 编辑:程序博客网 时间:2024/05/16 11:38

Conditional Widget

<screen name="ConditionalScreen">         <section>             <condition>                 <if-compare field-name="parameters.show" operator="equals" value="widgets"></if-compare>             </condition>             <actions>                 <set field="blah" value="blih"></set>             </actions>             <widgets>                 <label text="Condition passed. Showing widgets element. Blah is: ${blah}"></label>             </widgets>             <fail-widgets>                 <label text="Condition failed! Showing fail-widgets element. Blah is: ${blah}"></label>             </fail-widgets>         </section>     </screen>

其中,actions和widgets是condition为true时候会运作的内容,fail-widgets是为false时候运行的内容。这类似于if-else的结构。

关于<if-condition>

有如下的条件:

4种logical operators:<and>, <xor>, <or>, <not>

3种permissions-related checks: <if-service-permission> , <if-has-permission>, <if-entity-permission>

5种comparators:<if-validate-method>,  <if-compare>,  <if-compare-field> ,  <if-regexp>, <if-empty>

例:

<condition><not><if-empty field-name="parameters.submit"/></not></condition>

关于<actions>

有如下的action可以使用:

5种data retrieval操作:

<actions>    <entity-one entity-name="Planet" value-name="planet">      <field-map field-name="planetId" env-name="mechMap.postalAddress.planet"/>    </entity-one>    <entity-condition entity-name="Planet" filter-by-date="true" list-name="planets">      <order-by field-name="planetName"/>    </entity-condition>  </actions>

  • <entity-one> - 将会遍历Planet这个Entity,找到planetId为mechMap.postalAddress.planet的record,把他存在变量planet中
  • <entity-condition> - 将Entity Planet中的所有内容pull到list planets中
    • <filter-by-date> - specifies that the query must filter out those records that are not active now
    • <order-by> - pull的record安装planetName升序排序,如果要降序,就field-name="planetName DESC"
  • <entity-and>, 
  • <get-related-one>,  
  • <get-related> 

2种引入business logic的操作:

  • <script> - 使用脚本,如ftl
  • <service>

3种设置值的操作: 

  • <property-map>
    如,在CommonScreen.xml中有这么一段:

<actions>            <!-- base/top/specific map first, then more common map added for shared labels -->                 <property-map resource="LearningUiLabels" map-name="uiLabelMap" global="true"/><property-map resource="CommonUiLabels" map-name="uiLabelMap" global="true"/>
这里的作用实际上是声明了一个全局都可以使用map,用config目录下的LearningUiLabels.xml中的property来初始化,使用这个map的方法如下
<set field="layoutSettings.companyName" from-field="uiLabelMap.LearningCompanyName" global="true"/>                <set field="layoutSettings.companySubtitle" from-field="uiLabelMap.LearningCompanySubtitle" global="true"/>
  • <property-to-field>
  • <set> - 设置一个参数的值

关于<widget>

如下15种内容可以使用:

  • <container> - 自我感觉就是显示的时候起到换行的作用
  • <image>
  • <link>
  • <label>, (以后补充)

关于<fail-widgets>

类似于<widget>,只不过只有在condition为false的时候才会运行里面的代码

关于条件参数的传入

我们有着这样的一行代码

<if-compare field-name="parameters.show" operator="equals" value="widgets"></if-compare>

那么,这个show的值如何传入呢?

通常,我们在URL请求中使用“?”来表示开始传入参数,如:

http://localhost:8080/learning/control/SomeRequest?paramOne=valueOne

如果有多个参数,就用“&”,如:

http://localhost:8080/learning/control/SomeRequest?paramOne=valueOne&paramTwo=valueTwo

Screen Widget Context and Variables

Each screen widget's actions (in <actions> sub-element) operate within their own private context. In that context, all variables are private to that context

有10种对象可以在context中使用:

  • screen - 使用FreeMarker temple载入sub-screen
  • globalContext - 被top level screen本身和它的嵌套窗口共享
  • nullField - 用于数据库空值的判断
  • availableLocales和locale - 用于不同地区语言的选择,新版的OFBiz已经不怎么用的,软件如果不跨国家使用,我觉得这个我们也用不上
  • delegator - 用于与数据库的交互
  • dispatcher - 用于调用OFBiz的service
  • security - 提供一系列安全操作的工具
  • userLogin - 顾名思义,常与security一起使用
  • parameters - 一个request parameters的map,可以得到各个request parameter的值

原创粉丝点击