(备注:要看懂该文章必须具备OFBIZ的基础知识。)
关键代码1:在widget的screen中,action部分用<entity-condition 标签指定实体名和实体列表名;
关键代码2:在widget的screen中,widgets部分用<include-form 标签指定被引用表单的位置和表单名;
<screen name="guestbook">
<section>
<actions>
<!-- find HelloPerson by condition. since there is no conditions, all values of HelloPerson are returned in allGuests -->
<entity-condition entity-name="HelloPerson" list-name="allGuests"><order-by field-name="helloPersonId"/></entity-condition>
<!--窗口中调用的表单用到的实体数据在该处指出!!如果该句设置得不对表单中将不显示数据!!!-->
</actions>
<widgets>
<decorator-screen name="CommonDecorator">
<decorator-section name="body">
<label>我们的客人和他们说的话</label> <!-- a label/header -->
<!-- use this form directly, instead of going through a Freemarker template again -->
<include-form name="GuestbookList" location="component://hello3/webapp/hello3/guestbook/GuestbookForms.xml"/>
</decorator-section>
</decorator-screen>
</widgets>
</section>
</screen>
<section>
<actions>
<!-- find HelloPerson by condition. since there is no conditions, all values of HelloPerson are returned in allGuests -->
<entity-condition entity-name="HelloPerson" list-name="allGuests"><order-by field-name="helloPersonId"/></entity-condition>
<!--窗口中调用的表单用到的实体数据在该处指出!!如果该句设置得不对表单中将不显示数据!!!-->
</actions>
<widgets>
<decorator-screen name="CommonDecorator">
<decorator-section name="body">
<label>我们的客人和他们说的话</label> <!-- a label/header -->
<!-- use this form directly, instead of going through a Freemarker template again -->
<include-form name="GuestbookList" location="component://hello3/webapp/hello3/guestbook/GuestbookForms.xml"/>
</decorator-section>
</decorator-screen>
</widgets>
</section>
</screen>
关键代码3:在表单文件内的对应(上面的<include-form 标签指出的表单名)的表单代码处,<form 标签的type要设成list,list-name要和widget中窗口中的action部分的列表名一致。
<form name="GuestbookList" type="list" list-name="allGuests">
<!-- 该处的列表名和widget的窗口action中指定的列表名要对应!this form just lists all the values of allGuests -->
<auto-fields-entity entity-name="HelloPerson" default-field-type="display"/>
<auto-fields-entity entity-name="HelloPerson" default-field-type="display"/>
<!-- 自动显示指定实体的所有域automatically display all fields from HelloPerson -->
</form>
</form>
总体思路就是:form根据实体定义创建表头,action里的entity condition根据条件从数据库中取出数据显示于表中,这就完成了在页面上显示数据库表的过程。