Done. Vincent, could you please check if this is the way to go?

Thanks,
Bart.

> -----Oorspronkelijk bericht-----
> Van: Bart Molenkamp
> Verzonden: dinsdag 17 april 2007 12:15
> Aan: wicket-dev@incubator.apache.org
> Onderwerp: RE: [Wicket-autocvs] SF.net SVN: wicket-stuff: [1935] 
> branches/wicket-1.3/wicket-
> contrib-dojo/ src/main/java/org/wicketstuff/dojo
> 
> Ok, I can just simply add my configuration parameters using 
> ComponentTag.put(). Also reloading
> works (probably didn't work in the first case due to the bug in RichText.js).
> 
> I will remove the AbstractDojoWidgetBehavior class.
> 
> Thanks,
> Bart.
> 
> > -----Oorspronkelijk bericht-----
> > Van: Vincent Demay [mailto:[EMAIL PROTECTED]
> > Verzonden: dinsdag 17 april 2007 11:35
> > Aan: wicket-dev@incubator.apache.org
> > Onderwerp: Re: [Wicket-autocvs] SF.net SVN: wicket-stuff: [1935] 
> > branches/wicket-1.3/wicket-
> > contrib-dojo/ src/main/java/org/wicketstuff/dojo
> >
> > Bart Molenkamp a écrit :
> > > Hi Vincent,
> > >
> > > I wasn't aware of the TargetRefreshManager class. I found out that the 
> > > DojoRichTextBehavior
> > didn't work when the component was added to the page after an Ajax update 
> > (in my case I replaced
> > some panel with another panel that contained the rich text editor). The 
> > solution would be call to
> > dojo.hostenv.makeWidgets(); (I see this is done by the 
> > TargetRefreshManager).
> > >
> > More than creating widget, TargetRefresherManager ensure also that the
> > widget will be created before all appendJavascript interpretation which
> > is quite usefull when we want add some javascript dealing with the
> > widget created by an ajax response
> > > But I choose to create the widgets by hand, because then I can add 
> > > parameters to it. If you
> look
> > at the DojoRichTextBehavior you can see that it's possible to set some 
> > properties, like height,
> and
> > the toolbar template. These properties are passed to the createWidget call 
> > in JavaScript. Is it
> > possible to add these parameters to a widget if you use the 
> > dojoType="Editor2" tag to create
> > widgets?
> > >
> > Probably yes, Dojo actually parse all attributes in a "dojoType tags" to
> > use each one as a setter of the class attribute (if exists) during
> > widget creation. So It should work expect if there is a bug in dojo ;)
> > > I think you're right that it might become a problem when the same widget 
> > > is created more than
> > once. I didn't thought about it.
> > >
> > > We should indeed use one (and only one) way to create/maintain widgets. 
> > > TargetRefreshManager is
> > OK by me (thinking of it, I guess that it failed to create the widget due 
> > to the bug in
> > RichText.js) if I can pass parameters on creation (I need the height and 
> > the custom toolbar for
> the
> > Editor2 widget).
> > >
> > > Thanks for looking at this,
> > >
> > no pb !
> > > Bart.
> > >
> > --
> > Vincent
> > >
> > >> -----Oorspronkelijk bericht-----
> > >> Van: Vincent Demay [mailto:[EMAIL PROTECTED]
> > >> Verzonden: dinsdag 17 april 2007 10:28
> > >> Aan: wicket-dev@incubator.apache.org
> > >> Onderwerp: Re: [Wicket-autocvs] SF.net SVN: wicket-stuff: [1935] 
> > >> branches/wicket-1.3/wicket-
> > >> contrib-dojo/ src/main/java/org/wicketstuff/dojo
> > >>
> > >> Hi Bart
> > >>
> > >> I see you added a behavior to deal with Dojo widget creating it using
> > >> dojo.widget.createWidget. I don't understand what is the aim of this
> > >> abstract behavior because AbstractRequireDojoBehavior can already create
> > >> a dojo widget via an AjaxRequestTarget (see TargetRefresherManager which
> > >> is a listener on ajaxRequest Target) but I maybe miss something.
> > >>
> > >> The way we choose to create dojo widget in Wicket is adding parameters
> > >> on the component tag. AbstractDojoWidgetBehavior deals with
> > >> dojo.widget.createWidget and extending AbstractRequireDojoBehavior the
> > >> widget created with this behavior could be added twice in the 
> > >> dojoManager.
> > >> On the other hand it will be great to keep a unique way to create widget
> > >> in WCD. I'm not saying the way we use now is the better but it can be
> > >> better if we use always the same (adding attribute on component tag OR
> > >> using dojo.widget.createWidget).
> > >>
> > >> Just say me if I simply not well understand the goal of this class ;) .
> > >> Otherwise we need to choose a *unique* way to render dojo widget and
> > >> apply it on all widgets.
> > >>
> > >> --
> > >> Vincent
> > >>
> > >> [EMAIL PROTECTED] a écrit :
> > >>
> > >>> Revision: 1935
> > >>>           http://svn.sourceforge.net/wicket-stuff/?rev=1935&view=rev
> > >>> Author:   molenkampb
> > >>> Date:     2007-04-16 23:56:42 -0700 (Mon, 16 Apr 2007)
> > >>>
> > >>> Log Message:
> > >>> -----------
> > >>> * Introduced AbstractDojoWidgetBehavior that can create widgets when 
> > >>> first rendered and after
> > >>>
> > >> rerendering (by ajax)
> > >>
> > >>> branches/wicket-1.3/wicket-contrib-
> > >>>
> > >> dojo/src/main/java/org/wicketstuff/dojo/AbstractDojoWidgetBehavior.java
> > >>
> > >>> ===================================================================
> > >>> --- branches/wicket-1.3/wicket-contrib-
> > >>>
> > >> dojo/src/main/java/org/wicketstuff/dojo/AbstractDojoWidgetBehavior.java
> > >> (rev 0)
> > >>
> > >>> +++ branches/wicket-1.3/wicket-contrib-
> > >>>
> > >> dojo/src/main/java/org/wicketstuff/dojo/AbstractDojoWidgetBehavior.java  
> > >> 2007-04-17 06:56:42
> > >> UTC (rev 1935)
> > >>
> > >>> @@ -0,0 +1,169 @@
> > >>> +/**
> > >>> + *
> > >>> + */
> > >>> +package org.wicketstuff.dojo;
> > >>> +
> > >>> +import java.util.HashMap;
> > >>> +import java.util.Iterator;
> > >>> +import java.util.Map;
> > >>> +
> > >>> +import org.apache.wicket.IRequestTarget;
> > >>> +import org.apache.wicket.RequestCycle;
> > >>> +import org.apache.wicket.ResourceReference;
> > >>> +import org.apache.wicket.ajax.AjaxRequestTarget;
> > >>> +import org.apache.wicket.markup.html.IHeaderResponse;
> > >>> +
> > >>> +/**
> > >>> + * Abstract behavior implementation that deals with dojo widgets.
> > >>> + *
> > >>> + * @author B. Molenkamp
> > >>> + * @version SVN: $Id$
> > >>> + */
> > >>> +public abstract class AbstractDojoWidgetBehavior extends 
> > >>> AbstractRequireDojoBehavior {
> > >>> +
> > >>> +       /* (non-Javadoc)
> > >>> +        * @see
> > >>>
> > >>
> >
> org.wicketstuff.dojo.AbstractRequireDojoBehavior#renderHead(org.apache.wicket.markup.html.IHeaderRe
> > >> sponse)
> > >>
> > >>> +        */
> > >>> +       @Override
> > >>> +       public void renderHead(IHeaderResponse response) {
> > >>> +               super.renderHead(response);
> > >>> +
> > >>> +               String markupId = getComponent().getMarkupId();
> > >>> +               WidgetProperties props = getWidgetProperties();
> > >>> +               String arrayString = props.convertToJavaScriptArray();
> > >>> +
> > >>> +               IRequestTarget target = 
> > >>> RequestCycle.get().getRequestTarget();
> > >>> +               if(!(target instanceof AjaxRequestTarget)){
> > >>> +                       
> > >>> response.renderJavascript("dojo.event.connect(dojo, \"loaded\", 
> > >>> function()
> {" +
> > >>> +                                       "dojo.widget.createWidget('" + 
> > >>> getWidgetType() + "', " +
> arrayString
> > >>>
> > >> + ", dojo.byId('" + markupId + "'))" +
> > >>
> > >>> +                                       "});\n",
> > >>> +                                       markupId + "onLoad");
> > >>> +               }
> > >>> +       }
> > >>> +
> > >>> +       /* (non-Javadoc)
> > >>> +        * @see
> > >>>
> > >>
> >
> org.wicketstuff.dojo.AbstractRequireDojoBehavior#onComponentReRendered(org.apache.wicket.ajax.AjaxR
> > >> equestTarget)
> > >>
> > >>> +        */
> > >>> +       @Override
> > >>> +       public void onComponentReRendered(AjaxRequestTarget ajaxTarget) 
> > >>> {
> > >>> +               super.onComponentReRendered(ajaxTarget);
> > >>> +
> > >>> +               String markupId = getComponent().getMarkupId();
> > >>> +
> > >>> +
> > >>> +               //dojo.widget.createWidget("Editor2", {}, 
> > >>> dojo.byId("editorContent"));
> > >>> +               WidgetProperties props = getWidgetProperties();
> > >>> +               String arrayString = props.convertToJavaScriptArray();
> > >>> +               
> > >>> ajaxTarget.appendJavascript("dojo.widget.createWidget('" + 
> > >>> getWidgetType() + "',
> " +
> > >>>
> > >> arrayString + ", dojo.byId('" + markupId + "'));\n");
> > >>
> > >>> +       }
> > >>> +
> > >>> +       /**
> > >>> +        * Returns the widget type.
> > >>> +        * @return
> > >>> +        */
> > >>> +       protected abstract String getWidgetType();
> > >>> +
> > >>> +       /**
> > >>> +        * Return the properties string that is used when creating the 
> > >>> widget.
> > >>> +        * @return
> > >>> +        */
> > >>> +       protected WidgetProperties getWidgetProperties() {
> > >>> +               // by default return an empty map.
> > >>> +               return new WidgetProperties();
> > >>> +       }
> > >>> +
> > >>> +       /**
> > >>> +        * A class to hold widget properties.
> > >>> +        */
> > >>> +       public class WidgetProperties {
> > >>> +
> > >>> +               private Map<String, String> properties;
> > >>> +
> > >>> +               public WidgetProperties() {
> > >>> +                       this.properties = new HashMap<String, String>();
> > >>> +               }
> > >>> +
> > >>> +               /**
> > >>> +                * Adds a boolean property.
> > >>> +                * @param name
> > >>> +                * @param value
> > >>> +                */
> > >>> +               public void addProperty(String name, boolean value) {
> > >>> +                       this.properties.put(name, 
> > >>> Boolean.toString(value));
> > >>> +               }
> > >>> +
> > >>> +               /**
> > >>> +                * Adds an integer property
> > >>> +                * @param name
> > >>> +                * @param value
> > >>> +                */
> > >>> +               public void addProperty(String name, int value) {
> > >>> +                       this.properties.put(name, 
> > >>> Integer.toString(value));
> > >>> +               }
> > >>> +
> > >>> +               /**
> > >>> +                * Adds a string property (encloses the string in 
> > >>> qoutes).
> > >>> +                * @param name
> > >>> +                * @param value
> > >>> +                */
> > >>> +               public void addProperty(String name, String value) {
> > >>> +                       value = value.replace("\"", "\\\"");    // 
> > >>> escape any double qoute.
> > >>> +                       this.properties.put(name, "\"" + value + "\"");
> > >>> +               }
> > >>> +
> > >>> +               /**
> > >>> +                * Adds a resource reference property. The resource is 
> > >>> looked up using
> > >>> +                * Dojo's dojo.uri.dojoUri() function. Relative paths 
> > >>> are handled.
> > >>> +                *
> > >>> +                * @param name
> > >>> +                * @param reference
> > >>> +                */
> > >>> +               public void addProperty(String name, ResourceReference 
> > >>> reference) {
> > >>> +                       RequestCycle cycle = RequestCycle.get();
> > >>> +
> > >>> +                       ResourceReference dojo =
> > >>>
> > >> AbstractDojoWidgetBehavior.this.getDojoResourceReference();
> > >>
> > >>> +                       String dojoUrl = cycle.urlFor(dojo).toString();
> > >>> +                       dojoUrl = dojoUrl.substring(0, 
> > >>> dojoUrl.lastIndexOf("/") + 1);
> > >>> +
> > >>> +                       CharSequence url = cycle.urlFor(reference);
> > >>> +                       String relativeUrl = 
> > >>> dojoUrl.replaceAll(".[^/]*/", "../") + url;
> > >>> +                       this.properties.put(name, "dojo.uri.dojoUri(\"" 
> > >>> + relativeUrl + "\")");
> > >>> +               }
> > >>> +
> > >>> +               /**
> > >>> +                * Adds a raw property. The object's toString() is 
> > >>> called and added
> > >>> +                * without any further conversion.
> > >>> +                * @param name
> > >>> +                * @param value
> > >>> +                */
> > >>> +               public void addRawProperty(String name, Object value) {
> > >>> +                       this.properties.put(name, value.toString());
> > >>> +               }
> > >>> +
> > >>> +               /**
> > >>> +                * Convert the properties to a valid javascript array.
> > >>> +                * @return
> > >>> +                */
> > >>> +               public String convertToJavaScriptArray() {
> > >>> +                       // convert the properties to string
> > >>> +                       StringBuffer propertyString = new 
> > >>> StringBuffer("{");
> > >>> +                       Iterator<String> i = 
> > >>> this.properties.keySet().iterator();
> > >>> +                       while (i.hasNext()) {
> > >>> +                               String propertyName = i.next();
> > >>> +                               Object property = 
> > >>> this.properties.get(propertyName);
> > >>> +
> > >>> +                               propertyString.append(propertyName + ": 
> > >>> " + property);
> > >>> +
> > >>> +                               // if there are more properties, 
> > >>> separate them by a comma
> > >>> +                               if (i.hasNext()) {
> > >>> +                                       propertyString.append(", ");
> > >>> +                               }
> > >>> +                       }
> > >>> +
> > >>> +                       // close the property string.
> > >>> +                       propertyString.append("}");
> > >>> +
> > >>> +                       return propertyString.toString();
> > >>> +               }
> > >>> +       }
> > >>> +}
> > >>>
> > >>>
> > >>>
> > >>>
> > >>>
> > >>> This was sent by the SourceForge.net collaborative development 
> > >>> platform, the world's largest
> > Open
> > >>>
> > >> Source development site.
> > >>
> > >>> -------------------------------------------------------------------------
> > >>> 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-autocvs mailing list
> > >>> [EMAIL PROTECTED]
> > >>> https://lists.sourceforge.net/lists/listinfo/wicket-autocvs
> > >>>
> > >>>
> > >
> > >
> > >
> 


Reply via email to