How to display the current date and time in the Freemarker templates section for smooks?

I can display the contents of my incoming XML file using smooks in the freemarker template, but I want to add the current date and time of my local system to identify the execution of my program.

<ftl:freemarker applyOnElement="CreditCard"> <ftl:template><!-- <BalanceInquiryRequest> <TransactionId>${BalanceInquiryRequest.TransactionId}</<TransactionId> <ConfigurationId>${BalanceInquiryRequest.ConfigurationId}</ConfigurationId> <CardNumberr>${.vars["GiftCard"].CardNumber}</CardNumberr> <ExpirationDate>${.vars["GiftCard"].ExpirationDate}</ExpirationDate> <SecurityCode>${.vars["GiftCard"].SecurityCode}</SecurityCode> ***************************** Here I want to display the current Date & time </BalanceInquiryRequest> --></ftl:template> </ftl:freemarker> 

Can you tell me how to add the current date and time in XML without having a record in the incoming XML.

+4
source share
5 answers

use.now, they introduced it some time ago, no java needed

+6
source

There seems to be an answer here. The short answer is you have to go through Java.

+3
source

You cannot do this because XML, like Freemarker, is a template engine, not an object. You must pass it to the java object as new Date();

0
source

You can write a short groovy script in the Smooks configuration file to populate the bean in a beancontext with today's date. Then the freemarker script can use the value from this bean.

Edit: you can learn more about groovy and smooks here: http://www.smooks.org/mediawiki/index.php?title=V1.3:Smooks_v1.3_User_Guide#Groovy_Scripting

You will probably want to use the methods from http://www.milyn.org/javadoc/v1.2/smooks-cartridges/javabean/org/milyn/javabean/repository/BeanRepository.html and do something similar to:

  <g:groovy executeOnElement="xxx"> <g:script> <!-- addBean("date", new Date()); --> </g:script> </g:groovy> 

You can then access the "date" of the bean in your freemarker.

0
source

You can do this without .now, and you do not need to pass a new date. I need to work with an old freemarker at the moment and did it instead.

 <#assign dateNow = Static["java.util.Calendar"].getInstance().getTime()?datetime /> 
0
source

Source: https://habr.com/ru/post/1300183/


All Articles