views:

2248

answers:

2

I am attempting to create a struts2 component using freemarker. I created a ftl file with code like this:

<script type="text/javascript" src="${parameters.library?default('')}"></script>

Which is expecting a parameter named library to be passed to the component. If the parameter is absent then it defaults to a blank string.

On my JSP page I am referring to the component like this:

<s:component template="mytemplate.ftl">
    <s:param name="library" value="/scripts/mylibrary.js"/>
</s:component>

Unfortunately, the value for the library parameter is not being set. It is always a blank string.

I am using the advice from this tutorial and it seems as if the s:param tag should pass the parameter into the template and make it available. What am I missing here?

Does anyone have some experience building these components that could shed some light?

Thanks.

A: 

I eventually ran across some syntax in the docs that works. I have to refer to the parameter like this:

<script type="text/javascript" src="${parameters.get('library')?default('')}">
</script>
Vincent Ramdhanie
+3  A: 

send the param with single quotes

<s:component template="mytemplate.ftl">
    <s:param name="library" value="'/scripts/mylibrary.js'"/>
</s:component>
Kirti Teja
Thanks. I will try this.
Vincent Ramdhanie
Excellent, this does work.
Vincent Ramdhanie