ofbiz的form是如何生成的

ofbiz的form是如何生成的

Ofbiz支持多种表示层的生成方案。可以是HTML,FTL ,JSP、screen widgets等等,甚至可以让开发者根据需要进行扩展。至于如何扩展,我们今天在此不作讨论,以后合适的时候我会给打家分享。在现有的表示层开发方式中,最能展示OFBIZ风格和特点的当为widgets了。基于widgets进行表示展的开发,高效,扩展性好,模块化结构明朗,开发效率也最高,这也是ofbiz首先的开发方式。但是ofbiz中基于widgets的开发,与我们常见的开发方式有很大的不同(至少对于新手页言是这样的确),这也就加大了入门的难度。今天我就来给大家讲讲widgets,和大家分享它的实现原理,以及我们怎样才能有效的用好它。
   我们先来说说从xml的配置到最后html转换的大至过程。我们知道在基于widget进行界面开发时,我们总要在一个xml文件中定义screen,并且screen还可以进行嵌套,可以在screen中加入逻辑、引用form,菜单、或ftl文件等。那么最后它们是怎样有序的组成一张html页面,直至最后呈现在用户的面见的呢?当请求进入服务器以后,根据请求路径的定义(control.xml文件中定义的),可以的到相应的screen定义。Ofbiz加载并解析xml。解析后得到一个又一个的页面元素对象,ofbiz会解析这些对象,成生一个又一个的ftl宏语句。由freemarker编译即可得出我们需要的html.原理非常之简单。
举个例子来说吧,比如我们在screen中引用了catalog的FindCategory这个form。(<include-form name="FindCategory" location="component://product/widget/catalog/CategoryForms.xml"/>
)。通过ofbiz根据xml解析后 就会得如下的freemarker语句:   
  <@renderScreenBegin />
<@renderFormOpen  linkUrl="/catalog/dyn/FindCategory" formType="single" targetWindow="" containerId="FindCategory" containerStyle="" autocomplete="" name="FindCategory" viewIndexField="viewIndex_0" viewSizeField="viewSize_0" viewIndex="0" viewSize="20" useRowSubmit=false />
<@renderHiddenField  name="noConditionFind" value="Y" id="FindCategory_noConditionFind" event="" action="" />
<@renderFormatSingleWrapperOpen  formName="FindCategory" style="basic-table" />
<@renderFormatFieldRowOpen />
<@renderFormatFieldRowTitleCellOpen  style="" />
<@renderFormatFieldRowTitleCellClose />
<@renderFormatFieldRowWidgetCellOpen  positionSpan=0 style="" /><@renderTextFindField  name="productCategoryId" value="" defaultOption="contains" opEquals="等于" opBeginsWith="开头字符" opContains="包含" opIsEmpty="为空" opNotEqual="不等于" className="" alert="false" size="25" maxlength="" autocomplete="" titleStyle="" hideIgnoreCase=false ignCase=true ignoreCase="忽略大小写" />
<@renderTooltip tooltip="" tooltipStyle="" />
<@renderFormatFieldRowWidgetCellClose />
<@renderFormatFieldRowClose />
<@renderFormatFieldRowOpen />
<@renderFormatFieldRowTitleCellOpen  style="" />
<@renderFormatFieldRowTitleCellClose />
<@renderFormatFieldRowWidgetCellOpen  positionSpan=0 style="" />
<@renderTextFindField  name="categoryName" value="" defaultOption="contains" opEquals="等于" opBeginsWith="开头字符" opContains="包含" opIsEmpty="为空" opNotEqual="不等于" className="" alert="false" size="25" maxlength="" autocomplete="" titleStyle="" hideIgnoreCase=false ignCase=true ignoreCase="忽略大小写" />
<@renderTooltip tooltip="" tooltipStyle="" /><@renderFormatFieldRowWidgetCellClose />
<@renderFormatFieldRowClose />
<@renderFormatFieldRowOpen />
<@renderFormatFieldRowTitleCellOpen  style="" />
<@renderFormatEmptySpace />
<@renderFormatFieldRowTitleCellClose />
<@renderFormatFieldRowWidgetCellOpen  positionSpan=1 style="" />
<@renderSubmitField buttonType="button" className="smallSubmit" alert="false" formName="FindCategory" title="" name="submitButton" event="" action="" imgSrc="" containerId="" confirmation ="" ajaxUrl="" />
<@renderTooltip tooltip="" tooltipStyle="" />
<@renderFormatFieldRowWidgetCellClose />
<@renderFormatFieldRowClose />
<@renderFormatSingleWrapperClose formName="FindCategory"/>
<@renderFormClose  focusFieldName="" formName="FindCategory" containerId="FindCategory" hasRequiredField="" />
<@renderScreenEnd />

我想信,如果我们直接把以上这些语句写在一个ftl的文件中,那么大家一看都就明白了,现在ofbiz所作的工作,只是通过根据xml来运态的生成这些语句而已。

有了以上这些freemarker宏的调用语句还是不购的。还需要定义这些宏,这些宏是freemarker的语法要求的。在ofbiz的framwork目录下的widget组件下widget\templates中定义了很多种类形的宏模板,这些模板又通过widget.properties进行了配置。至此我们知道,如果我们想在改变最后from的展示,我们可以通过修改这些宏模板,即可以实现。另外,因为模板是通过widget.properties配置的,我们基于可以开发自己的模板,然后通过修改widget.properties中的配置,我们即可以方便的实现替换了。
  除此之外,在widget\templates下定义了多种类型的模板,可以有生成html的,pdf的,xml的。也就是说,我们可以让ofbiz生成我们想要的任何表达方式。需要说明的是除了html 之外,ofbiz的基它模板,现在还不成熟。在使用的过程中很可能会遇到不少错误,不过只要你愿意去调一下代码,相信很快可以解决的。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值