NIHVIVO-304 TestWidget demonstrates the use of different markup macros based on Java logic.

This commit is contained in:
rjy7 2010-11-15 02:22:37 +00:00
parent 37d95fe5fc
commit d53a900e11
2 changed files with 16 additions and 9 deletions

View file

@ -8,6 +8,7 @@ import java.util.Map;
import javax.servlet.ServletContext; import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import edu.cornell.mannlib.vedit.beans.LoginStatusBean;
import freemarker.core.Environment; import freemarker.core.Environment;
public class TestWidget extends Widget { public class TestWidget extends Widget {
@ -16,8 +17,15 @@ public class TestWidget extends Widget {
protected WidgetTemplateValues process(Environment env, Map params, protected WidgetTemplateValues process(Environment env, Map params,
HttpServletRequest request, ServletContext context) { HttpServletRequest request, ServletContext context) {
Map<String, Object> map = new HashMap<String, Object>(); Map<String, Object> map = new HashMap<String, Object>();
map.put("fruit", "bananas"); String macroName;
return new WidgetTemplateValues (getMarkupMacroName(), map); if (LoginStatusBean.getBean(request).isLoggedIn()) {
map.put("status", "logged in");
macroName = "loggedIn";
} else {
map.put("status", "not logged in");
macroName = "notLoggedIn";
}
return new WidgetTemplateValues (macroName, map);
} }
} }

View file

@ -8,17 +8,16 @@
${headScripts.add("/js/testheadscript.js")} ${headScripts.add("/js/testheadscript.js")}
</#macro> </#macro>
<#macro markup> <#macro loggedIn>
<#import "lib-list.ftl" as l>
<div class="testWidget"> <div class="testWidget">
<h4>This is the test widget using macros.</h4> <h4>This is the test widget for logged-in users.</h4>
<p>I like ${fruit}.</p> <p>Login status: ${status}.</p>
</div> </div>
</#macro> </#macro>
<#macro altMarkup> <#macro notLoggedIn>
<div class="testWidget"> <div class="testWidget">
<h4>This is the alternate version of the test widget.</h4> <h4>This is the test widget for non-logged-in users.</h4>
<p>I hate ${fruit}.</p> <p>Login status: ${status}.</p>
</div> </div>
</#macro> </#macro>