码迷,mamicode.com
首页 > 其他好文 > 详细

ofbiz进击 第四节。 我的form之旅

时间:2015-04-28 17:29:59      阅读:313      评论:0      收藏:0      [点我收藏+]

标签:

一般使用ofbiz做后台管理的时候,多数会使用ofbiz的form去做后台。下面我就总结下我在使用form的时候的一些总结与问题吧。
1.首先,我们看如何使用最简单form去查询某个单个的对象,并对其进行显示。
如下:
< form name= "returnHeaderReason" type = "single" default-map-name ="returnHeader" >
       <actions >
                   <entity-one value-field = "returnHeader" entity-name= "ReturnHeader" >
                         <field-map field-name = "returnId" from-field= "parameters.returnId" />
                   </entity-one >
       </actions >
       <field name = "returnReason" title= "退货理由" ><display ></display ></field >
    </form > 
只需要在actions标签里面   使用entity-one  然后通过field-map 去根据returnId 去查询到一条记录
然后使用default-map-name 的方式,去制定默认的映射方式(则为查询出来的entity的name),field则为要展示的列名。
如果有的时候要展示全部的列  可以根据
 < auto-fields-entity entity-name = ""/>< auto-fields-service service-name = ""/>
这两个标签去根据实体或者服务去自动展现出所有的相关的列。
上述的为最简单的单个对象的展示方式,下面我列举一张单表的列表为大家呈现一下ofbiz所提供列表展示功能。
 
< form name= "listReturnItem" type = "list" list-name= "listReturnItems" 
             odd-row-style= "alternate-row" header-row-style ="header-row-2" default-table-style = "basic-table hover-bar">     
             <actions >
                   <entity-and entity-name = "ReturnItem" use-cache= "false" list= "listReturnItems" >
                        <field-map field-name = "returnId" from-field= "parameters.returnId" />
                       </entity-and >     
             </actions >
        <field name = "returnQuantity" title= "退货数量" ><display ></display ></field >
        <field name = "returnPrice" title= "退货单价" ><display ></display ></field >
        <field name = "returnTotalPrice" title= "退货金额" ><display ></display ></field >
    </form >  
同样的道理,这里通过actions 标签里面的entity-and标签查询出来所需要的列表,列表名称为listReturnItems  合格的List 要跟form的list-name保持一致即可,这里不能写default-map-name,如果写了这个映射标签,当使用row-actions的时候,获取单行的某个属性的时候,调用的将不会是单行的对象,而是default-map-name所制定的对象。现在,一个单表的列表已经能够显示出来了。可是,如果要显示一个多表联合查询的结果,又该怎么处理呢?就是我刚刚所说的  <row-actions > 这个标签。
< row-actions>
      <script location= "component://portal/webapp/portal/WEB-INF/actions/returnOrder/listReturnItem.groovy" />
</row-actions >
给上述的form加上一个row-actions标签,则代表每行将调用的groovy。接下来我贴出来的是最简单的groovy.(groovy采用的是java语言类似的编写风格,具体的我在以后的学习中会继续跟大家分享)
if (!productId) return;
product = delegator.findOne ("Product" ,[productId:productId], false);
productDescription = product. get("description" )
context. productDescription = productDescription 
上述的代码是判断productId是否存在,如果不存在,则返回,如果存在,则通过delegator的findOne方法去查询出product对象,然后获取对应的商品描述,将商品描述赋给context,这样在form里面就可以添加一行显示列了 
<field name = "productDescription" title= "商品描述" ><display ></display ></field >
上面我给大家分享的是没有分页的多列表格,如果需要分页功能,我们又该如何处理,别急,下面就为大家展示。
首先要知道,在ofbiz里面使用分页,肯定要分为两个form,一个是上面的查询的form 一个是下面的列表form .
 
 < decorator-section name = "body">
                         <section >
                               <widgets >
                                    <decorator-screen name= "FindScreenDecorator" location= "component://common/widget/CommonScreens.xml" >
                                        <decorator-section name= "search-options" >
                                            <include-form name= "SearchReturnOrder" location= "component://portal/widget/ReturnOrderForms.xml" />
                                        </decorator-section >
                                           <decorator-section name= "search-results" >
                                            <include-form name= "ListReturnOrder" location= "component://portal/widget/ReturnOrderForms.xml" />
                                        </decorator-section >      
                                    </decorator-screen >
                               </widgets >
                         </section >
                    </decorator-section >
上面的就是分别是实现分页的两个form,我先贴出的是查询form的代码
< form name= "SearchReturnOrder" target = "ListReturnOrder" title= "" type= "single"
          header-row-style= "header" default-table-style = "basic-table talbe_left_padding">
        <field name = "noConditionFind">< hidden value= "Y" /></field >
        <field name = "returnId">< text ></text ></field >
       <field name = "statusId" title= "${uiLabelMap.CommonStatus}">
            <drop-down allow-empty = "true">
                <entity-options entity-name = "StatusItem" description= "${description}" >
                    <entity-constraint name = "statusTypeId" operator= "equals" value = "ORDER_RETURN_STTS"/>
                </entity-options >
            </drop-down >
        </field >
        <field name = "createdStamp_fld0_value" title= "申请开始时间" >
             <date-time type = "date"/>
        </field >
        <field name = "createdStamp_fld0_op">
             <hidden value = "greaterThanFromDayStart"/>
        </field >
        <field name = "createdStamp_fld1_value" title= "申请结束时间" >
             <date-time type = "date"/>
        </field >
        <field name = "createdStamp_fld1_op">
             <hidden value = "upThruDay"/>
        </field >
       <field name = "searchButton" title= "${uiLabelMap.CommonFind}" widget-style= "smallSubmit" ><submit button-type = "button"/></ field>
    </form > 
该form可能涉及了很多别的内容,如果大家为初学者,可以耐心的听我分析每一个标签,如果您不是初学者,您完全不用看本文章,这完全是我自己写给我自己的学习进阶分析 ,目的是为了帮助初学者分析以及自己日后的查看而已。
在field中,可以添加标签来表示该field的表现形式。例如drop-down  就表示该字段以下拉框的形式展示
entity-name 标示下拉框要查询的对象名, description 标示要展示的字段。如果不写  
<entity-constraint name = "statusTypeId" operator= "equals" value = "ORDER_RETURN_STTS"/>
这个标签的话,则标示将会查询出表status_item里面所有的数据。 上面的这个标签的作用就是起到过滤的作用,标示 只显示 字段 statusTypeId equals ORDER_RETURN_STTS 的数据。       
<field name = "createdStamp_fld0_value" title= "申请开始时间" >
             <date-time type = "date"/>
        </field >
        <field name = "createdStamp_fld0_op">
             <hidden value = "greaterThanFromDayStart"/>
        </field >

  

这是一对一起使用的标签,表示 createdstamp 字段显示格式为date日期形式,当执行查询的时候,会根据 greaterThanFromDayStart 去查询大于当天开始的时间。
有人可能会为这是为什么,具体的你可以 到 /emt/framework/common/src/org/ofbiz/common/FindServices.java 这个类中去查看是如何映射的。可以说说这是ofbiz的一种映射机制吧。
以上的是一些常用的标签,然后查询这个form 要跟列表做集成的话,只需要在target中指定ListReturnOrder 即列表的查询control的方式。
 
 

ofbiz进击 第四节。 我的form之旅

标签:

原文地址:http://www.cnblogs.com/wangqc/p/ofbiz_form.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!