zoukankan      html  css  js  c++  java
  • ofbiz进击 第四节。 我的form之旅

    一般使用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的方式。
     
     1 <form name="ListReturnOrder" target="" title="" list-name="listIt" type="list" paginate-target="ListReturnOrder"
     2         odd-row-style="alternate-row" header-row-style="header-row-2" default-table-style="basic-table hover-bar jointd">
     3         <actions>
     4             <service service-name="performFind" result-map="result" result-map-list="listIt">
     5                 <field-map field-name="inputFields" from-field="parameters"/>
     6                 <field-map field-name="entityName" value="ReturnHeader"/>
     7                 <field-map field-name="orderBy" from-field="parameters.sortField"/>
     8                 <field-map field-name="viewIndex" from-field="viewIndex"/>
     9                 <field-map field-name="viewSize" from-field="viewSize"/>
    10             </service>
    11         </actions>
    12         <row-actions>
    13             <script location="component://portal/webapp/portal/WEB-INF/actions/returnOrder/listReturnOrder.groovy"/>
    14         </row-actions>
    15         <field name="returnId" title="退货单号"><display/></field>
    16         <field name="createdStamp" title="申请时间" sort-field="true"><display/></field>
    17         <field name="orderId" title="原订单号">
    18             <display/>
    19         </field>
    20         <field name="fromPartyId" title="申请人">
    21             <display/>
    22         </field>
    23         <field name="totalPrice" title="总金额">
    24             <display/>
    25         </field>
    26         <field name="statusId" title="退货单状态" sort-field="true">
    27             <display-entity entity-name="StatusItem" key-field-name="statusId" description="${description}"/>
    28         </field>
    29         <field name="backLink" title="退回" widget-style="buttontext" use-when="&quot;RETURN_REQUESTED&quot;.equals(statusId)">
    30             <hyperlink target="backReturnOrder" description="退回" confirmation-message="确认要退回该退货单?">
    31                 <parameter param-name="returnId"/>
    32             </hyperlink>
    33         </field>
    34         <field  name="acceptLink" title="审核" widget-style="buttontext" use-when="&quot;RETURN_REQUESTED&quot;.equals(statusId)">
    35             <hyperlink target="acceptReturnOrder" description="审核" confirmation-message="确认提交审核?">
    36                 <parameter param-name="returnId"/>
    37             </hyperlink>
    38         </field>
    39         <field name="viewLink" title="查看" widget-style="buttontext">
    40             <hyperlink target="viewReturnOrder" description="查看">
    41                 <parameter param-name="returnId"/>
    42                 <parameter param-name="orderId"/>
    43             </hyperlink>
    44         </field>
    45     </form>
    View Code

    上面的代码是列表List的代码,需要注意的点是 list-name 的属性一定要是listlt 才行, performFindList 因为这个服务调用的org.ofbiz.common.FindServices类里面的performFindList实现方法,在这个方法里面,是获取reslut名称为listLt的数据的,个人感觉这里面的确不合理,但是既然ofbiz这样做了,一定有它自己的道理,这里就不深究了。然后在讲一下这边的按钮,这三个按钮的话,如果想在同一列里面,就需要自己去写jquery去实现列的整合。这种简单的操作(主要不属于ofbiz的内容)我就不再贴出代码了。

    下面在介绍一个List里面存在的标签

    <alt-target use-when="contactListParty==null" target="createContactListParty"/>
    

    这个标签多数用于编辑与新增的form里面,是用来判断对象是否存在的,如果对象不存在的情况下,就修改form的target属性。  

     
  • 相关阅读:
    yii框架中的各种小问题
    yii框架无限极分类的做法
    yii框架中的下拉菜单和单选框
    yii框架定时任务的操作
    yii框架里DetailView视图和GridView的区别
    git的使用(1)
    mysql 连接问题
    PHP字符串函数
    phpdocmentor 生成php 开发文档(转载)
    使用Nginx的X-Accel-Redirect实现大文件下载
  • 原文地址:https://www.cnblogs.com/wangqc/p/ofbiz_form.html
Copyright © 2011-2022 走看看