<
From version < 15.1 >
edited by Vincent Massol
on 2014/09/19
To version < 16.1 >
edited by Vincent Massol
on 2014/09/19
>
Change comment: There is no comment for this version

Summary

Details

Page properties
Content
... ... @@ -78,6 +78,45 @@
78 78  * New URL Tool ##$urltool##: A [[new tool>>extensions:Extension.Velocity Module||anchor="HVelocityTools"]] has been added with one method to parse query string from the URL ##$urltool.parseQuery(String)##. The value returned by this is method is a ##Map<String, List<String>>## which maps parameter names to (possibly multiple) values, and can be passed e.g. directly into ##$escapetool.url(Map<String, ?>)## to convert it back to a string. This is useful e.g. in cases where one want to pass a complete query string around between requests, as it happend for the PDF export; the ##$urltool## allows for a sane deserialization of the value passed around.
79 79  * New Exception Tool ##$exceptiontool##: A [[new tool>>extensions:Extension.Velocity Module||anchor="HVelocityTools"]] to manipulate Java Exceptions (get root cause, convert into String, etc).
80 80  
81 +== Ability to catch Exceptions from Velocity ==
82 +
83 +A new Velocity Directive has been added to catch Exceptions from Velocity. In addition a new ###displayException()## velocity macro has also been added to nicely display an exception to the user.
84 +
85 +For example:
86 +
87 +{{code language="velocity"}}
88 +#try()
89 + #set($outputSyntax = $xwiki.getAvailableRendererSyntax($request.outputSyntax, $request.outputSyntaxVersion))
90 + #if ($outputSyntax)
91 + ## If the passed syntax is not an HTML-compatible syntax we need to HTML-escape it so that it can be
92 + ## displayed fine in HTML (since at the point this vm file is called we're already inside an HTML page with
93 + ## panels on the side, header, etc).
94 + #set($syntaxType = $outputSyntax.type.toIdString())
95 + #if (($syntaxType == "xhtml") || ($syntaxType == "html"))
96 + #set ($renderedContent = $tdoc.getRenderedContent($outputSyntax))
97 + #else
98 + ## Make sure to print correctly the result when it's not HTML
99 + #set ($renderedContent = "<pre>$escapetool.html($tdoc.getRenderedContent($outputSyntax))</pre>")
100 + #end
101 + #else
102 + #set ($renderedContent = $tdoc.getRenderedContent())
103 + #end
104 +#end
105 +...
106 +<div id="xwikicontent">
107 + #if ("$!exception" != '')
108 + #displayException($exception)
109 + #else
110 + $renderedContent
111 + #end
112 +</div>
113 +...
114 +{{/code}}
115 +
116 +This generates the following in case of error rendering the page:
117 +
118 +{{image reference="renderingerror.png"/}}
119 +
81 81  == Deprecated and Retired projects ==
82 82  
83 83  <description of deprecated and retired projects>

Get Connected