Hi Daniel, Thanks for the remarks and hints! Please see my question inline.
On Sat, Aug 26, 2017 at 4:50 AM, Daniel Dekany <[email protected]> wrote: > Saturday, August 26, 2017, 10:44:03 AM, Daniel Dekany wrote: > > [snip] >> <#macro foo> >> <#local status = 'blah'> >> <@spring.bind "user.name"> >> ${status.value} <#-- Means 'blah'.value, won't work --> > > To clarify, here I have assumed that spring.bind calls > env.setVariable("status", ...) internally. Then the local with the > same name shadows that tempolate-namespace scoped variable. It seems working with env.setVariable("status", ...): // Excerpt from https://github.com/woonsan/incubator-freemarker/blob/feature/FREEMARKER-55-2/freemarker-spring/src/main/java/org/apache/freemarker/spring/model/BindDirective.java @Override public void execute(TemplateModel[] args, CallPlace callPlace, Writer out, Environment env) throws TemplateException, IOException { final ObjectWrapper objectWrapper = env.getObjectWrapper(); if (!(objectWrapper instanceof DefaultObjectWrapper)) { throw new TemplateException("The ObjectWrapper of environment wasn't instance of " + DefaultObjectWrapper.class.getName()); } // SNIP TemplateModel model = env.getDataModel().get(AbstractTemplateView.SPRING_MACRO_REQUEST_CONTEXT_ATTRIBUTE); RequestContext requestContext = (RequestContext) ((DefaultObjectWrapper) objectWrapper).unwrap(model); String resolvedPath = CallableUtils.getStringArgument(args, PATH_PARAM_IDX, this); // SNIP final TemplateModel oldStatusModel = env.getVariable(STATUS_VARIABLE_NAME); try { BindStatus status = requestContext.getBindStatus(resolvedPath); env.setVariable(STATUS_VARIABLE_NAME, new BeanModel(status, (DefaultObjectWrapper) objectWrapper)); callPlace.executeNestedContent(null, out, env); } finally { env.setVariable(STATUS_VARIABLE_NAME, oldStatusModel); } } Another question: is it okay to assume that I have a DefaultObjectWrapper when this directive is executed and throw an exception otherwise? > > [snip] >> With nested content parameter it's also more obvious what's going on, >> and if you chose a shorter name it's not that verbose either: >> >> <@spring.bind "user.name"; s> >> ${s.value} <#-- Means 'blah'.value, won't work --> If I choose to use nested content parameter instead of having env.setVariable() calls, how can I get access to the parameter, s? Can I access it through any argument of the #execute() method in the Java code? Any example java code using nested content parameter? Thanks in advance, Woonsan > [snip] > > Eh... of course the comment is outdated here. It will work in this > case. `s` can't be hidden by anyone there, it wouldn't mater if we had > <#local s = 'blah'> for example. > > -- > Thanks, > Daniel Dekany >
