[stringtemplate-interest] Conditionally included subtemplates?

erwin.mueller at deventm.org erwin.mueller at deventm.org
Sat Feb 5 22:26:02 PST 2011


Hello,

    I'm a new user of StringTemplate and so far I have manage my simple
templates w/o any problems. But I wonder in a template like [1] I understood the
documentation that the subtemplate will be included if the attribute ``address''
exists. Why do I get then NoSuchFieldException [2]? My classes are like in [3]
where ``httpd'' is an object of classes implementing the ``HttpdDirective''
interface.

    I understood the documentation ``IF actions test the presence or absence of
an attribute unless the object is a Boolean/bool, true".
For example,"$if(!member)$...$endif$".'' Presence or absence is for me whether
the object have the attribute or not. What is the documentation understands as
``presence'' or ``absence''?

Kind regards, Erwin.

[1]
domains(httpd) ::= <<
\<!-- domains --\>
<httpd.directives:{<if(it.address)>{NameVirtualHost <it.address><\n>}<endif>}>
>>

[2]
Class
com.globalscalingsoftware.sscontrol.cli.internal.application.services.httpd.
directives.SetupJkWorkerDirective$$EnhancerByGuice$$f9c51395 has no such
attribute: address in template context [httpd_default domains anonymous]
java.lang.NoSuchFieldException: address

[3]
public interface HttpdDirective {

    String getTemplateName();

    HttpdDirective setProperty(String name, Object value);

}

public class DomainDirective implements HttpdDirective {

    public String getAddress() {
        return address;
    }

}

public class SetupJkWorkerDirective implements HttpdDirective {
    // no getAddress() method
}
-- 
Erwin Mueller, erwin.mueller at deventm.org
http://www.global-scaling-institute.de/
http://www.deventm.org


More information about the stringtemplate-interest mailing list