一直不懂jeecms中<@p.table><@p.column/></@p.table>等标签是在哪个地方配置的,项目现在需要扩展@p.table标签的功能,在网上找了一天后终于找到了,并对freemarker有了大致的了解理。
1.由于项目是在jeecms中做的二次开发,第一步是去jeecms中下载源码查看配置。
web.xml
后台管理配置:
<servlet>
<servlet-name>JeeCmsAdmin</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/config/jeecms-servlet-admin.xml
/WEB-INF/config/plug/**/*-servlet-admin-action.xml
</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
2.进而查看jeecms-servlet-admin.xml
<bean id="freemarkerConfig" class="org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer">
<property name="templateLoaderPath" value="/WEB-INF"/>
<property name="freemarkerVariables">
<map>
<!--在FCK编辑器中需要用到appBase,以确定connector路径。-->
<entry key="appBase" value="/jeeadmin/jeecms"/>
<!--后台管理权限控制-->
<entry key="cms_perm" value-ref="cms_perm"/>
<entry key="text_cut" value-ref="text_cut"/>
<entry key="html_cut" value-ref="html_cut"/>
<entry key="cms_content_list" value-ref="cms_content_list"/>
<entry key="cms_content_page" value-ref="cms_content_page"/>
</map>
</property>
<property name="freemarkerSettings">
<props>
<prop key="template_update_delay">0</prop>
<prop key="defaultEncoding">UTF-8</prop>
<prop key="url_escaping_charset">UTF-8</prop>
<prop key="locale">zh_CN</prop>
<prop key="boolean_format">true,false</prop>
<prop key="datetime_format">yyyy-MM-dd HH:mm:ss</prop>
<prop key="date_format">yyyy-MM-dd</prop>
<prop key="time_format">HH:mm:ss</prop>
<prop key="number_format">0.######</prop>
<prop key="whitespace_stripping">true</prop>
<prop key="auto_import">/ftl/jeecms/index.ftl as p,/ftl/spring.ftl as s</prop>
</props>
</property>
</bean>
3.打开/ftl/jeecms/index.ftl:
<#ftl strip_whitespace=true>
<#include "ui/index.ftl"/>
<#include "operate_right.ftl"/>
很明显此文件嵌入了两个ftl文件。
4.继续查看ui/index.ftl
<#include "text.ftl"/>
<#include "select.ftl"/>
<#include "radio.ftl"/>
<#include "checkbox.ftl"/>
<#include "checkboxlist.ftl"/>
<#include "textarea.ftl"/>
<#include "hidden.ftl"/>
<#include "file.ftl"/>
<#include "tree.ftl"/>
<#include "table.ftl"/>
<#include "table-column.ftl"/>
<#include "button.ftl"/>
<#include "password.ftl"/>
<#include "editor.ftl"/>
<#include "form.ftl"/>
<#include "td.ftl"/>
<#include "tr.ftl"/>
<#include "self_define_widget.ftl"/>
<#include "self_define_register_widget.ftl"/>
看到了table.ftl 模板文件.
6.打开table.ftl:
<#--
表格标签:用于显示列表数据。
value:列表数据,可以是Pagination也可以是List。
class:table的class样式。默认"pn-ltable"。
sytle:table的style样式。默认""。
width:表格的宽度。默认100%。
-->
<#macro table value listAction="v_list.do" class="pn-ltable" style="" theadClass="pn-lthead" tbodyClass="pn-ltbody" width="100%" cellspacing="1">
<table class="${class}" style="${style}" width="${width}" cellspacing="${cellspacing}" cellpadding="0" border="0">
<#if value?is_sequence><#local pageList=value/><#else><#local pageList=value.list/></#if>
<#list pageList as row>
<#if row_index==0>
<#assign i=-1/>
<thead class="${theadClass}"><tr><#nested row,i,true/></tr></thead>
</#if>
<#assign i=row_index has_next=row_has_next/>
<#if row_index==0><tbody class="${tbodyClass}"><tr ><#else><tr ></#if><#nested row,row_index,row_has_next/>
<#if !row_has_next>
</tr></tbody>
<#else>
</tr>
</#if>
</#list>
</table>
找到了定义的table宏。
本文探讨在Jeecms二次开发中如何理解并使用FreeMarker的@p.table宏定义。从查看web.xml开始,逐步分析jeecms-servlet-admin.xml,到解析index.ftl和ui/index.ftl,最终在table.ftl中找到table宏的定义,揭示其在后台管理界面中的作用。

967

被折叠的 条评论
为什么被折叠?



