NIHVIVO-564 Dump directive displays a message rather than throwing an error if the variable is undefined in the data model.

This commit is contained in:
rjy7 2010-08-26 20:51:55 +00:00
parent fd53202f21
commit 3dbbf13cd7
5 changed files with 52 additions and 79 deletions

View file

@ -48,10 +48,16 @@ public class DumpHelper {
log.error("Error getting value of template model " + varName + " from data model.");
}
Map<String, Object> map = new HashMap<String, Object>();
map.put("var", varName);
if (tm != null) {
// Just use toString() method for now. Handles nested collections. Could make more sophisticated later.
String value = tm.toString();
String type = null;
String value = tm.toString();
Object unwrappedModel = null;
try {
unwrappedModel = DeepUnwrap.permissiveUnwrap(tm);
} catch (TemplateModelException e) {
@ -87,11 +93,9 @@ public class DumpHelper {
} else {
type = "object";
}
Map<String, Object> map = new HashMap<String, Object>();
map.put("var", varName);
map.put("value", value);
map.put("type", type);
}
return map;
}

View file

@ -1,15 +0,0 @@
<#-- $This file is distributed under the terms of the license in /doc/license.txt$ -->
<#-- Template for dumping hash values -->
<strong>Type:</strong> hash<br />
<strong>Values:</strong><br />
<ul>
<#list value?keys as key>
<#-- Shallow (non-recursive) dump -->
<li>${key} = ${value[key]}</li>
<#-- Deep (recursive) dump
<li>${key} = <@dump var="${value[key]}" /></li> -->
</#list>
</ul>

View file

@ -1,14 +0,0 @@
<#-- $This file is distributed under the terms of the license in /doc/license.txt$ -->
<#-- Template for dumping sequence (list and array) values -->
<strong>Type:</strong> sequence (array/list)<br />
<strong>Values:</strong><br />
<ul>
<#list value as item>
<#-- Shallow (non-recursive) dump -->
<li>${item_index}: ${item}</li>
<#-- Deep (recursive) dump
<li>${item_index}: <@dump var="${item}" /></li> -->
</#list>
</ul>

View file

@ -1,6 +0,0 @@
<#-- $This file is distributed under the terms of the license in /doc/license.txt$ -->
<#-- Template for dumping string values -->
<strong>Type:</strong> ${type}<br />
<strong>Value:</strong> ${value}<br />

View file

@ -5,8 +5,12 @@
<div class="var">
<h6>Variable name: <em>${var}</em></h6>
<#if value??>
<strong>Type:</strong> ${type}<br />
<strong>Value:</strong> ${value}<br />
<#else>
Variable is undefined in the data model
</#if>
</div>