NIHVIVO-304 TestWidget demonstrates the use of different markup macros based on Java logic.
This commit is contained in:
parent
37d95fe5fc
commit
d53a900e11
2 changed files with 16 additions and 9 deletions
|
@ -8,6 +8,7 @@ import java.util.Map;
|
|||
import javax.servlet.ServletContext;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import edu.cornell.mannlib.vedit.beans.LoginStatusBean;
|
||||
import freemarker.core.Environment;
|
||||
|
||||
public class TestWidget extends Widget {
|
||||
|
@ -16,8 +17,15 @@ public class TestWidget extends Widget {
|
|||
protected WidgetTemplateValues process(Environment env, Map params,
|
||||
HttpServletRequest request, ServletContext context) {
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
map.put("fruit", "bananas");
|
||||
return new WidgetTemplateValues (getMarkupMacroName(), map);
|
||||
String macroName;
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -8,17 +8,16 @@
|
|||
${headScripts.add("/js/testheadscript.js")}
|
||||
</#macro>
|
||||
|
||||
<#macro markup>
|
||||
<#import "lib-list.ftl" as l>
|
||||
<#macro loggedIn>
|
||||
<div class="testWidget">
|
||||
<h4>This is the test widget using macros.</h4>
|
||||
<p>I like ${fruit}.</p>
|
||||
<h4>This is the test widget for logged-in users.</h4>
|
||||
<p>Login status: ${status}.</p>
|
||||
</div>
|
||||
</#macro>
|
||||
|
||||
<#macro altMarkup>
|
||||
<#macro notLoggedIn>
|
||||
<div class="testWidget">
|
||||
<h4>This is the alternate version of the test widget.</h4>
|
||||
<p>I hate ${fruit}.</p>
|
||||
<h4>This is the test widget for non-logged-in users.</h4>
|
||||
<p>Login status: ${status}.</p>
|
||||
</div>
|
||||
</#macro>
|
Loading…
Add table
Add a link
Reference in a new issue