Michael,
I use
$page.setScript("JavaScript",
"text/javascript",$content.getURI("resources/global.js"))
and this class:
package de.geoconnect.audiotex.turbineext;
import org.apache.turbine.util.template.TemplatePageAttributes;
import org.apache.turbine.util.RunData;
import org.apache.ecs.html.Script;
import org.apache.ecs.html.Link;
import org.apache.ecs.html.Style;
public class ExtTemplatePageAttributes extends TemplatePageAttributes {
private RunData data = null;
/**
* Default constructor. The init method must be called before use
*/
public ExtTemplatePageAttributes()
{
super();
}
/**
* Construct a new instance with the given RunData object.
*
* @param data a RunData instance
*/
public ExtTemplatePageAttributes(RunData data)
{
super(data);
this.data = data;
}
/**
* Initialise this instance with the given RunData object.
* (ApplicationTool method)
*
* @param data Assumed to be a RunData instance
*/
public void init(Object data)
{
super.init(data);
// we blithely cast to RunData as the runtime error thrown
// if data is null or not RunData is appropriate.
this.data = (RunData)data;
}
/**
* Refresh method - does nothing
*/
public void refresh()
{
// empty
}
/**
* Adds a LINK to a javascript file to the HEAD of the page.
*
* @param url A String.
* @return A TemplatePageAttributesEx (self).
*/
public TemplatePageAttributes setScript(String url)
{
data.getPage().getHead().addElement(new Script().setSrc(url)
.setType("text/javascript").setLanguage("JavaScript"));
return this;
}
public TemplatePageAttributes setScript(String lang, String type, String
url)
{
data.getPage().getHead().addElement(new Script()
.setLanguage(lang).setType(type).setSrc(url));
return this;
}
/**
* Adds a LINK to a CSS stylesheet to the HEAD of the page, allowing the
* media type to be specified.
*
* @param url The value for the <code>href</code> attribute.
* @param media The value for the <code>media</code> attribute.
* @return a <code>TemplatePageAttributes</code> (self).
*/
public TemplatePageAttributes setStyleSheet(String url, String media)
{
data.getPage().getHead().addElement(new Link().setRel("stylesheet")
.setType("text/css").setMedia(media).setHref(url));
return this;
}
// /**
// * Adds a STYLE element to the HEAD of the page.
// *
// * @param styleText The content of the style element.
// * @param media The value for the <code>media</code> attribute.
// * @return a <code>TemplatePageAttributes</code> (self).
// */
// public TemplatePageAttributes setStyleElement(String styleText, String
media)
// {
// Style style = new Style("text/css", styleText);
// style.setMedia(media);
// data.getPage().getHead().addElement(style);
// return this;
// }
/**
* Adds a STYLE element to the HEAD of the page with the provided
content.
*
* @param styleText The contents of the <code>style</code> tag.
* @return a <code>TemplatePageAttributes</code> (self).
*/
public TemplatePageAttributes setStyle(String styleText)
{
data.getPage().getHead().addElement(new Style("text/css",
styleText));
return this;
}
}
You have to register the class in your TR.props.
Marc
> -----Urspr�ngliche Nachricht-----
> Von: michael shek sia lim [mailto:[EMAIL PROTECTED]]
> Gesendet: Samstag, 14. Dezember 2002 01:20
> An: [EMAIL PROTECTED]
> Betreff: Re: AW: adding Javascript
>
>
> The discussion in the link below does not seem to be conclusive. Is there
> any other solution to Javascript used in conjunction with Velocity?
>
> cheers
> michael
>
>
>
>
>
> > Hi,
> > it is described in the list archive.
> > Start here for example:
> >
> http://www.mail-archive.com/[email protected]/msg07518.html
> >
> > Marc
> >
> >
> >> -----Urspr�ngliche Nachricht-----
> >> Von: michael shek sia lim [mailto:[EMAIL PROTECTED]]
> >> Gesendet: Freitag, 13. Dezember 2002 14:30
> >> An: [EMAIL PROTECTED]
> >> Betreff: adding Javascript
> >>
> >>
> >> Dear All,
> >>
> >> If a javascript is to be added to my Turbine application, where can I
> >> find the <head> </head> pair in the setup so that I can achieve what I
> >> intend to do?
> >>
> >> cheers
> >> michael
> >>
> >>
> >>
> >>
> >> --
> >> To unsubscribe, e-mail:
> >> <mailto:[EMAIL PROTECTED]>
> >> For additional commands, e-mail:
> >> <mailto:[EMAIL PROTECTED]>
> >>
> >
> >
> > --
> > To unsubscribe, e-mail:
> > <mailto:[EMAIL PROTECTED]> For additional
> > commands, e-mail: <mailto:[EMAIL PROTECTED]>
>
>
>
>
> --
> To unsubscribe, e-mail:
<mailto:[EMAIL PROTECTED]>
For additional commands, e-mail:
<mailto:[EMAIL PROTECTED]>
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>