[stringtemplate-interest] setAttribute() method chaining
Terence Parr
parrt at cs.usfca.edu
Thu Jan 22 22:09:25 PST 2009
Hi. a good idea. Though, I think it's easier to just do
jspTemplate.setAttributes(aMap);
and set aMap appropriately using Java stuff. Does HashMap allow
setter chaining? If not, you can do:
aMap = new HashMap() {
{
put("templateContext", this.templateContext);
put("project", this.project);
...
};
On Jan 22, 2009, at 2:51 PM, Nathan Ward wrote:
> Terence,
>
> I have been integrating StringTemplate with a home grown JSP based
> template solution that we have used for several years. It would be
> convenient in this case to use “method chaining” if the
> setAttribute() method returned the instance of the StringTemplate.
>
> e.g.
> Instead of:
> StringTemplate jspTemplate =
> jspTemplateGroup.getInstanceOf("jsp");
> jspTemplate.setAttribute("templateContext",
> this.templateContext);
> jspTemplate.setAttribute("project", this.project);
> jspTemplate.setAttribute("screen", screen);
> String content = jspTemplate.toString();
>
> I could do:
> String content = jspTemplateGroup.getInstanceOf(“jsp”)
> .setAttribute("templateContext", this.templateContext)
> .setAttribute("project", this.project)
> .setAttribute("screen", screen)
> .toString();
>
> This is particularly convenient in cases where I have a block of
> code that needs to use more than one StringTemplate template
> instance. It mainly saves me from having to think up separate names
> for the StringTemplate variables and also seems to be more readable
> than a set of separate statements since there is less non-value
> added text. All it would take is the setAttribute() method to return
> the current StringTemplate object (i.e. “return this;”). For now,
> I’ve written a simple wrapper for StringTemplateGroup and
> StringTemplate classes and had to create a method named
> “newTemplate()” that mimics “getInstanceOf()” and a “setParam()”
> method that just calls setAttribute() but also returns itself.
>
> Nathan
>
> Nathan Ward
> ResQSoft, Inc.
> www.resqsoft.com
>
> _______________________________________________
> stringtemplate-interest mailing list
> stringtemplate-interest at antlr.org
> http://www.antlr.org/mailman/listinfo/stringtemplate-interest
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/stringtemplate-interest/attachments/20090122/f5ba6bcd/attachment.html
More information about the stringtemplate-interest
mailing list