Error executing FreeMarker template

cancel
Showing results for 
Search instead for 
Did you mean: 
P_Giannuzzi
Member II

Error executing FreeMarker template

Hello everyone,

I'm doing some practice with Alfresco 5.2 (Community), to understand its mechanisms.

I'm trying to understand the customizable constraints through Java class, and to do this I followed (slightly adapting it) the example provided at this link  https://hub.alfresco.com/t5/alfresco-content-services-hub/content-model-constraints/ba-p/289687 

But when I open the form the console returns the Error executing FreeMarker template error

What am I doing wrong? I am attaching content model, java class and console log.

 

CONTENT MODEL

<constraints>
     <constraint name="trbar:FactorsOf" type="com.went.platformsample.Multipli">
<parameter name="multipleOf"><value>2</value></parameter> </constraint>
</constraints>

 

<property name="trbar:Eta">
	<title>Età</title>
	<description>Età</description>
	<type>d:int</type>
	<mandatory>true</mandatory>
	<index enabled="true">
		<tokenised>true</tokenised>
		<facetable>true</facetable>
	</index>
	<constraints>
		<constraint ref="trbar:FactorsOf" />
	</constraints>
</property>

 

Multipli.java

package com.went.platformsample;

import java.util.HashMap;
import java.util.Map;

import org.alfresco.service.cmr.dictionary.Constraint;

public class Multipli implements Constraint {
	private Integer multipleOf = 0;

	@Override
	public Map<String, Object> getParameters() {

		System.out.println("getParameters");

		System.out.println("1 valore di multipleOf = " + multipleOf);
		System.out.println("2 valore di multipleOf = " + this.multipleOf);
		Map<String, Object> params = new HashMap<String, Object>(2);

		params.put("multipleOf", this.multipleOf);
		
		System.out.println("3 valore di multipleOf = " + params.get("multipleOf"));
		
		System.out.println("Params = " + params);
		
		return params;
	}

	@Override
	public String getType() {
		System.out.println("getType");
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public String getTitle() {
		System.out.println("getTitle");
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public String getShortName() {
		System.out.println("getShortName");
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public void initialize() {
		System.out.println("initialize");
		// TODO Auto-generated method stub

	}

	@Override
	public void evaluate(Object value) {
		System.out.println("evaluate");
		// TODO Auto-generated method stub

	}

	public Integer getMultipleOf() {
		System.out.println("getMultipleOf " + multipleOf);
		return multipleOf;
	}

	public void setMultipleOf(Integer multipleOf) {
		System.out.println("setMultipleOf " + multipleOf);
		this.multipleOf = multipleOf;
	}

}

Console log

2021-08-20 09:40:21,110  ERROR [freemarker.runtime] [http-bio-8080-exec-13] Error executing FreeMarker template
 FreeMarker template error:
The following has evaluated to null or missing:
==> jsonUtils.encodeJSONString(x)  [in template "org/alfresco/repository/forms/formdefinition.lib.ftl" at line 14, column 15]

Tip: If the failing expression is known to be legally null/missing, either specify a default value with myOptionalVar!myDefault, or use <#if myOptionalVar??>when-present<#else>when-missing</#if>. (These only cover the last step of the expression; to cover the whole expression, use parenthessis: (myOptionVar.foo)!myDefault, (myOptionVar.foo)??

The failing instruction (FTL stack trace):
----------
==> ${cnstrnt.type} auto-escaped  [in template "org/alfresco/repository/forms/formdefinition.lib.ftl" in macro "formDefJSON" at line 45, column 36]
    #if field.dataType??  [in template "org/alfresco/repository/forms/formdefinition.lib.ftl" in macro "formDefJSON" at line 36, column 21]
    @formDefLib.formDefJSON form=form  [in template "org/alfresco/repository/forms/formdefinition.post.json.ftl" at line 2, column 1]
----------

Java stack trace (for programmers):
----------
freemarker.core.InvalidReferenceException: [... Exception message was already printed; see it above ...]
	at freemarker.core.InvalidReferenceException.getInstance(InvalidReferenceException.java:98)
	at freemarker.core.EvalUtil.coerceModelToString(EvalUtil.java:382)
	at freemarker.core.Expression.evalAndCoerceToString(Expression.java:115)
	at freemarker.core.DollarVariable.accept(DollarVariable.java:76)
	at freemarker.core.Environment.visit(Environment.java:265)
	at freemarker.core.MixedContent.accept(MixedContent.java:93)
	at freemarker.core.Environment.visitByHiddingParent(Environment.java:286)
	at freemarker.core.IteratorBlock$Context.runLoop(IteratorBlock.java:193)
	at freemarker.core.Environment.visitIteratorBlock(Environment.java:509)
	at freemarker.core.IteratorBlock.accept(IteratorBlock.java:103)
	at freemarker.core.Environment.visit(Environment.java:265)
	at freemarker.core.MixedContent.accept(MixedContent.java:93)
	at freemarker.core.Environment.visitByHiddingParent(Environment.java:286)
	at freemarker.core.ConditionalBlock.accept(ConditionalBlock.java:86)
	at freemarker.core.Environment.visit(Environment.java:265)
	at freemarker.core.MixedContent.accept(MixedContent.java:93)
	at freemarker.core.Environment.visit(Environment.java:265)
	at freemarker.core.IfBlock.accept(IfBlock.java:84)
	at freemarker.core.Environment.visit(Environment.java:265)
	at freemarker.core.MixedContent.accept(MixedContent.java:93)
	at freemarker.core.Environment.visitByHiddingParent(Environment.java:286)
	at freemarker.core.IteratorBlock$Context.runLoop(IteratorBlock.java:193)
	at freemarker.core.Environment.visitIteratorBlock(Environment.java:509)
	at freemarker.core.IteratorBlock.accept(IteratorBlock.java:103)
	at freemarker.core.Environment.visit(Environment.java:265)
	at freemarker.core.MixedContent.accept(MixedContent.java:93)
	at freemarker.core.Environment.visit(Environment.java:265)
	at freemarker.core.EscapeBlock.accept(EscapeBlock.java:85)
	at freemarker.core.Environment.visit(Environment.java:265)
	at freemarker.core.Macro$Context.runMacro(Macro.java:209)
	at freemarker.core.Environment.visit(Environment.java:694)
	at freemarker.core.UnifiedCall.accept(UnifiedCall.java:116)
	at freemarker.core.Environment.visit(Environment.java:265)
	at freemarker.core.MixedContent.accept(MixedContent.java:93)
	at freemarker.core.Environment.visit(Environment.java:265)
	at freemarker.core.Environment.process(Environment.java:243)
	at org.alfresco.repo.template.FreeMarkerProcessor.process(FreeMarkerProcessor.java:230)
	at org.springframework.extensions.webscripts.AbstractWebScript.renderTemplate(AbstractWebScript.java:967)
	at org.springframework.extensions.webscripts.DeclarativeWebScript.renderFormatTemplate(DeclarativeWebScript.java:267)
	at org.springframework.extensions.webscripts.DeclarativeWebScript.execute(DeclarativeWebScript.java:147)
	at org.alfresco.repo.web.scripts.RepositoryContainer$3.execute(RepositoryContainer.java:512)
	at org.alfresco.repo.transaction.RetryingTransactionHelper.doInTransaction(RetryingTransactionHelper.java:464)
	at org.alfresco.repo.web.scripts.RepositoryContainer.transactionedExecute(RepositoryContainer.java:587)
	at org.alfresco.repo.web.scripts.RepositoryContainer.transactionedExecuteAs(RepositoryContainer.java:656)
	at org.alfresco.repo.web.scripts.RepositoryContainer.executeScriptInternal(RepositoryContainer.java:428)
	at org.alfresco.repo.web.scripts.RepositoryContainer.executeScript(RepositoryContainer.java:308)
	at org.springframework.extensions.webscripts.AbstractRuntime.executeScript(AbstractRuntime.java:399)
	at org.springframework.extensions.webscripts.AbstractRuntime.executeScript(AbstractRuntime.java:210)
	at org.springframework.extensions.webscripts.servlet.WebScriptServlet.service(WebScriptServlet.java:132)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:770)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
	at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
	at org.alfresco.web.app.servlet.GlobalLocalizationFilter.doFilter(GlobalLocalizationFilter.java:68)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
	at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
	at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1041)
	at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:603)
	at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	at java.lang.Thread.run(Thread.java:748)
2021-08-20 09:40:21,125  ERROR [extensions.webscripts.AbstractRuntime] [http-bio-8080-exec-13] Exception from executeScript: 07200002 Wrapped Exception (with status template): 07200019 Errore durante l'elaborazione del modello 'The following has evaluated to null or missing:
==> jsonUtils.encodeJSONString(x)  [in template "org/alfresco/repository/forms/formdefinition.lib.ftl" at line 14, column 15]

The impression is that the error is generated when the "return params;" at the end of the Map method.

Thanks in advance for the help.

 

 

6 Replies
cristinamr
Advanced

Re: Error executing FreeMarker template

It's failling the view because the value is missing or null. How are you getting and displaying those values?

--
VenziaIT: helping companies since 2005! Our ECM products: AQuA & Seidoc
P_Giannuzzi
Member II

Re: Error executing FreeMarker template

I had thought of this too, and in fact I put some logs on the console, and the log I print just before "return params;" shows the content of the object correctly valued.

The impression is that something is missing, but I can't understand what.

cristinamr
Advanced

Re: Error executing FreeMarker template

Please share with us your code or what results are you expecting.

When you add a contraint in a model you need to manage the view too. Usually, it's defined under share-config-custom.xml (to display under Share UI). Did you develop this part?

More info here and here.

--
VenziaIT: helping companies since 2005! Our ECM products: AQuA & Seidoc
P_Giannuzzi
Member II

Re: Error executing FreeMarker template

The view part I have already developed and, before I added this constraint to the content-model, it worked perfectly.

Furthermore, the guide I found from which I tried to generate the constraint does not say in any way (nor have I found other references) of the views.

But as I said, I am convinced that something is missing but I don't understand what.

cristinamr
Advanced

Re: Error executing FreeMarker template

Share with us the view part :-)

--
VenziaIT: helping companies since 2005! Our ECM products: AQuA & Seidoc
P_Giannuzzi
Member II

Re: Error executing FreeMarker template

This is the part affected by the constraint, which worked correctly before I applied it.

In addition, I have also defined the other evaluator.

 

<config condition="trbar:IusPrimeNoctis" evaluator="model-type">
		<forms>
			<form>
				<field-visibility>
					<show id="trbar:Eta" />
				</field-visibility>
				<appearance>
					<set appearance="whitespace" id="trbar:IusPrimeNoctis_cmm_set0" />
					<field id="trbar:Eta" set="trbar:IusPrimeNoctis_cmm_set0"></field>

				</appearance>
			</form>
			
		</forms>
	</config>