2007/6/19, Gerolf Seitz <[EMAIL PROTECTED]>:
> take a look at the class
> org.apache.wicket.extensions.yui.calendar.DatePicker (in
> wicket-datetime)
>  there is the following statement in line 183
>
> TextTemplateHeaderContributor.forJavaScript(DatePicker.class,
> "DatePicker.js",
>
> Model.valueOf(variables)).renderHead(response);
>
>  this does the following:
>  it takes the file DatePicker.js, which wicket finds relativ to the location
> of DatePicker.class and substitues every ${VARIABLENAME} text it can find in
> DatePicker.js with the value mapped to the key VARIABLENAME in the Map
> "variables".
>
>  1)
>  so you might want to put the javascript in a file.
>  the line would look like:
>  var myvar = '${myvalue}';
>
>  2)
>  let the component (or behaviour) implement IHeaderContributor and implement
> the renderHead method like the following
>
>  2.a)
>  put the key/value in a map:
>  Map variables = new HashMap();
>  variables.put("myvalue", foo);
>
>  2.b)
>  put this statement after all variables have been put in the map
>  TextTemplateHeaderContributor.forJavaScript(MyClass.class,
> "MyScript.js",
>
> Model.valueOf(variables)).renderHead(response);

Thanks, in fact this is not exactly what I needed but it gave me some
inspiration. My javascript code was in a loop so I wanted to apply a
template to the content of a tag.
Here is what I did, it works fine, I'm not completely happy with my
test on the model, but I cannot find a model that returns the content
of the tag that is in the template

public class TemplateLabel extends Label
{
        private Map variables;

        // some constructors ...


        protected void onComponentTagBody(MarkupStream markupStream,
ComponentTag openTag)
        {
                IModel iModel = getModel();
                String objectAsString;
                if (iModel == null)
                {
                        MarkupElement element = markupStream.get();
                        objectAsString = element.toString();
                }
                else
                {
                        objectAsString = getModelObjectAsString();
                }
                MapVariableInterpolator newContent = new
MapVariableInterpolator(objectAsString, variables);
                replaceComponentTagBody(markupStream, openTag, 
newContent.toString());
        }
}

Matthieu

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Wicket-user mailing list
Wicket-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wicket-user

Reply via email to