Patch for _get tag to be able to return default body content

Bug #463682 reported by dunsun
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
play framework
Status tracked in 1.0
1.0
Fix Released
Undecided
Unassigned
1.1
Fix Committed
Undecided
Unassigned

Bug Description

Current _get tag does not accept body closure as a default content. Please could you modify this tag or add new _getDefault tag according to my solution ?

Current ORIGINAL _get tag:
public static void _get(Map args, Closure body, PrintWriter out, ExecutableTemplate template, int fromLine) {
        Object name = args.get("arg");
        if (name == null) {
            throw new TemplateExecutionException(template.template, fromLine, "Specify a variable name", new TagInternalException("Specify a variable name"));
        }
        Object value = Template.layoutData.get().get(name);
        if (value != null) {
            out.print(Template.layoutData.get().get(name));
        }
}

My MODIFIED _get tag:
public static void _getDefalt(Map args, Closure body, PrintWriter out, ExecutableTemplate template, int fromLine) {
        Object name = args.get("arg");
        if (name == null) {
            throw new TemplateExecutionException(template.template, fromLine, "Specify a variable name", new TagInternalException("Specify a variable name"));
        }
        Object value = Template.layoutData.get().get(name);
        if (value != null) {

            // MODIFICATION
            String strOut = Template.layoutData.get().get(name);
            // nothing was retrieved via get -> print a default body
            if(!(strOut != null && strOut.length() > 0)) {
               strOut = JavaExtensions.toString(body);
            }
            out.print(strOut);
        }
}

Revision history for this message
dunsun (dunsun) wrote :
Changed in play:
status: New → Confirmed
Changed in play:
status: Confirmed → Fix Committed
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.