Velocity tools 3.0 have a new tool, LogTool enable you to log error message inside template with error method
Velocity Template debugging and Catch exceptions
Pergunta
How to print the exact line no of exception in Velocity Template at runtime?
I am using Veloeclipse for development to validate syntax related problems.. This works, but for Runtime based Exceptions information is missing.
I am sending a logging object to context of VT so when I want to log something I use the $logging.log(contenttobelogged)
If some exception occurs during runtime, the exception trace does not contain any line numer details of Velocity template.
For that I have to put my log for each lines , so log makes code nasty. Can you guide me to log errors with proper line number?
Exception Trace :
Template Name @@@@@@@@@@@@@@@@@@@@ yes/po/POSSellerRSPGridData_JSON.vm
org.apache.velocity.exception.MethodInvocationException: Invocation of method 'get' in class java.util.ArrayList threw exception class java.lang.IndexOutOfBoundsException : Index: 1, Size: 1
at org.apache.velocity.runtime.parser.node.ASTMethod.execute(ASTMethod.java:308)
at org.apache.velocity.runtime.parser.node.ASTReference.execute(ASTReference.java:202)
at org.apache.velocity.runtime.parser.node.ASTReference.value(ASTReference.java:345)
at org.apache.velocity.runtime.parser.node.ASTSetDirective.render(ASTSetDirective.java:135)
at org.apache.velocity.runtime.parser.node.ASTBlock.render(ASTBlock.java:94)
at org.apache.velocity.runtime.parser.node.ASTIfStatement.render(ASTIfStatement.java:109)
at org.apache.velocity.runtime.parser.node.ASTBlock.render(ASTBlock.java:94)
at org.apache.velocity.runtime.directive.Foreach.render(Foreach.java:344)
at org.apache.velocity.runtime.parser.node.ASTDirective.render(ASTDirective.java:153)
at org.apache.velocity.runtime.parser.node.ASTBlock.render(ASTBlock.java:94)
at org.apache.velocity.runtime.directive.Foreach.render(Foreach.java:344)
at org.apache.velocity.runtime.parser.node.ASTDirective.render(ASTDirective.java:153)
at org.apache.velocity.runtime.parser.node.SimpleNode.render(SimpleNode.java:271)
at org.apache.velocity.Template.merge(Template.java:296)
at ecnet.rd.core.template.TemplateResolver.merge(TemplateResolver.java:81)
at ecnet.rd.helper.YES_PO_Helper.mergerTemplateDetails(YES_PO_Helper.java:166)
Solução
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow