แสดงบทความที่มีป้ายกำกับ OFBiz แสดงบทความทั้งหมด
แสดงบทความที่มีป้ายกำกับ OFBiz แสดงบทความทั้งหมด

วันพุธที่ 18 สิงหาคม พ.ศ. 2553

การเพิ่ม filter ในการแสดงรายงานโดยใช้ dojo

โดยปกติการเรียกดู report ของ OFBiz จะมีข้อมูลที่จะต้องแสดงในปริมาณมาก จึงควรมีส่วนที่ให้ผู้ใช้งานสามารถสามารถเลือกดูได้ว่า จะดู report ของส่วนไหน และช่วงเวลาไหน

เพื่อให้ง่ายต่อการใช้งานของผู้ใช้ Imas จึงเลือกที่จะนำเอา Dojo มาสร้าง User Interface ซึ่งจะได้ form ในรูปแบบนี้


จาก form นี้ ผู้ใช้งานสามารถเลือกดู report ได้ว่า ต้องการช่วงไหนบ้าง

การนำเอา dojo มาช่วยใน user interface ในส่วนของ form มีขั้นตอนดังนี้

1. ค้นหารายงานที่ต้องการสร้าง dojo ui เช่น ในส่วนของ Payable - Recievable (เจ้าหนี้-ลูกหนี้) ต้องการสร้าง form แบบ calendar เพื่อให้ผู้ใช้สามารถเลือกช่วงเวลาที่ต้องการแสดงรายงานได้ โดย list ของรายงานเจ้าหนี้-ลูกหนี้ แสดงตาม url นี้
https://localhost:8443/imas-report/control/fourth

2. สร้าง form ของ calendar โดยการสร้างไฟล์ชื่อ ARAccruedInvoiceDialog.ftl ลงในโฟลเดอร์ ofbiz.9.04/hot-deploy/imas-report/webapp/imas-report/report/receivable/page ดังนี้

<form id="ARAccruedInvoiceForm" name="ARAccruedInvoiceForm" dojoType="dijit.form.Form" target="_blank" action="/imas-report/control/ARAccruedInvoice?externalLoginKey=${externalLoginKey}" method="POST">
    <table cellspacing="0">
      <tr>
        <td>${uiLabelMap.CommonFromDate}:</td>
        <td>
            <input id="ARAccruedInvoicefromDate" type="text" name="fromDate" dojoType="dijit.form.DateTextBox" constraints={datePattern:'dd-MM-yyyy'}
            onChange="dijit.byId('ARAccruedInvoicetoDate').constraints.min = arguments[0];"
            />
        </td>
        <td>${uiLabelMap.CommonThruDate}</td>
        <td>
            <input id="ARAccruedInvoicetoDate" type="text" name="toDate" dojoType="dijit.form.DateTextBox" constraints={datePattern:'dd-MM-yyyy'}
            onChange="dijit.byId('ARAccruedInvoicefromDate').constraints.max = arguments[0];"
            />
        </td>
      </tr>
      <tr>
      <td colspan="3">&nbsp;</td>
      </tr>
      <tr>
        <td>&nbsp;</td>
        <td colspan="3">
            <div align="center">
                <button id="ARAccruedInvoicesubmit" name="ARAccruedInvoicesubmitButton" dojoType="dijit.form.Button" type="submit" iconClass="dijitEditorIcon dijitEditorIconSave" onClick="dijit.byId('ARAccruedInvoiceDialog').hide();">${uiLabelMap.CommonSubmit}</button>
                <button id="ARAccruedInvoicecancel" name="cancelButton" dojoType="dijit.form.Button" type="button" iconClass="dijitEditorIcon dijitEditorIconCancel" onClick="javascript:dijit.byId('ARAccruedInvoiceDialog').hide();">${uiLabelMap.CommonCancelled}</button>
            </div>
        </td>
     </tr>
    </table>
</form>

อธิบายโค้ด
ไฟล์ ARAccruedInvoiceDialog.ftl นี้จะสร้างฟอร์มที่มี id = ARAccruedInvoiceForm และ name = ARAccruedInvoiceForm และมี action ไปที่ uri-map ชื่อ ARAccruedInvoice

ทำการสร้าง text field ที่มี id = ARAccruedInvoicefromDate โดยมี dojoType="dijit.form.DateTextBox" เพราะต้องการแสดงผลเป็น calendar ให้ผู้ใช้เลือกวันที่ได้ โดยกำหนด datePattern เป็น dd-MM-yyyy และส่งค่าที่เลือกนี้ไปกับ form

ทำการสร้าง text field ที่มี id = ARAccruedInvoicetoDate โดยมี dojoType="dijit.form.DateTextBox" เพราะต้องการแสดงผลเป็น calendar ให้ผู้ใช้เลือกวันที่ได้ โดยกำหนด datePattern เป็น dd-MM-yyyy และส่งค่าที่เลือกนี้ไปกับ form เช่นกัน

สร้างปุ่มที่มี id="ARAccruedInvoicesubmit" และ name="ARAccruedInvoicesubmitButton" เมื่อมีการกดปุ่มนี้ จะทำการซ่อน form ที่มี id = ARAccruedInvoiceDialog ในไฟล์ iMAS-ReportScreens.xml

สร้างปุ่มที่มี id="ARAccruedInvoicecancel" และ name="cancelButton" เมื่อมีการกดปุ่มนี้ จะทำการซ่อน form ที่มี id = ARAccruedInvoiceDialog ในไฟล์ iMAS-ReportScreens.xml

3. ที่ controller สร้าง request-map และ view-map ดังนี้
<request-map uri="ARAccruedInvoiceDialog"><security https="true" auth="true"/><response name="success" type="view" value="ARAccruedInvoiceDialog"/></request-map>
<view-map name="ARAccruedInvoiceDialog" type="screen" page="component://imas-report/widget/iMAS-ReportScreens.xml#ARAccruedInvoiceDialog"/>

อธิบายโค้ด
 สร้าง request-map ชื่อ ARAccruedInvoiceDialog ที่มีการเรียกใช้ view-map ชื่อ ARAccruedInvoiceDialog ที่มีการเรียกใช้ screen ชื่อ ARAccruedInvoiceDialog ในไฟล์ imas-report/widget/iMAS-ReportScreens.xml มาแสดงผล

4. ที่ imas-report/widget/iMAS-ReportScreens.xml สร้าง screen ชื่อ ARAccruedInvoiceDialog ดังนี้
<screen name="ARAccruedInvoiceDialog">
        <section>
            <actions>
                <property-map resource="iMAS-ReportUiLabels" map-name="uiLabelMap" global="true"/>
                <property-map resource="iMAS-PurchaseUiLabels" map-name="uiLabelMap" global="true"/>
                <property-map resource="CommonUiLabels" map-name="uiLabelMap" global="true"/>
                <set field="headerItem" value="ARAccruedInvoiceDialog"/>
            </actions>
            <widgets>
                    <platform-specific>
                        <html>
                            <html-template location="component://imas-report/webapp/imas-report/report/receivable/page/ARAccruedInvoiceDialog.ftl"/>
                        </html>
                    </platform-specific>
            </widgets>
        </section>
    </screen>
</screens>

อธิบายโค้ด
สร้าง screen ชื่อ ARAccruedInvoiceDialog ที่ทำการ include ไฟล์ ftl ชื่อ ARAccruedInvoiceDialog.ftl มาแสดงผล

5. แก้ไข link ที่ fourth.ftl เพื่อให้เรียกใช้ screen ชื่อ ARAccruedInvoiceForm ได้
<div class="browsecategorytext"><a href="#" id="ARAccruedInvoiceButton" onclick="javascript:dijit.byId('ARAccruedInvoiceDialog').show();">${uiLabelMap.ARAccruedInvoice} FF</button></div>
<div dojoType="dijit.Dialog" id="ARAccruedInvoiceDialog"  title="${uiLabelMap.ARAccruedInvoice}" href="/imas-report/control/ARAccruedInvoiceDialog?formTarget=ARAccruedInvoice&amp;dialogName=ARAccruedInvoiceDialog" ></div>

อธิบายโค้ด
เมื่อมีการกดลิ้ง จะมีการเรียก ARAccruedInvoiceDialog มาแสดงผล

ในบทความต่อไปจะพูดถึงเรื่องการทำ lookup ให้กับการเลือกดูฟอร์ม โดยใช้ dojo

วันอังคารที่ 27 กรกฎาคม พ.ศ. 2553

การสร้างไฟล์ diff เพื่อทำ patch

บางครั้งในการทำงานในโปรเจ็คท์ต้องมีการแก้ไขไฟล์หลักของ OFBiz โดยเฉพาะไฟล์ในโฟลเดอร์หลัก คือ applications, framework และ specialpurpose ซึ่งเมื่อแก้ไขแล้วหากทำการ commit ขึ้นไปที่ svn หลักของ OFBiz จะเกิดความสับสนกับ framework หลัก ดังนั้นจึงต้องทำไฟล์ .diff เพื่อให้เฉพาะโปรเจ็คท์ที่เราทำเท่านั้นได้ทราบถึงความเปลี่ยนแปลงของไฟล์ สามารถทำไฟล์ .diff ได้ดังนี้

1. ใช้คำสั่งดังนี้ใน terminal

svn diff applications >>/home/toonztudio/Documents/imas_28072010_toon.diff

อธิบายคำสั่ง
ใช้คำสั่ง svn diff เพื่อความแตกต่างของไฟล์ในโฟลเดอร์ applications แล้วสร้างไว้เป็นไฟล์ชื่อ imas_28072010.diff แล้วเก็บไว้ที่ /home/toonztudio/Documents

2. ทำการ copy ไฟล์ชื่อ imas_28072010.diff จาก /home/toonztudio/Documents มาเก็บไว้ใน โฟลเดอร์ patches ของโปรเจ็คท์ ในกรณีนี้คือ /home/toonztudio/Desktop/projects/imaserp/trunk/patches

3. ใช้คำสั่ง svn add ไฟล์ .diff

4. ใช้คำสั่ง svn commit ไฟล์ .diff เข้าสู่ repositories ต่อไป

วันพฤหัสบดีที่ 22 กรกฎาคม พ.ศ. 2553

การแยก column ในหัวตารางของ form

โดยปกติแล้วการแสดงข้อความในตารางควรจะมีหัวตาราง เพื่อแสดงข้อมูลว่าเป็นข้อมูลจากตารางไหน ซึ่งบางครั้งใน OFBiz จะแสดงหัวตารางในลักษณะติดกัน ทำให้ไม่สามารถทราบได้ว่า เป็นข้อมูลจากตารางไหน ดังรูป


ต้องทำการใส่แท็กเพื่อให้แสดงผลเป็นตาราง ดังนี้

separate-columns="true"

จะได้ตารางที่แสดงผลหัวตารางสมบูรณ์

วันจันทร์ที่ 5 กรกฎาคม พ.ศ. 2553

การเพิ่ม auto complete ให้กับ Eclipse

ในกรณีที่ Eclipse ไม่รู้จักคำสั่งใน namespace จะไม่สามารถสร้าง auto complete ได้ สามารถทำการเพิ่ม namespace ได้ ดังนี้

Windows -> Preference -> XML -> XML Catalog

ทำการเพิ่ม namespace เช่น http://ofbiz.apache.org/dtds/widget-screen.xsd
แล้วกด OK

วันอาทิตย์ที่ 4 กรกฎาคม พ.ศ. 2553

การเพิ่ม confirm dialog box ใน form ของ OFBiz 9.04

ใน OFBiz 10.04 การทำ Confirm Dialog Box สามารถใช้ confirmation-message ใน button ได้โดยตรง ดังนี้

<field name="searchButton" title="Search" widget-style="smallSubmit"><submit button-type="button" confirmation-message="Test"/></field>

แต่ใน OFBiz 9.04 ไม่สามารถใช้ confirmation-message ได้ จึงได้ทำการทดลองหาวิธีต่างๆ มาใช้ ดังนี้

ทดลองสร้าง javascript แล้วนำไปใช้กับ onClick ของปุ่มของฟอร์มใน OFBiz ดังนี้
<input type="submit" name="Submit" value="Submit" onClick="fncSubmit()" />

พบว่าไม่สามารถทำได้ เนื่องจาก OFBiz จะทำการ generate แท็ก onSubmit ให้โดยอัติโนมัติดังนี้

onSubmit="javascript:submitFormDisableSubmits(this)"

เมื่อเขียน javascript ที่ปุ่ม submit ของ form ทำให้เกิดการ submit ไปยัง target ของ form ถึงแม้ว่าจะเป็นการกดปุ่ม cancel

ได้รับคำแนะนำจากพี่แซนด์ให้ทำการสร้างปุ่มของฟอร์มในไฟล์ ftl แล้ว include เข้ามาใช้แทนปุ่มของ form โดยตรง จึงได้ทำการสร้างไฟล์ดังนี้

1. สร้างไฟล์ submitButton.ftl โดยมีรายละเอียดดังนี้ (ใช้ dojo มาช่วยในการเขียน javascript ศึกษาเพิ่มเติมได้จาก http://www.dojotoolkit.org/)

<button dojoType="dijit.form.Button" id="btn">Submit
    <script type="dojo/method" event="onClick">showDlg1("FindProject")</script>
</button>

2. ทำการ comment ปุ่มของ form เดิม เพื่อไม่ให้ปุ่มเดิมสามารถทำงานได้
3. เขียนฟังก์ชั่น javascript ในไฟล์ชื่อ testDialog.js ดังนี้

dojo.addOnLoad(function(){
 dojo.parser.parse();
});

function removeThis(){
 this.destroyRecursive()
}

function showDlg1(formIdName){
 var d = new dijit.Dialog({id:'dlg',title:'Dojo Dialogs',content: "<h2>Do you need to do this thing ?</h2>" +
        "<button dojoType='dijit.form.Button' type='submit' id='buttonalertyes' iconClass='mailIconOk' onClick='document." + formIdName + ".submit()'>Yes</button><button dojoType='dijit.form.Button' type='submit' id='buttonalertno' iconClass='mailIconCancel'>No</button>",onExecute:removeThis,onCancel:removeThis});
 d.show()
}

4. ที่ form ทำการ include ไฟล์ submitButton.ftl เข้าไปดังนี้
<platform-specific>
    <html><html-template location="component://imas-project/webapp/imas-project/project/submitButton.ftl"/></html>
</platform-specific>

5. ทำการเพิ่มไฟล์ testDialog.js ใน framework/common/widget/CommonScreens.xml เพื่อให้ทุกเพจสามารถเรียกใช้ไฟล์ javscript นี้ได้ ดังนี้
<set field="layoutSettings.javaScripts[+0]" value="/dojotoolkit/imas/testDialog.js" global="true"/>

6.เมื่อทดลองกดปุ่ม จะแสดง dialog box ดังนี้

วันอังคารที่ 8 มิถุนายน พ.ศ. 2553

การสร้าง service เพื่อ insert ข้อมูลลงในฐานข้อมูลโดยใช้ simple method

ในการสร้าง service ใน OFBiz นั้น สามารถใช้ engine ในการสร้าง method ได้ 3 วิธี ดังนี้
1. engine="java" ทำได้โดยการเขียนโปรแกรมภาษา java เก็บไว้ในโฟลเดอร์ src แล้วเรียกใช้งานผ่าน package
2. engine="simple" เขียนเป็น simple method เก็บไว้ในไฟล์ *Services.xml
3. engine เป็น webservice

ในบทความนี้จะแสดงการสร้าง service โดยใช้ simple method ในไฟล์ *Services.xml มีวิธีทำดังนี้

1. สร้าง form ชื่อ CreateBlog ที่ *Forms.xml

<form name="CreateBlog" type="single" target="createBlog" default-entity-name="NewBlog">
        <auto-fields-entity entity-name="NewBlog" default-field-type="edit"/>
        <field name="saveButton" title="Save" ><submit button-type="button"/></field>
</form>

2. include form ชื่อ CreateBlog เข้าไปในไฟล์ *Screens.xml
<screen name="CreateBlog">
        <section>
            <widgets>
                <decorator-screen name="CommonDecorator" location="component://myblog/widget/CommonScreens.xml">
                    <decorator-section name="body">
                        <container id="content">
                            <container id="content-bgtop">
                                <container id="content-bgbtm">
                                    <container style="post">
                                        <include-form location="component://myblog/widget/MyBlogForms.xml" name="CreateBlog"/>
                                    </container>
                                </container>
                            </container>
                        </container>
                    </decorator-section>
                </decorator-screen>
            </widgets>
        </section>
    </screen>

3. กลับไปดูที่ไฟล์ *Forms.xml ฟอร์มชื่อ CreateBlog มี target="createBlog"
<form name="CreateBlog" type="single" target="createBlog" default-entity-name="NewBlog">
        <auto-fields-entity entity-name="NewBlog" default-field-type="edit"/>
        <field name="saveButton" title="Save" ><submit button-type="button"/></field>
</form>

4. ใน controller.xml ทำการสร้าง request-map และสั่งให้มีการการ invoke simple method ชื่อ createBlog ที่ services.xml

<request-map uri="createBlog">
        <event type="service" invoke="createBlog"/>
        <response name="success" type="request-redirect-noparam" value="blog"></response>
</request-map>

5. ใน services.xml มีการ invoke createBlog ในไฟล์ *Services.xml
<service name="createBlog" engine="simple" auth="false"
            location="component://myblog/script/com/org/toon/myblog/MyBlogServices.xml" invoke="createBlog">
            <attribute name="newBlogId" mode="INOUT" type="String" optional="false"></attribute>
            <attribute name="newBlogTitle" mode="IN" type="String" optional="false"></attribute>
            <attribute name="newBlogBody" mode="IN" type="String" optional="false"></attribute>
            <attribute name="statusId" mode="IN" type="String" optional="true"></attribute>
</service>

6. สร้าง service ชื่อ createBlog ในไฟล์ MyBlogServices.xml
<simple-method method-name="createBlog" short-description="create a Blog">
        <make-value entity-name="NewBlog" value-field="newEntity"/>
        <set-pk-fields map="parameters" value-field="newEntity"/>
        <set-nonpk-fields map="parameters" value-field="newEntity"/>
        
        <create-value value-field="newEntity"/>

        <field-to-result field="parameters.newBlogId" result-name="newBlogId"/>
</simple-method>


7.จบส่วนในการสร้างและเรียกใช้ Service ต่อไปจะทำการ controller ให้เรียก view ที่มีหน้า form ของการ create new blog มาแสดงผล

8. เพิ่ม controller ชื่อ CreateBlog ใน controller.xml ให้เรียก view ชื่อ CreateBlog มาแสดงผล เมื่อมีการเรียกเข้ามาที่ controller นี้

<request-map uri="CreateBlog">
        <security https="true" auth="false"/>
        <response name="success" type="view" value="CreateBlog"></response>
</request-map>

9. สร้าง view ชื่อ CreateBlog เรียกฟอร์มการสร้างมาแสดงผล
<view-map name="CreateBlog" type="screen" page="component://myblog/widget/MyBlogScreens.xml#CreateBlog"/>

10. ทำการ ./startofbiz.sh ใหม่อีกครั้ง แล้วทดลองเพิ่มข้อมูลลงใน entity

ในบทความต่อไปจะแสดงการแก้ไขข้อมูลในฐานข้อมูลผ่านการสร้าง service โดยใช้ simple method แบบเดียวกันนี้

การใช้ form widget ใน OFBiz - การสร้าง list form widget

จากบทความที่แล้ว (การใช้ form widget ใน OFBiz - การสร้าง find form widget) ได้ทำการสร้างฟอร์มการค้นหา ขั้นตอนต่อไปจะทำการสร้างฟอร์มที่แสดลผลการค้นหา หรือ list form ดังนี้

1. define form ของการแสดงผลของ list form ในไฟล์ *Forms.xml

<form name="ListExamples" type="list" target="example" default-entity-name="Example" list-name="listIt">
        <actions>
            <service service-name="performFind" result-map="result" result-map-list="listIt">
                <field-map field-name="inputFields" from-field="parameters"/>
                <field-map field-name="entityName" value="Example"/>
            </service>
        </actions>
        <auto-fields-entity entity-name="Example" default-field-type="display"/>
    </form>

อธิบายโค้ด
ในส่วนของ actions จะมีการเรียกใช้ service ในไฟล์ services.xml ดังนี้
service-name="performFind" result-map="result" result-map-list="listIt" มีการเรียกใช้ service ชื่อ performFind ซึ่งเป็น service ของ OFBiz ที่สร้างขึ้นมาเพื่อให้เรียกใช้งาน find form ได้

2. ที่ screen ที่ต้องการให้ข้อมูลผลลัพธ์ของการค้นหาแสดงผล ให้เพิ่มโค้ดในส่วนของ actions และ include form ListExamples เข้าไป ดังนี้

<actions>
                <set field="exampleId" global="true" />
                <entity-one value-field="resultMap" entity-name="Example"></entity-one>
                <get-related relation-name="ExampleItem" list="resultList" value-field="resultMap"/>
            </actions>

<include-form location="component://culinary/widget/CulinaryForms.xml" name="ListExamples"/>

โค้ดในส่วนของ screen name="findExample" เมื่อสมบูรณ์แล้ว จะได้ดังนี้

<screen name="findExample">
        <section>
            <actions>
                <set field="exampleId" global="true" />
                <entity-one value-field="resultMap" entity-name="Example"></entity-one>
                <get-related relation-name="ExampleItem" list="resultList" value-field="resultMap"/>
            </actions>
            <widgets>
                <decorator-screen name="CommonDecorator" location="component://culinary/widget/CommonScreens.xml">
                    <decorator-section name="body">
                        <container id="content">
                             <container style="post">
                                   <container style="entry">
                                        <include-form location="component://culinary/widget/CulinaryForms.xml" name="FindExample"/>
                                        <include-form location="component://culinary/widget/CulinaryForms.xml" name="ListExamples"/>
                                   </container>
                             </container>
                        </container>
                    </decorator-section>
                </decorator-screen>
            </widgets>
        </section>
    </screen>

อธิบายโค้ด
ส่วนของ actions จะทำการประมวลผลก่อน ถึงจะส่งไปให้ในส่วนของ widgets แสดงผลต่อไป
field="exampleId" global="true" ทำการเซ็ตค่าที่ได้จากตัวแปร exampleId ให้เป็น global

entity-one value-field="resultMap" entity-name="Example" ทำการส่งค่าที่ได้จากการค้นหาใน entity ชื่อ Example มาเก็บไว้ในตัวแปรชนิด map ชื่อ resultMap

get-related relation-name="ExampleItem" list="resultList" value-field="resultMap" ทำการลิสต์ item ที่มีความสัมพันธ์กับ entity ชื่อ Example นี้มาแสดงผลทีละ item

entity ชื่อ Example นี้ จะมี entity ชื่อ ExampleItem ที่มีความสัมพันธ์กันแบบ one to many โค้ดในส่วนของ get-related จะช่วยทำการลิสต์ item ใน ExampleItem มาแสดงผล

ยกตัวอย่างความสัมพันธ์เหล่านี้ เช่น ในการออกรายงานในแต่ละครั้ง การแสดงผลของรายงานจะมีส่วนหัวที่ประกอบไปด้วย ที่อยู่บริษัทหรือวันที่ต่างๆ และส่วนของ item ที่ต้องการโชว์ในรายงาน

ส่วนหัวของรายงานเปรียบได้กับ entity ชื่อ Example ที่มี entity ชื่อ ExampleItem มามีความสัมพันธ์ด้วย เพื่อเรียกใช้ส่วนหัวของรายงาน นั่นหมายความว่า หัวรายงาน 1 หัวรายงาน สามารถแสดง item ใน entity ชื่อ ExampleItem ได้หลายไอเท็มนั่นเอง ซึ่งคำสั่งนี้จะทำการลิสต์ไอเท็มที่ต้องการแสดงภายใต้หัวรายงานออกมาทั้งหมด

เมื่อจบในส่วนของ actions แล้ว จึง include เพื่อเรียกใช้งาน form ชื่อ ListExamples มาแสดงผลต่อจากส่วน FindExample

3. ทำการทดลองค้นหาผ่าน url http://localhost:8080/culinary/control/example จะพบว่า เมื่อกดปุ่ม Search แล้ว ผลลัพธ์ในการค้นหาจะแสดงต่อจาก find form ทางด้านล่าง

การใช้ form widget ใน OFBiz - การสร้าง find form widget

ใน OFBiz สามารถนำ form แสดงผลใน screen ได้ โดย form ที่นำมาแสดง สามารถแบ่งประเภทได้ดังนี้
1. find form เป็นฟอร์มที่ใช้ค้นหา item หรือ content ต่างๆ ใน module
โดย form ชนิดนี้จะมี type เป็น single


2. list form เป็นฟอร์มที่ใช้แสดงรายการ โดยจะลิสต์แสดงรายการออกมาเป็น table
form ชนิดนี้จะมี type เป็น list


3. display and edit เป็นฟอร์มที่ใช้แสดงรายการแก้ไข โดยจะสามารถแก้ไขข้อความใน field ที่อนุญาตให้แก้ไขได้ หากต้องการให้ field ไหนแก้ไขได้ สามารถ เซ็ต type เป็น input หรือ textbox หรือแล้วแต่ชนิดของ field ที่ต้องการแก้ไข แต่หากไม่ต้องการให้สามารถแก้ไขได้ ให้เซ็ต type เป็น display จะเป็นการสั่งให้แสดงผลเท่านั้น แต่ไม่สามารถแก้ไขได้



ขั้นตอนการสร้าง find form widget สามารถทำได้ดังนี้

1. ทำการ define form เข้าไปในไฟล์ *Form.xml ดังนี้
หมายเหตุ *Form.xml คือชื่อของ Component ต่อด้วย Form.xml จะอยู่ในโฟลเดอร์ widget

<form default-entity-name="Example" name="FindExample" target="example" type="single">
<auto-fields-entity default-field-type="find" entity-name="Example">
        <field name="noConditionFind"><hidden value="Y"></hidden>
        <field name="searchButton" title="Search"><submit button-type="button"></submit>
    </field></field></auto-fields-entity></form>

อธิบายโค้ด
form name="FindExample" ตั้งชื่อฟอร์มว่า  FindExample
type="single" target="example" ให้เป็นชนิด single และ route ไปที่ example controller
default-entity-name="Example" ชื่อ entity ที่เรียกใช้ข้อมูลคือ Example

auto-fields-entity entity-name="Example" ทำการเรียกข้อมูลใน entity ชื่อ Example มาแสดงโดยอัติโนมัติทุก field โดยที่ไม่ต้องระบุชื่อฟิลด์
default-field-type="find" ระบุชนิดของ field ใน form นี้ให้เป็น find

field name="searchButton" title="Search"
submit button-type="button"เพิ่มปุ่ม Search ให้ฟอร์มนี้

2. ทำการเรียก form ที่ define ไว้ใน *Form.xml มาแสดงผลใน *Screen.xml
<screen name="findExample">
        <section>
            <widgets>
                <decorator-screen location="component://culinary/widget/CommonScreens.xml" name="CommonDecorator">
                    <decorator-section name="body">
                        <container id="content">
                             <container>
                                   <container>
                                        <include-form location="component://culinary/widget/CulinaryForms.xml" name="FindExample">
                                   </include-form>
                             </container>
                        </container>
                    </container>
                </decorator-section>
            </decorator-screen>
        </widgets>
    </section></screen>
อธิบายโค้ด
include-form location="component://culinary/widget/CulinaryForms.xml" name="FindExample" ทำการ include form ชื่อ FindExample ไปแสดงผลที่ screen widget ที่ชื่อ findExample

3. ทำการกำหนด request-map ให้กับไฟล์ controller.xml

<request-map uri="example">
        <security auth="true" https="false">
        <response name="success" type="view" value="example"></response>
    </security>
</request-map>

4.สร้าง view ให้กับ example controller

<view-map name="example" page="component://culinary/widget/CulinaryScreens.xml#findExample" type="screen"></view-map>

5. ทดลองเรียกใช้ url http://localhost:8080/culinary/control/example จะปรากฏ find form ดังนี้

ซึ่งฟอร์มนี้จะแสดงเฉพาะฟอร์มการค้นหา ไม่สามารถแสดงผลการค้นหาได้ เนื่องจากยังไม่กำหนด actions ให้กับ screen
ในบทความต่อไปจะแสดงผลลัพธ์จากการค้นหาที่ต่อเนื่องจากการสร้างฟอร์มในบทความนี้

การดึงข้อมูลจาก Entity มาแสดงผลในหน้าเพจ

OFBiz สามารถเรียกข้อมูลจาก Entity มาแสดงผลในหน้าเวบเพจได้ 2 วิธี คือ
1. ดึงจาก Screen หรือ Widget
2. ดึงจาก Script

ในบทความจะแสดงการดึงค่าจาก Widget ดังนี้
1. เพิ่มแท็ก <action> ลงภายใต้แท็ก <screen><section> ในไฟล์ CulinaryScreens.xml ในโฟลเดอร์ widget
หมายเหตุ: ชื่อไฟล์ CulinaryScreens.xml ตาม component ชื่อ culinary หากทำการสร้าง component ชื่ออื่น ให้ทำการแก้ไขที่ไฟล์ ชื่อคอมโพเน้นท์Screens.xml
ดังนี้

<actions>
                <set field="exampleId" value="10000" global="true" />
                <entity-one value-field="resultMap" entity-name="Example"></entity-one>
                <get-related relation-name="ExampleItem" list="resultList" value-field="resultMap"/>
</actions>

อธิบายโค้ด

<set field="exampleId" global="true" value="10000">
</set>
ทำการเลือก record มาแสดงผล โดยทำการเลือก record ที่มี exampleId = 10000 และทำการเซ็ตให้มีค่าเป็น Global


<entity-one value-field="resultMap" entity-name="Example"></entity-one>
เก็บผลลัพธ์ (record) ที่ได้จากบรรทัดแรกมาเก็บในตัวแปร resultMap

<get-related relation-name="ExampleItem" list="resultList" value-field="resultMap"/>
ดึง item ที่มีความสัมพันธ์กับ exampleId = 10000 มาเก็บไว้ใน list ชื่อ resultList

2. ที่หน้า view ของ home เพิ่มโค้ดดังนี้

<#list resultList as resultItem>
    ${resultItem.description}<br />
</#list>

อธิบายโค้ด
ใช้แท็ก FreeMarker มาช่วยในการแสดงผล โดยทำการ list ค่าของ ExampleItem ทั้งหมดที่อยู่ใน resultList มาแสดงผลทีละไอเทม

3. ทดลองเปิดหน้าเว็บไซต์ดู

วันจันทร์ที่ 7 มิถุนายน พ.ศ. 2553

การสร้างและการเรียกใช้งาน Screen Decorator ใน OFBiz

ในการสร้างหน้าเพจ มักจะมีส่วนของการแสดงผลที่ซ้ำๆ กัน เช่น ส่วนของ menu, header, footer เป็นต้น ซึ่งใน OFBiz จะมีการสร้าง Screen Decorator ไว้สำหรับเป็น template และหากมีการเปลี่ยนแปลงเฉพาะส่วนย่อยๆ จะเปลี่ยนเฉพาะ Screen บางส่วนเท่านั้น ซึ่งในการสร้าง Screen Decorator สามารถสร้างได้ดังนี้

1. ในเทมเพลนมีส่วนที่ซ้ำกันทุกหน้าคือ header และ footer ให้ทำการแยกโค้ดในส่วนของ header และ footer เก็บไว้ในเพจ .ftl เช่น header.ftl และ footer.ftl
2. โค้ดในส่วนที่เหลือจาก header.ftl และ footer.ftl ให้เซฟเก็บไว้เป็นไฟล์ index.ftl
3. เปิดไฟล์ CommonScreens.xml ซึ่งจะอยู่ในโฟลเดอร์ hot-deploy/culinary/widget/CommonScreens.xml
4. ทำการสร้าง Screen สำหรับที่จะใช้เป็น template ภายใต้แท็ก <screens></screens> ดังโค้ดต่อไปนี้

<screen name="CommonDecorator">
        <section>
            <widgets>
                <!-- header section -->
                <platform-specific>
                    <html>
                        <html-template location="component://culinary/webapp/culinary/includes/header.ftl"/>
                    </html>
                </platform-specific>
                <decorator-section-include name="body"/>
                <!-- right -->
                <platform-specific>
                    <html>
                        <html-template location="component://culinary/webapp/culinary/includes/right.ftl"/>
                    </html>
                </platform-specific>
                <!-- footer section -->
                <platform-specific>
                    <html>
                        <html-template location="component://culinary/webapp/culinary/includes/footer.ftl"/>
                    </html>
                </platform-specific>
            </widgets>
        </section>
    </screen>

อธิบายโค้ด
 <screen name="CommonDecorator"> ตั้งชื่อ screen นี้ว่า CommonDecorator

<platform-specific>
      <html>
              <html-template location="component://culinary/webapp/culinary/includes/header.ftl"/>
      </html>
</platform-specific>
ดึงไฟล์ header.ftl มาเป็นส่วนหนึ่งของเทมเพลต


<decorator-section-include name="body"/>
เตรียมพื้นที่ไว้รอแสดงส่วนเนื้อหาจากหน้าอื่น

<platform-specific>
    <html>
        <html-template location="component://culinary/webapp/culinary/includes/footer.ftl"/>
    </html>
</platform-specific>
ดึงไฟล์ header.ftl มาเป็นส่วนหนึ่งของเทมเพลต

เมื่อเสร็จขั้นตอนนี้ จะได้ เทมเพลตที่ประกอบไปด้วยส่วน header และ footer ที่ไม่มีการเปลี่ยนแปลงของ screen และมีส่วน body ที่ define ไว้รอสำหรับการนำเอาเนื้อหาที่มีการเปลี่ยนแปลงในแต่ละหน้ามาแสดงผล

5. ในโฟลเดอร์ widget จะมีไฟล์ xml ที่ใช้จัดการกับ screen อีก 3 ไฟล์ ซึ่งจะมี 1 ไฟล์ที่ชื่อเดียวกับชื่อ component เช่น ถ้า component ชื่อ culinary ไฟล์นี้จะชื่อ CulinaryScreens.xml ทำการเปิดไฟล์นี้และเพิ่มโค้ดดังนี้

<screen name="home">
        <section>
            <widgets>
                <decorator-screen name="CommonDecorator" location="component://culinary/widget/CommonScreens.xml">
                    <decorator-section name="body">
                        <platform-specific>
                            <html>
                                <html-template location="component://culinary/webapp/culinary/home.ftl"/>
                            </html>
                        </platform-specific>
                    </decorator-section>
                </decorator-screen>
            </widgets>
        </section>
    </screen>

อธิบายโค้ด
<decorator-screen location="component://culinary/widget/CommonScreens.xml" name="CommonDecorator">
ตั้งชื่อ screen ว่า CommonDecorator และ url ของ screen นี้ถูกกำหนดลงใน location

<decorator-section name="body">
    <platform-specific>
        <html>
            <html-template location="component://culinary/webapp/culinary/home.ftl"/>
        </html>
    </platform-specific>
</decorator-section>
อธิบายโค้ด
ในส่วน decorator-section ชื่อ body ให้เรียกไฟล์ home.ftl มาแสดงผล

6. ทำการกำหนด controller และ view ในไฟล์ webapp/culinary/WEB-INF/controller.xml ดังนี้

<request-map uri="home">
<security https="false" auth="true"/>
<response name="success" type="view" value="home"/></request-map>
<view-map name="home" type="screen" page="component://culinary/widget/CulinaryScreens.xml#home"/>

7. ทดสอบเรียกหน้า home ขึ้นมาแสดงผล

การติดตั้ง OFBiz โดยใช้ PostgreSQL เป็นฐานข้อมูล

PostgreSQL คือ ระบบจัดการฐานข้อมูลเชิงสัมพันธ์ (Object-Relational DataBase Management System หรือ ORDBMS) มีความสามารถในการทำงานร่วมกับ OFBiz ได้อย่างดี ทั้งนี้ยังเป็นซอฟต์แวร์ฟรีอีกด้วย จึงสามารถนำมาช่วยลดค่าใช้จ่ายในองค์กรได้

จากบทความเรื่องการติดตั้ง OFBiz ได้ใช้ฐานข้อมูล Derby ซึ่งเป็นฐานข้อมูลขนาดเล็กที่มาพร้อม OFBiz มีความสามารถในระดับหนึ่ง แต่ไม่เทียบเท่า PostgreSQL และไม่สามารถรองรับการใช้งานที่มีการเรียกใช้ฐานข้อมูลจำนวนมากได้ จึงได้นำเอา PostgreSQL มาช่วยให้การใช้งาน OFBiz มีประสิทธิภาพมากขึ้น

ขั้นตอนการติดตั้ง PostgreSQL สำหรับ OFBiz ทำได้ดังนี้

1. ติดตั้ง PostgreSQL จาก Synaptic Package Manager
2. ติดตั้ง pgadmin จาก Synaptic Package Manager
3. ทำการตั้งค่า password ให้กับ account ของ PostgreSQL โดยเปิด terminal และเข้าไปที่โฟลเดอร์ /etc/postgresql/8.4/main
4. สั่งแก้ไขไฟล์ชื่อ pg_hba.conf โดยใช้คำสั่ง
    sudo gedit pg_hba.conf
5. เปลี่ยนค่าจาก ident เป็น trust ทั้งหมด และ เปลี่ยนค่าจาก md5 เป็น trust ทั้งหมด
6. สั่งแก้ไขไฟล์ชื่อ postgresql.conf โดยใช้คำสั่ง
sudo gedit postgresql.conf 
7. แก้ไขบรรทัด #listen_addresses = 'localhost' โดยการเอา # ออกและเปลี่ยนจาก localhost เป็น * จะได้โค้ดดังนี้
listen_addresses = '*'   
8. สั่ง start serveice ของ postgresql โดยใช้คำสั่ง
cd /etc/init.d
9. สั่ง restart service โดยใช้คำสั่ง
sudo service postgresql-8.4 restart

เมื่อตั้งค่าเสร็จแล้ว ลงมือทำการสร้าง connection ดังนี้
1. เปิด pgadmin
2. กดปุ่ม add a connection to a server
3. ตั้งค่าดังนี้
    Name = localhost
    Host = localhost
แล้วกด ok
4. ทำการสร้าง login role ให้แก่ database โดยการคลิ้กขวาที่ Login Roles แล้วเลือก New Login Role
5. กรอกรายละเอียด Role name, Password และ Password(again) แล้วกด OK
6. ในการสร้างฐานข้อมูลสำหรับ OFBiz ต้องสร้างทั้งหมด 3 database โดยกำหนดดังนี้
    Database1
        name = ofbiz
        login role = ofbiz
    Database2
        name = ofbizolap
        login role = ofbiz
    Database3
        name = ofbiztenance
        login role = ofbiz
7. ทำการดาวน์โหลด jdbc driver สำหรับ postgresql โดยสามารถดาวน์โหลดได้ที่ http://jdbc.postgresql.org/download.html
เลือกดาวน์โหลดไฟล์ JDBC4 Postgresql Driver, Version 8.4-701 สำหรับ 1.6 JVM ขึ้นไป
8. ทำการ copy ไฟล์ที่ดาวน์โหลดไปไว้ในโฟลเดอร์ framework/entity/lib/jdbc ของโปรเจ็ค
9. ทำการแก้ไขไฟล์ framework/entity/config/entityengine.xml โดยการเพิ่ม datasource ดังนี้
<datasource name="localpostnew"
            helper-class="org.ofbiz.entity.datasource.GenericHelperDAO"
            schema-name="public"
            field-type-name="postnew"
            check-on-start="true"
            add-missing-on-start="true"
            use-fk-initially-deferred="false"
            alias-view-columns="false"
            join-style="ansi"
            result-fetch-size="50"
            use-binary-type-for-blob="true">
        <read-data reader-name="seed"/>
        <read-data reader-name="seed-initial"/>
        <read-data reader-name="demo"/>
        <read-data reader-name="ext"/>
        <inline-jdbc
                jdbc-driver="org.postgresql.Driver"
                jdbc-uri="jdbc:postgresql://127.0.0.1/org"
                jdbc-username="org"
                jdbc-password="orgpass"
                isolation-level="ReadCommitted"
                pool-minsize="2"
                pool-maxsize="250"
                time-between-eviction-runs-millis="600000"/>
    </datasource>
    
    <datasource name="localpostnewolap"
            helper-class="org.ofbiz.entity.datasource.GenericHelperDAO"
            schema-name="public"
            field-type-name="postnew"
            check-on-start="true"
            add-missing-on-start="true"
            use-fk-initially-deferred="false"
            alias-view-columns="false"
            join-style="ansi"
            result-fetch-size="50"
            use-binary-type-for-blob="true">
        <read-data reader-name="seed"/>
        <read-data reader-name="seed-initial"/>
        <read-data reader-name="demo"/>
        <read-data reader-name="ext"/>
        <inline-jdbc
                jdbc-driver="org.postgresql.Driver"
                jdbc-uri="jdbc:postgresql://127.0.0.1/orgolap"
                jdbc-username="org"
                jdbc-password="orgpass"
                isolation-level="ReadCommitted"
                pool-minsize="2"
                pool-maxsize="250"
                time-between-eviction-runs-millis="600000"/>
    </datasource>
    
    <datasource name="localpostnewtenant"
            helper-class="org.ofbiz.entity.datasource.GenericHelperDAO"
            schema-name="public"
            field-type-name="postnew"
            check-on-start="true"
            add-missing-on-start="true"
            use-fk-initially-deferred="false"
            alias-view-columns="false"
            join-style="ansi"
            result-fetch-size="50"
            use-binary-type-for-blob="true">
        <read-data reader-name="seed"/>
        <read-data reader-name="seed-initial"/>
        <read-data reader-name="demo"/>
        <read-data reader-name="ext"/>
        <inline-jdbc
                jdbc-driver="org.postgresql.Driver"
                jdbc-uri="jdbc:postgresql://127.0.0.1/orgtenant"
                jdbc-username="org"
                jdbc-password="orgpass"
                isolation-level="ReadCommitted"
                pool-minsize="2"
                pool-maxsize="250"
                time-between-eviction-runs-millis="600000"/>
    </datasource>

และแก้ไข delegetor ของ delegator name="default" และ delegator name="default-no-eca" ดังนี้

<delegator name="default" entity-model-reader="main" entity-group-reader="main" entity-eca-reader="main" distributed-cache-clear-enabled="false">
        <group-map group-name="org.ofbiz" datasource-name="localpostnew"/>
        <group-map group-name="org.ofbiz.olap" datasource-name="localpostnewolap"/>
        <group-map group-name="org.ofbiz.tenant" datasource-name="localpostnewtenant"/>
    </delegator>
    <delegator name="default-no-eca" entity-model-reader="main" entity-group-reader="main" entity-eca-reader="main" entity-eca-enabled="false" distributed-cache-clear-enabled="false">
        <group-map group-name="org.ofbiz" datasource-name="localpostnew"/>
        <group-map group-name="org.ofbiz.olap" datasource-name="localpostnewolap"/>
        <group-map group-name="org.ofbiz.tenant" datasource-name="localpostnewtenant"/>
    </delegator> 

10. พิมพ์คำสั่งใน terminal ดังนี้
./ant clean-all
11. พิมพ์คำสั่งใน terminal ดังนี้
./ant run-install
12. สั่ง start ofbiz ดังนี้
./startofbiz.sh

วันศุกร์ที่ 4 มิถุนายน พ.ศ. 2553

การเพิ่ม page ใน OFBiz

webapp ของ OFBiz อาศัยหลักการ MVC หรือ Model-View-Controller ในการแสดงผล โดยแยกออปเจคที่เก็บข้อมูล (model) ออปเจคที่แสดงข้อมูล (view) และออปเจคที่ติดต่อกับผู้ใช้ (controller) ออกจากกันอย่างชัดเจน โดย webapp ใน OFBiz จะมีไฟล์ชื่อ controller.xml ในโฟลเดอร์ WEB-INF เป็นตัวกำหนดว่าจะเรียก view ไหนขึ้นมาแสดงผล เมื่อถูก request ผ่านทาง url

ทดลองสร้าง views ขึ้นมาใน webapp ของ component โดยสร้างไฟล์ชนิด ftl ดังนี้
หมายเหตุ ftl เป็นไฟล์ชนิด free marker template engine

1. เลือก File > New > Others > Web > Html page
2. ตั้งชื่อไฟล์ เช่น testpage จะได้ไฟล์ testpage.html
3. ทำการ rename นามสกุลไฟล์เป็น .ftl จะได้ไฟล์ testpage.ftl
4. ในไฟล์ controller.xml ทำการสร้าง request-map ดังนี้

<request-map uri="testpage">
    <security auth="true" https="false">
        <response name="success" type="view" value="testpage"></response>
    </security>
</request-map>

อธิบายโค้ด

<request-map uri="testpage"></request-map>

ทำการเซ็ตค่าว่า ถ้าหาก uri ชื่อ testpage ถูก request ผ่าน webapp มา จะให้ทำอะไรบ้าง



security https="false" กำหนดให้ ไม่สามารถเรียกผ่าน https protocol ได้
auth="true" กำหนดให้ต้องมีการ login ก่อน ถึงจะสามารถเรียกใช้ page นี้ได้


response name="success" เมื่อมีการ success ในการเรียกใช้เพจนี้
type="view" ชนิดของ object ที่จะเรียกให้แสดงผลเมื่อถูก request url นี้เป็นชนิด view
value="testpage" ชื่อของ view ที่จะถูกเรียกมาแสดงผล

5. เมื่อทำการเพิ่ม view map ดังนี้



อธิบายโค้ด
view-map name ="testpage" ชื่อของ view นี้
type="ftl" เป็นชนิด ftl
page="component://testtest/webapp/testtest/testpage.ftl" uri ของ view นี้

6. ทดลองเรียกใช้ page ที่สร้างขึ้น โดยเรียกผ่าน url

https://localhost:8443/testtest/control/testpage

เอกสารอ้างอิง
http://www.narisa.com/forums/index.php?showtopic=1036
http://freemarker.sourceforge.net/

วันพฤหัสบดีที่ 3 มิถุนายน พ.ศ. 2553

การสร้าง Component ใน OFBiz

ในการพัฒนา OFBiz จะเรียกการสร้าง application หรือ module ว่า component โดยแต่ละ component จะเป็นอิสระต่อกัน และแต่ละ component จะมี data model, views, controller เป็นของ component เอง แต่สามารถทำงานร่วมกับ component อื่นได้

component หลักของ OFBiz จะอยู่ใน folder ชื่อ applications ส่วน component ที่ถูกสร้างขึ้นจะถูกสร้างไว้ในโฟลเดอร์ hot-deploy โดยขั้นตอนในการสร้าง component สำหรับ OFBiz มีดังนี้
1. เปิด Terminal แล้วเข้าไปยัง folder ที่มีการรัน OFBiz
2. ทำการเรียก ant ให้สร้าง component โดยใช้คำสั่งดังนี้
./ant create-component
3. ant จะให้ตั้งค่าต่างๆ ของ component รูปแบบดังนี้
- ชื่อ component รูปแบบดังนี้ Component name: (e.g. mycomponent)
- Component resource name รูปแบบดังนี้ Component resource name: (e.g. MyComponent)
- ชื่อ web application รูปแบบดังนี้ Webapp name: (e.g. mycomponent)
- Base permission รูปแบบดังนี้ Base permission: (e.g. MYCOMPONENT)
4. เมื่อกำหนดค่าทั้งหมดแล้ว ant จะให้ confirm สิ่งที่ตั้งค่าไป เมื่อถูกต้องทั้งหมดแล้วกด y เพื่อยืนยัน ant จะเริ่มทำการสร้าง component ให้
5. ทดสอบการสร้าง component โดยลองเรียกผ่านทาง web browser ดังนี้
https://localhost:8443/ชื่อคอมโพเน้นท์/control/main หรือ
http://localhost:8080/ชื่อคอมโพเน้นท์

เมื่อสร้าง component เสร็จแล้ว จะยังไม่สามารถล็อกอินเข้าใช้คอมโพเน้นท์ได้ ให้ทำการแอด data security ให้กับ component ก่อน มีขั้นตอนดังนี้
1. login เข้าไปใน webtools ของ OFBiz ที่ได้ติดตั้งไว้ ตาม url ดังนี้
https://localhost:8443/webtools/control/main หรือ
https://localhost:8080/webtools
2. ค่า default ของการ login เข้าใช้งาน OFBiz ดังนี้
username = admin
password = ofbiz
3. ในการ import data security เข้าไปใน webtools สามารถทำได้หลายวิธี ดังนี้
วิธีที่ 1 import security data xml file
3.1.1 เลือก XML Data Import ใน webtools
3.1.2 ใส่ค่า absolute path ของ security data file ลงในช่อง Absolute Filename or URL: เช่น
/home/toonztudio/Desktop/projects/ofbiz.10.04/hot-deploy/testtest/data/TestTestSecurityData.xml

หมายเหตุ: ไฟล์ security data จะอยู่ในโฟลเดอร์ hot-deploy/ชื่อคอมโพเน้นท์/data/ชื่อ Component resource name ต่อด้วย SecurityData.xml

3.1.3 กดปุ่ม Import file
3.1.4 หากขึ้นข้อความว่าไฟล์ถูกอิมพอร์ตเข้าไปแล้ว และไม่มี error แสดงว่าการนำเข้า security data สำเร็จ ดังนี้
Results:
Got 12 entities to write to the datasource.
วิธีที่ 2 import xml element
3.2.1 เลือก XML Data Import ใน webtools
3.2.2 เปิดไฟล์ SecurityData.xml แล้ว copy element ระหว่าง ลงในช่อง Complete XML document (root tag: entity-engine-xml):
3.2.3 กดปุ่ม import text
3.2.4 หากไม่มี error แสดงว่าสามารถนำเข้าได้ทั้งหมด
Results:
Got 12 entities to write to the datasource.

วิธีที่ 3 XML Data Import Dir
3.3.1 เลือก XML Data Import ใน webtools
3.3.2 ใส่ค่า absolute path ของ data directory ลงในช่อง Absolute directory path: เช่น
/home/toonztudio/Desktop/projects/ofbiz.10.04/hot-deploy/testtest/data

3.3.3 กดปุ่ม import file หากไม่มี error แจ้งว่า fail แสดงว่าการนำเข้าสำเร็จ

เมื่อทำการเพิ่ม data security ให้กับ component นี้แล้ว แอคเคาท์ admin จะสามารถ login เข้าใช้งาน component นี้ได้ ทดสอบได้โดยการ login เข้าไปใน url ดังนี้
https://localhost:8443/ชื่อคอมโพเน้นท์/control/main หรือ
http://localhost:8080/ชื่อคอมโพเน้นท์

เมื่อล็อกอินเข้ามาแล้วจะพบหน้า OFBiz ว่าง ซึ่งต้องทำการเซ็ต controller ของ webapp ใน component ของ OFBiz ให้เรียก views มาแสดงผลได้ ซึ่งจะแสดงในบทความต่อไป

วันอังคารที่ 1 มิถุนายน พ.ศ. 2553

Apache OFBiz ERP/Framework


ERP
เป็นการวางแผนการจัดการทรัพยากรขององค์กร เพื่อให้สามารถจัดการทรัพยากรของระบบให้มีประสิทธิภาพและเกิดประโยชน์สูงสุดต่อองค์กร

โดยทั่วไปในองค์กรมักจะใช้ซอฟต์แวร์สำเร็จรูปในการจัดการข้อมูลในองค์กร ทำให้เกิดความไม่เป็นอันหนึ่งอันเดียวกัน และข้อมูลไม่เป็นรูปแบบเดียวกัน เมื่อมีความต้องการจะนำเอาข้อมูลมาใช้ ความหลากหลายของซอฟต์แวร์ทำให้เกิดความไม่สะดวกในการเรียกข้อมูล ก่อให้เกิดความล่าช้าในการแข่งขันในธุรกิจยุคปัจจุบัน

ดังนั้นจึงมีแนวคิดที่จะนำเอาการวางแผนการจัดการทรัพยากรขององค์กร หรือ ERP มารวมกับระบบสารสนเทศ เพื่อรวบรวมข้อมูลทั้งหมดในองค์กรให้เป็นระบบเดียวกัน ส่งผลให้ง่ายต่อการเรียกใช้ข้อมูล, การควบคุมข้อมูล และข้อมูลทั้งหมดสามารถเชื่อมโยงกันได้อย่างทันเหตุการณ์ (real time)

OFBiz
เป็น Open Source Software ที่ช่วยให้องค์กรหรือธุรกิจสามารถวางแผนการใช้งานทรัพยากรให้เกิดประโยชน์สูงสุด โดยสามารถเชื่อมต่อกับทุกระบบ หรือเชื่อมต่อระบบสำคัญๆ ในองค์กร ช่วยให้ผู้ที่มีความสามารถเข้าถึงข้อมูลใช้ประโยชน์จากข้อมูลที่เชื่อมโยงกันได้อย่างทันเหตุการณ์ (real time)

OFBiz มาจากคำว่า Open For Business อยู่ภายใต้การดูแลของ Apache Foundation ซึ่งมี Developer จากทั่วโลกมาช่วยกันพัฒนา แล้วแจกจ่ายให้ผู้สนใจนำไปใช้งานและพัฒนาต่อโดยไม่เสียค่าใช้จ่าย แต่อยู่ภายใต้เงื่อนไขของ Open Source Software

OFBiz ประกอบด้วยแอพพลิเคชั่นที่ช่วยในการทำงานหลายด้าน เช่น Customer Relationship Management(CRM), Human Resource Management(HRM), Supply Chain Management(SCM), Purchase Management, Inventory, Sales Management, IT Management, Production Management, Data Analysis/Report เป็นต้น

ปัจจุบันมี Open Source ERP จากหลายบริษัท แต่หลักๆ แล้ว จะแบ่งตาม Framework ที่ใช้เป็นพื้นฐานในการพัฒนาได้ดังนี้

1. Apache OFBiz - ERP ที่นำเอา OFBiz ไปเป็นพื้นฐานในการพัฒนา เช่น Opentabs ERP/CRM, Shared OFBiz, OrangeGears ERP/CRM, Atlassian JIRA, Neogia ERP เป็นต้น
2. Open ERP
3. Compiere - ERP ที่นำเอา OFBiz ไปเป็นพื้นฐานในการพัฒนา เช่น Adempier, Open Bravo, Seree ERP เป็นต้น

องค์ประกอบหลักของ OFBiz
1. Application Component
2. Application Development Framework
3. Application Data Model

โครงสร้างของ OFBiz Framework แบ่งเป็น 3 ส่วน คือ
1. Presentation
2. Business Logic
3. Data

บรรยายสำหรับนักศึกษาฝึกงาน Orange Gears
เมื่อวันที่ 1 มิ.ย. 2553 โดย คุณธนกฤติ วงศ์ยืด

เอกสารอ้างอิง
http://www.slideshare.net/orangegears/apache-ofbiz-erp