freemarker

Freemarker/Velocity - date manipulation

拈花ヽ惹草 提交于 2019-12-04 14:48:15
问题 I have a fairly simple question about these 2 templating engines. I'm trying to make a future/past date, a fixed time from now, e.g. 18 months ago, or tomorrow. I know that it is possible to do this with a java date object inside a velocity/freemarker template (something like $date.add(2,-18) ), but I would like to do this with DateTool or freemarker core. This is something that I see as purely presentational (just think at the default dates you see in flight booking forms), so I can't see

Keycloak Remove First Name and Last Name fields on Registration Screen

六月ゝ 毕业季﹏ 提交于 2019-12-04 14:42:12
In Keycloak we have a created a custom ftl registration theme that has removed the optional first name and last name fields. Our system only requires the user to have an email address and password. However when the user hits enter an error is displayed indicating that the first name and last name need to be entered. In the Keycloak UserModel these fields are optional, and it is also possible to create users via the admin console / api without firstname and lastname. How do we remove these fields from the keycloak form validation on the registration screen? Profile Validation can be disabled

JSP tags in a Freemarker template

只愿长相守 提交于 2019-12-04 13:12:35
问题 I want to use some custom tags in a freemarker template which is easy enough as I can include the JspSupportServlet in my web.xml file and include the folowing line in the template. <#assign my=JspTaglibs["/WEB-INF/mytaglib.tld"] /> However how do I go about doing this if the .tld is bundled in a JAR file inside the META-INF directory? I tried both of these with no luck. <#assign my=JspTaglibs["/META-INF/mytaglib.tld"] /> <#assign my=JspTaglibs["/mynamespace"] /> 回答1: FreeMarker automatically

Better template language needed [closed]

非 Y 不嫁゛ 提交于 2019-12-04 11:06:51
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 5 years ago . Yes, I know that this has been asked before. But most of the questions were two years ago, and there's got to be a better answer today. I need a template language for rendering HTML. Requirements: Must be callable from Java. Must not be Freemarker, Velocity, or StringTemplate. We've been using Freemarker for a

spring security 3.2.0 csrf token not working in freemarker template

[亡魂溺海] 提交于 2019-12-04 10:07:32
After uprading to Spring Security 3.2.0 and configuring the xml, the _csrf token is not working. Fundamentals: Spring 4.0.1 Spring Security 3.2.0. Freemarker Template Language Step 1 - the spring security xml configuration: <!-- enable csrf protection via csrf-element --> <sec:http> <!-- --> <sec:csrf token-repository-ref="csrfTokenRepository" /> </sec:http> <!-- rewrite headerName --> <bean id="csrfTokenRepository" class="org.springframework.security.web.csrf.HttpSessionCsrfTokenRepository"> <property name="headerName" value="X-SECURITY" /> </bean> Step 2 - the freemarker template: <form

Freemarker, PDF, Header/Footer and page-breaks

时光怂恿深爱的人放手 提交于 2019-12-04 09:32:40
A common use of Freemarker is the generation of a PDF. Unfortunally I have to generate a pdf with a lot of pages and "they" asking me to put an header with some information and a footer with somethings like "page 2/60" etc... Searching on web I found how to create a Macro template but it only share some common tags (like css) but it doesn't tell freemarker how to manage multipage PDF. In addition to this, sometimes I have, inside ftl, a "page-break css class" so I cant determine when and where a new page is created. Im using Freemakrer 2.3 on Java Thanks for any help. You can specify a header

Spring Boot 集成 FreeMarker

旧巷老猫 提交于 2019-12-04 08:05:10
使用 FreeMarker 作为页面展示 FreeMarker是一种比较简单的网页展示技术,是网页模板和数据模型的结合体。这种结合模式的好处就是,分离了网页界面设计人员和编程人员的工作,让他们各司其职。 一、build.gradle 中增加 FreeMarker 依赖: compile "org.springframework.boot:spring-boot-starter-freemarker" 二、src/main/resources 中创建 application.properties 文件,内容如下: spring.freemarker.cache=false spring.freemarker.charset=UTF-8 spring.freemarker.check-template-location=true spring.freemarker.content-type=text/html spring.freemarker.expose-request-attributes=true spring.freemarker.expose-session-attributes=true spring.freemarker.request-context-attribute=request 或在application.yml中增加配置: spring:

@ControllerAdvice 拦截异常并统一处理

末鹿安然 提交于 2019-12-04 07:18:31
在spring 3.2中,新增了@ControllerAdvice 注解,可以用于定义@ExceptionHandler、@InitBinder、@ModelAttribute,并应用到所有@RequestMapping中。 一、介绍 创建 MyControllerAdvice,并添加 @ControllerAdvice注解。 package com.sam.demo.controller; import org.springframework.ui.Model; import org.springframework.web.bind.WebDataBinder; import org.springframework.web.bind.annotation.ControllerAdvice; import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.InitBinder; import org.springframework.web.bind.annotation.ModelAttribute; import org.springframework.web.bind.annotation.ResponseBody;

Feemarker writing images to html

浪尽此生 提交于 2019-12-04 07:04:41
is there anyway to write image in freemarker instead of giving link as <img src="${pathToPortalImage} Note : cant we use otputstream or something in freemarker ? You can embed the image as base64 directly inside the html img tag. To convert an image to base 64 you can use Apache Commons (codec) . Here is a solution using Apache Commons IO + Codec (but you can do without if you want): File img = new File("file.png"); byte[] imgBytes = IOUtils.toByteArray(new FileInputStream(img)); byte[] imgBytesAsBase64 = Base64.encodeBase64(imgBytes); String imgDataAsBase64 = new String(imgBytesAsBase64);

SpringBoot | 第二十六章:邮件发送

我与影子孤独终老i 提交于 2019-12-04 05:52:39
前言 讲解了日志相关的知识点后。今天来点相对简单的,一般上,我们在开发一些注册功能、发送验证码或者订单服务时,都会通过短信或者邮件的方式通知消费者,注册或者订单的相关信息。而且基本上邮件的内容都是模版,一些差异化的可根据实际情况来进行替换。比如12306购票成功后,会发送一封购票信息邮件;在京东下单成功后,也会收到一封包含订单的邮件。所以,今天就来讲讲如何利用 Spring 提供的 JavaMailSender 接口,实现邮件发送功能。 一点知识 讲解前,我们先来简单了解下相关邮件知识。 JavaMail介绍 JavaMail 是由 Sun 定义的一套收发电子邮件的 API ,不同的厂商可以提供自己的实现类。但它并没有包含在JDK中,而是作为 JavaEE 的一部分。而 JavaMailSender 底层也是基于 JavaMail jar包的,官网介绍时就说了依赖关系: 邮件通信协议 SMTP:简单邮件传输协议,用于发送电子邮件的传输协议; POP3:用于接收电子邮件的标准协议; IMAP:互联网消息协议,是POP3的替代协议。 这三种协议都有对应SSL加密传输的协议,分别是 SMTPS , POP3S 和 IMAPS 。除 JavaMail 服务提供程序之外, JavaMail 还需要 JAF(JavaBeans Activation Framework)