วันพุธที่ 20 ตุลาคม พ.ศ. 2553

การเขียน beanshell เพื่อคำนวนค่าใน row-actions

ใน OFBiz เราสามารถคำนวนค่าใดๆ ในแต่ละแถวของการแสดงผลของ form ได้ โดยใช้คำสั่ง beanshell script ใน action หรือ row-actions ของ form ดังนี้

<row-actions>
            <set field="estimatedTotalMilliSeconds" value="${bsh:estimatedMilliSeconds * quantity}" type="BigDecimal"/>
</row-actions>

จากโค้ด ได้ทำการคำนวน โดยการนำค่าของ estimatedMilliSeconds มาทำการคูณกับ quantity แล้วเก็บไว้ในตัวแปร estimatedTotalMilliSeconds
โดยหากใช้คำสั่ง <row-actions> นั่นจะหมายถึง มีการคำนวนค่านี้ในทุกแถวที่มีการ process ค่านี้ออกมา

วันจันทร์ที่ 18 ตุลาคม พ.ศ. 2553

การเรียงลำดับฟิล์ดในฟอร์มของ OFBiz

ใน form ของ OFBiz แล้ว บางครั้งการวางตำแหน่งของโค้ดตามลำดับก่อนหลัง ไม่ใช่ลำดับของการแสดงผลก่อนหลังของฟอร์มแต่อย่างใด หากต้องการเรียงลำดับฟิล์ดให้ได้ตามต้องการแล้ว ควรเพิ่มโค้ดของ <sort-order></sort-order> ไว้ก่อนจะจบฟอร์มด้วย ดังนี้

<form default-map-name="partyGroup" default-table-style="basic-table" focus-field-name="groupName" header-row-style="header-row" name="EditDepartment" target="updatePartyGroup" type="single">
    <field name="groupName" title="${uiLabelMap.DepartmentName}" tooltip="${uiLabelMap.CommonRequired}" widget-style="required"></field>
    <field name="partyId" title="${uiLabelMap.Department}" tooltip="${uiLabelMap.CommonRequired}" widget-style="required"><text></text></field>
    <field name="description" title="${uiLabelMap.CommonDescription}"><text></text>
    <field name="annualRevenue" title="${uiLabelMap.iMAS_AnnualRevenue}"><text></text>
    <field name="numEmployees" title="${uiLabelMap.iMAS_NumberOfEmployees}"><text></text>
<sort-order>
        <sort-field name="groupName"/>
        <sort-field name="description"/>
        <sort-field name="numEmployees"/>
        <sort-field name="annualRevenue"/>
        <sort-field name="partyId"/>
</sort-order>
</form>

การเขียนในรูปแบบนี้ ถึงแม้ว่าจะเรียงลำดับฟิล์ดในฟอร์มดังนี้
1. groupName
2. partyId
3. description
4. annualRevenue
5. numEmployees

แต่เวลาแสดงผลในฟอร์ม จะแสดงผลตามลำดับที่บังคับไว้ใน sort-order ดังนี้
1. groupName
2. description
3. numEmployees
4. annualRevenue
5. partyId