╰☆把酒言欢
                               聪明出于勤奋,天才在于积累.

 screen widget 本质是基于freemarker 的。 目前screen类型的view基本都是MacroScreenViewHandler.java 负责处理的。

 MacroScreenViewHandler.java render 方法中首先通过配置文件加载了三个类库。如下

 

ScreenStringRenderer screenStringRenderer = new MacroScreenRenderer(UtilProperties.getPropertyValue("widget", getName() + ".name"), UtilProperties.getPropertyValue("widget", getName() + ".screenrenderer"));  
FormStringRenderer formStringRenderer = new MacroFormRenderer(UtilProperties.getPropertyValue("widget", getName() + ".formrenderer"), request, response);  
TreeStringRenderer treeStringRenderer = new MacroTreeRenderer(UtilProperties.getPropertyValue("widget", getName() + ".treerenderer"), writer);  

 

正式render 页面前后,利用freemarker 编译了两个宏指令

screenStringRenderer.renderScreenBegin(writer, screens.getContext());  
          screens.render(page);  
          screenStringRenderer.renderScreenEnd(writer, screens.getContext());  

 

public void renderScreenBegin(Appendable writer, Map<String, Object> context) throws IOException {  
       executeMacro(writer, "renderScreenBegin", null);  
   }  
  
   public void renderScreenEnd(Appendable writer, Map<String, Object> context) throws IOException {  
       executeMacro(writer, "renderScreenEnd", null);  
   }  

宏指令定义为

<#macro renderScreenBegin>  
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
</#macro>  
  
<#macro renderScreenEnd>  
</#macro>  

screen widget 大概处理过程。获取screnn 第一个section ,解析处理action(预处理所需数据)condition,根据condition结果决定处理子widget是widget还是fail-widget 。子widget的处理过程和上层widget类似。如此深入。具体的没有嵌套的screen widget 可以使用上述freemarker 类库来编译成html。

posted on 2012-10-25 16:28  把酒言欢  阅读(1165)  评论(0编辑  收藏  举报