我正在尝试使用freemarker创建一个struts2组件.我ftl用这样的代码创建了一个文件:
<script type="text/javascript" src="${parameters.library?default('')}"></script>
Run Code Online (Sandbox Code Playgroud)
期望一个名为library传递给组件的参数.如果参数不存在则默认为空白String.
在我的JSP页面上,我指的是这样的组件:
<s:component template="mytemplate.ftl">
<s:param name="library" value="/scripts/mylibrary.js"/>
</s:component>
Run Code Online (Sandbox Code Playgroud)
不幸的是,没有设置library参数的值.它总是一片空白String.
我正在使用本教程中的建议,似乎s:param标记应该将参数传递给模板并使其可用.我在这里错过了什么?
有没有人有一些建立这些组件的经验可以解决一些问题?
谢谢.
我在Spring中使用freemarker.
这是我配置我的freemarker的方式:
<bean id="freemarkerConfiguration" class="org.springframework.ui.freemarker.FreeMarkerConfigurationFactoryBean">
<property name="templateLoaderPath" value="classpath:/META-INF/templates"/>
</bean>
Run Code Online (Sandbox Code Playgroud)
这个配置实际上工作正常,我能够使用模板等生成我的报告.
但是在Weblogic中,我总是得到这个例外:
15 Sep 2012 01:03:02,060 DEBUG DefaultListableBeanFactory.doCreateBean:504 - Eagerly caching bean 'freemarkerConfiguration' to allow for resolving potential circular references
15 Sep 2012 01:03:02,074 DEBUG DefaultListableBeanFactory.invokeInitMethods:1498 - Invoking afterPropertiesSet() on bean with name 'freemarkerConfiguration'
15 Sep 2012 01:03:02,228 DEBUG FreeMarkerConfigurationFactoryBean.getTemplateLoaderForPath:360 - Cannot resolve template loader path [classpath:/META-INF/templates] to [java.io.File]: using SpringTemplateLoader as fallback
java.io.FileNotFoundException: class path resource [META-INF/templates] cannot be resolved to absolute file path because it does not reside in …Run Code Online (Sandbox Code Playgroud) 我的EmailHandler类如下:
Class EmailHandler {
...
@Autowired
protected Configuration config;
}
...
protected Template getTemplate(String templateName, Locale locale) throws IOException, TemplateException {
return config.getTemplate(templateName, locale);
}
...
}
Run Code Online (Sandbox Code Playgroud)
在我的applicationcontext.xml中,我有
<bean id="freemarkerConfiguration" class="org.springframework.ui.freemarker.FreeMarkerConfigurationFactoryBean">
<property name="templateLoaderPath" value="classpath:/templates/email"/>
</bean>
Run Code Online (Sandbox Code Playgroud)
我的模板目录结构如下:
--src
----main
------resources
--------templates
----------email
------------template1.ftl
------------template2.ftl
------------template3.ftl
------------template4.ftl
------------multilanguage
--------------fr
----------------template1.ftl
Run Code Online (Sandbox Code Playgroud)
目前,getTemplate始终使用(string,Locale.US)进行调用。但是,将来,我希望能够使用(string,Locale.FR)调用getTemplate。
以下是我的问题:1.如何更改目录结构以指定法语模板。2. config.getTemplate(templateName,locale)是什么?到底是做什么的?该方法如何在模板目录中找到Locale.US的模板?3.我想从email / multilanguage / fr目录加载我的法语模板。我怎么做?
谢谢,
里士
我努力为这个问题命名.我试图解决的问题与此处描述的问题非常相似,但我没有提交bean的列表,而是提交表示模型对象中的地图的http请求参数,让框架(Spring)负责构建地图来自http请求参数.有人可以建议最好的做法/最干净的方法吗?任何帮助将非常感激.
目前我传递两个String数组,然后在保存到模型对象之前将它们转换为映射.我认为必须有一个更好的方法来做到这一点.
我使用Spring MVC和Freemarker进行视图渲染.
说明代码:
模型对象:
public class Foo {
private Map<String, String> barMap;
// other member variables...
}
Run Code Online (Sandbox Code Playgroud)
查看fremarker模板:
<#list foo.barMap?keys as currKey>
<tr id="barList_${currKey_index}">
<td><input name="key" type="text" value="${currKey}"/></td>
<td><input name="value" type="text" value="${foo.barMap[currKey]}"/></td>
</tr>
</#list>
Run Code Online (Sandbox Code Playgroud)
控制器:
@RequestMapping(value = "/foo", method = RequestMethod.POST)
public String foo (Model model,
@RequestParam(value="key", required=false) String[] keys,
@RequestParam(value="value", required=false) String[] values) {
Foo foo = new Foo();
Map<String, String> barMap = new HashMap<String, String>();
if (keys != null && values != null && …Run Code Online (Sandbox Code Playgroud) 我的Web应用程序使用Spring MVC和Freemarker.当它在启动后必须首先呈现网页(使用Freemarker 2.3.22)时,它会记录一条警告消息:
Custom EL functions won't be loaded because no ObjectWarpper was specified
Run Code Online (Sandbox Code Playgroud)
(是的,ObjectWarpper错误信息有拼写错误)
不过,我觉得我做了一个ObjectWrapper在我的配置Bean规定:
<bean id="freemarkerConfig" class="org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer">
<property name="templateLoaderPath" value="/WEB-INF/views/" />
<property name="freemarkerSettings">
<props>
<prop key="url_escaping_charset">UTF-8</prop>
<prop key="object_wrapper">DefaultObjectWrapper(2.3.22)</prop>
</props>
</property>
</bean>
Run Code Online (Sandbox Code Playgroud)
那么我该怎样做才能正确设置ObjectWrapper并防止记录此警告消息?
如果我使用的话,我也有同样的问题default object_wrapper.
我正在使用将FreeMarker用于视图的Spring MVC应用程序。
我绝对是FreeMarker的新手,但我遇到以下问题:在我的项目中,我必须将3个文件组装成单个页面。
所以我有:
1)header.ftl代表我所有页面的标题,如下所示:
<!DOCTYPE html>
<!--[if IE 8]><html class="no-js is-ie8"><![endif]-->
<!--[if gt IE 8]><!--><html class="no-js"><!--<![endif]-->
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Registrazione - MY WEBSITE</title>
<meta name="robots" content="noindex,nofollow">
<link rel="stylesheet" href="resources/css/webfont.css">
<link rel="stylesheet" href="resources/bootstrap/css/bootstrap.min.css">
<link rel="stylesheet" href="resources/bootstrap/css/bootstrap-theme.min.css">
<link rel="stylesheet" href="resources/plugins/bs-select/bootstrap-select.min.css">
<link rel="stylesheet" href="resources/plugins/bs-dialog/bootstrap-dialog.min.css">
<link rel="stylesheet" href="resources/css/style.css" />
</head>
<body id="main">
<!-- versione per popup. non prendere in considerazione -->
<!--
<div class="container page-header">
<h1>MY WEBSITE</h1>
</div>
Run Code Online (Sandbox Code Playgroud)
2)footer.ftl …
我有一个FreeMarker变量,${string}可以是任何长度.我怎样才能获得最后四个字符?
例如:
string ="326235253235235";
我要显示:"5235";
我正在寻找一种简洁的方法来将字符串重复n次,其中n是一个变量。我在文档中找不到能做到这一点的好方法。
我正在尝试使用Netsuite中的Advanced PDF为Bill of Materials创建打印输出.我正在使用源代码.如何将打印的方向从纵向更改为横向?我知道在使用WYSWYG时,我只需在模板设置中选择方向,但在使用源代码时该选项不可用.
谢谢!
如何初始化即时类型?
我试过这个:
Instant instant = new Instant();
Run Code Online (Sandbox Code Playgroud)
但是不起作用..
我需要它,因为在Freemarker之后我必须这样做:
[#assign dateFormated = newDate.from(instant.ofEpochSecond(data.time.seconds))/]
Run Code Online (Sandbox Code Playgroud) freemarker ×10
java ×4
spring ×3
spring-mvc ×3
bfo ×1
classpath ×1
components ×1
date ×1
html ×1
localization ×1
netsuite ×1
pdf ×1
struts2 ×1
substring ×1
templates ×1