spring中有关freeer的配置如下:<bean id="cmsListDirective" class="com.wki.web.directive.CmsListDirective"/>
<bean id="freeMarkerConfigurer" class="org.springframework.web.servlet.view.freeer.FreeMarkerConfigurer">
<property name="freeerVariables">
<map>
<entry key="cms_list" value-ref="cmsListDirective"/>
</map>
</property>
<property name="freeerSettings">
<props>
<prop key="locale">zh_CN</prop>
<prop key="template_update_delay">0</prop>
<prop key="defaultEncoding">UTF-8</prop>
<prop key="url_escaping_charset">UTF-8</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>
</props>
</property>
</bean>
<bean id="viewResolver" class="org.springframework.web.servlet.view.freeer.FreeMarkerViewResolver">
<property name="cache" value="true"/>
<property name="prefix" value=""/>
<property name="suffix" value=".ftl"/>
<property name="exposeSpringMacroHelpers" value="true"/>
</bean>其中cmsListDirective 是自定义指令,问题在于该配置不起任何作用,在模版中调用<@cms_list></@cms_list>报未找到异常。我整个项目的环境是:urlrewrite + struts2 + mybatis + spring3.0 + freeer求各位指点迷津!
<bean id="freeMarkerConfigurer" class="org.springframework.web.servlet.view.freeer.FreeMarkerConfigurer">
<property name="freeerVariables">
<map>
<entry key="cms_list" value-ref="cmsListDirective"/>
</map>
</property>
<property name="freeerSettings">
<props>
<prop key="locale">zh_CN</prop>
<prop key="template_update_delay">0</prop>
<prop key="defaultEncoding">UTF-8</prop>
<prop key="url_escaping_charset">UTF-8</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>
</props>
</property>
</bean>
<bean id="viewResolver" class="org.springframework.web.servlet.view.freeer.FreeMarkerViewResolver">
<property name="cache" value="true"/>
<property name="prefix" value=""/>
<property name="suffix" value=".ftl"/>
<property name="exposeSpringMacroHelpers" value="true"/>
</bean>其中cmsListDirective 是自定义指令,问题在于该配置不起任何作用,在模版中调用<@cms_list></@cms_list>报未找到异常。我整个项目的环境是:urlrewrite + struts2 + mybatis + spring3.0 + freeer求各位指点迷津!
解决方案 »
- 一道java转码的问题
- action找不到
- [Fatal Error] :1:8: The processing instruction target matching "[xX][mM][lL]" is not allowed.
- 生成WORD文件
- 解决Oracle 9i和Tomcat端口冲突
- JAVA连接数据库问题(比较特殊)
- request.removeAttribute为什么移不掉值???在线等
- 求助:用jdbc连Oracle,ResultSet.getString()取得的值跟数据库中的不一样?
- ant_HOME是什么?
- 7年mm,有结局,撒分,java版每个都有,希望斑竹别删
- 关于JBPM子流程,脚本调用。
- java项目下载文件功能,用ie第一次下载txt文件,文件名会被修改急急急!
<property name="cache" value="false"/>
<property name="prefix" value=""/>
<property name="suffix" value=".html"/>
<property name="exposeSpringMacroHelpers" value="true"/>
<property name="exposeRequestAttributes" value="false"/>
<property name="exposeSessionAttributes" value="false"/>
<property name="contentType" value="text/html;charset=UTF-8"/>
<property name="requestContextAttribute" value="rc"></property>
</bean>
<bean id="freeerConfig" class="org.springframework.web.servlet.view.freeer.FreeMarkerConfigurer">
<property name="templateLoaderPath" value="/WEB-INF/template/front"/>
<property name="freeerVariables">
<map>
<entry key="cms_channel" value-ref="channelDirective"/>
<entry key="cms_channel_list" value-ref="channelListDirective"/>
<entry key="cms_content_list" value-ref="contentListDirective"/>
<entry key="cms_content" value-ref="contentContextlDirective"/>
<entry key="cms_navigation" value-ref="navigationDirective"/>
<entry key="cms_menu" value-ref="menuDirective"/>
<entry key="cms_hotcontent_list" value-ref="hotContentListDirective"/>
<entry key="cms_questionnaire_list" value-ref="questionnaireListDirective"/>
<entry key="cms_hotquestionnaire_list" value-ref="hotQuestionnaireListDirective"/>
<entry key="cms_relative_list" value-ref="relativeListDirective"/>
<entry key="cms_enterprise_list" value-ref="enterpriseListDirective"/>
<entry key="cms_region" value-ref="regionDirective"/>
<entry key="shiro_authenticated" value-ref="authenticatedTag"/>
<entry key="shiro_guest" value-ref="guestTag"/>
<entry key="shiro_hasAnyRoles" value-ref="hasAnyRolesTag"/>
<entry key="shiro_hasPermission" value-ref="hasPermissionTag"/>
<entry key="shiro_hasRole" value-ref="hasRoleTag"/>
<entry key="shiro_lacksPermission" value-ref="lacksPermissionTag"/>
<entry key="shiro_lacksRole" value-ref="lacksRoleTag"/>
<entry key="shiro_notAuthenticated" value-ref="notAuthenticatedTag"/>
<entry key="shiro_principal" value-ref="principalTag"/>
<entry key="shiro_user" value-ref="userTag"/>
</map>
</property>
<property name="freeerSettings">
<props>
<prop key="tag_syntax">auto_detect</prop>
<prop key="template_update_delay">5</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">#</prop>
<prop key="whitespace_stripping">true</prop>
<!--空值处理<prop key="classic_compatible">true</prop>-->
</props>
</property>
</bean>
我们是这么配的,只不过我们的bean使用annotation注入的,前台ftl是这么写的[@cms_channel][/@cms_channel]
我的bean也是使用annotation注入的,现在按照你的配置还是不起作用。
是不是struts2 的配置文件中还要加其他的内容?
我们freeer自定义标签是这样写的@Component
public class ChannelListDirective implements TemplateDirectiveModel {
// 栏目管理的业务类
@Autowired
private ChannelManager channelManager; /**
* execute 实现接口方法
*
* @param Environment
* env 上下文环境
* @param Map
* params 参数的map
* @param TemplateModel
* loopVars 循环变量
* @param TemplateDirectiveBody
* body
* @return void
* @throws 无
* ==============================================
* 2012-05-22 gooton-刘忠映 新增
* ==============================================
*/
public void execute(Environment env, Map params, TemplateModel[] loopVars,
TemplateDirectiveBody body) throws TemplateException, IOException {
// 父id
String parentId = params.get("parentId") == null ? null : params.get(
"parentId").toString();
// 站点ID
String siteId = params.get("siteId") == null ? null : params.get(
"siteId").toString();
// 是否有内容
String hasContent = params.get("hasContent") == null ? null : params
.get("hasContent").toString();
// 生成查询对象
Search search = Search.build();
// 父id存在
if (!StringUtils.isBlank(parentId)) {
search.addFilterEqual("parent.id", Long.parseLong(parentId));
} else {
search.addFilterEqual("level", "0");
} // 站点id存在
if (!StringUtils.isBlank(siteId)) {
search.addFilterEqual("site.id", Long.parseLong(siteId));
}
// 是否有内容
if (!StringUtils.isBlank(hasContent)) {
search.addFilterEqual("hasContent", "1".equals(hasContent) ? true
: false);
}
search.addFilterEqual("sysFlag", "1");
// 按优先级排序
search.addSortAsc("priority");
List<Channel> channels = channelManager.findChannelList(search);
env.setVariable(Constant.OUT_LIST, DEFAULT_WRAPPER.wrap(channels));
body.render(env.getOut());
}
}
是struts2配置文件中还要加一段配置:<constant name="struts.freeer.manager.classname" value="com.wki.commons.freeer.FreeerManager"/>
public class FreeerManager extends
org.apache.struts2.views.freeer.FreeerManager { protected Configuration createConfiguration(ServletContext servletContext)
throws TemplateException {
FreeMarkerConfigurer configurer = (FreeMarkerConfigurer) BeanUtils
.getContext(servletContext).getBean("freeMarkerConfigurer");
return configurer.getConfiguration();
}}这样就行了。