Ok, thanks for all this!

I'm new to Ajax, so I'll have to play around with this so I can better
appreciate the solution proposed below.


Cheers,
Dave



On Fri, 2007-04-20 at 00:26 -0700, Igor Vaynberg wrote:
> i dont really get what scriptaculous, etc has to do with it. and i
> dont get why you would have to redo anything? the solution is
> transparent.
> 
> so if you have existing widgets that are panels, most likely they are,
> thats how you develop widgets in wicket, you just drop them into that
> container page and you are done 
> 
> -igor
> 
> 
> On 4/20/07, David Leangen <[EMAIL PROTECTED]> wrote:
>         
>         Ok, that's interesting.
>         
>         So, you guys are suggesting that a reasonable approach to the
>         problem
>         would be to find a lib that I like (such as scriptaculous),
>         set them up
>         on a widget server, then access them either as standalone
>         javascript 
>         widgets or in wicket via ComponentAsWidgetContainer?
>         
>         The only unfortunate thing about this approach is that we'd
>         have to redo
>         all our existing wicket stuff... But hey, who said life was
>         perfect? ;-)
>         
>         
>         Cheers,
>         Dave
>         
>         
>         
>         On Thu, 2007-04-19 at 23:59 -0700, Igor Vaynberg wrote:
>         > just to add
>         >
>         > an important point is
>         >
>         > this is completely transparent to the widget panel. it is
>         just a 
>         > panel. it doesnt know it is being inlined via javascript
>         into another
>         > page - this is the job of ComponentAsWidgetContainerPage
>         >
>         > one thing to consider is that you would need to rewrite urls
>         so they 
>         > point back to the widget server.
>         >
>         > -igor
>         >
>         >
>         > On 4/19/07, Igor Vaynberg <[EMAIL PROTECTED]> wrote:
>         >         afaict there is no servlet. 
>         >
>         >         what he does is have a bookmarkable page which he
>         mounts. all
>         >         this page does is read some parameter off url and
>         based on
>         >         that parameter add the right panel to itself. it
>         then renders 
>         >         this panel, and wraps the output in document.write()
>         call.
>         >
>         >         well this is almost accurate. i think what he does
>         is create a
>         >         different page for different widget and mount each
>         onto a 
>         >         different url.
>         >
>         >         so
>         >
>         >         MyWidgetAPage extends ComponentAsWidgetContainerPage
>         {
>         >            protected Panel getContent(String id) { return
>         new
>         >         MyWidgetAPanel(id); } 
>         >         }
>         >
>         >         MyWidgetBPage extends ComponentAsWidgetContainerPage
>         {
>         >            protected Panel getContent(String id) { return
>         new
>         >         MyWidgetBPanel(id); }
>         >         } 
>         >         mountPage("/widgeta", MyWidgetAPage.class);
>         >         mountPage("/widgetb", MyWidgetBPage.class);
>         >
>         >         -igor
>         >
>         >
>         >         -igor
>         >
>         > 
>         >
>         >         On 4/19/07, David Leangen <[EMAIL PROTECTED]>
>         wrote:
>         >
>         >                 Hi, Barrett,
>         >
>         >                 Thank you for this. Very interesting. 
>         >
>         >                 So, allow me to rephrase to make sure I'm
>         >                 understanding you on this.
>         >
>         >                 The requirement is:
>         >
>         >                 - Continue to use Wicket as web framework 
>         >                 - Be able to reuse javascript widgets
>         outside of
>         >                 wicket
>         >                 - Reuse same javascript code for both usage
>         patterns
>         >
>         >                 IIUC, what you do below accomplishes that by
>         using all 
>         >                 javascript as
>         >                 <script>ed widgets, even from Wicket. In
>         other words,
>         >                 the javascript is
>         >                 no longer served by Wicket, but by a
>         servlet. 
>         >
>         >
>         >                 Is that correct?
>         >
>         >
>         >                 If so, don't you find that a bit cumbersome
>         to have to
>         >                 change the way
>         >                 you write all your wicket apps? Or has it
>         been 
>         >                 relatively painless for
>         >                 you?
>         >
>         >
>         >                 Cheers,
>         >                 Dave
>         >
>         >
>         >
>         >
>         >                 On Thu, 2007-04-19 at 11:33 -0700, barrett
>         wrote: 
>         >                 > Forgot to mention, to use this just create
>         a page
>         >                 class that extends
>         >                 > ComponentAsWidgetContainerPage and then
>         implement
>         >                 the getComponent(id) 
>         >                 > method. This method should return the
>         >                 component(usually a panel) that you
>         >                 > wish to make into a widget, with the id
>         set to the
>         >                 id passed in to the 
>         >                 > getComponent call.
>         >                 >
>         >                 > You then have a script tag whose src
>         points at this
>         >                 page as seen in the
>         >                 > javadoc comments. 
>         >                 >
>         >                 > -Barrett
>         >                 >
>         >                 >
>         >                 > barrett wrote:
>         >                 > >
>         >                 > > David, 
>         >                 > > We recently had a requirement where we
>         wanted to
>         >                 include a panel from our
>         >                 > > new Wicket app on one of our non-wicket
>         legacy
>         >                 applications. To do this I 
>         >                 > > created a behavior and container page
>         which will
>         >                 spit out any component
>         >                 > > between a javascript document.write
>         method. Then
>         >                 on your non-wicket page 
>         >                 > > you include a script tag whose src
>         attribute is
>         >                 the address of the
>         >                 > > container page. Below are the 3 files
>         that make up
>         >                 the solution. If the 
>         >                 > > files don't show up properly let me know
>         and I can
>         >                 find another way to
>         >                 > > post them.
>         >                 > >
>         >                 > > 
>         >                 > > ComponentAsWidgetContainerPage.java:
>         >                 > >
>         >                 > > package com.company.ui.wicket.page;
>         >                 > >
>         >                 > > import wicket.Component;
>         >                 > >
>         >                 > > import
>         >
>         com.company.ui.wicket.behaviors.JavascriptDocumentWritingBehavior ;
>         >                 > >
>         >                 > > /**
>         >                 > >  * A page which widgetizes a component
>         so it can
>         >                 be used on any page
>         >                 > > outside of
>         >                 > >  * the containing wicket application. 
>         >                 > >  *
>         >                 > >  * @see [EMAIL PROTECTED]
>         JavascriptDocumentWritingBehavior}
>         >                 > >  *
>         >                 > >  */
>         >                 > > public abstract class 
>         >                 ComponentAsWidgetContainerPage extends
>         WebPage
>         >                 > > {
>         >                 > >
>         >                 > >     private static final String
>         WIDGET_ID =
>         >                 "componentAsWidget";
>         >                 > >
>         >                 > >     public
>         ComponentAsWidgetContainerPage()
>         >                 > >     {
>         >                 > >             super(); 
>         >                 > >             Component widget =
>         >                 getComponent(WIDGET_ID);
>         >                 > >             if ( widget.getId() !=
>         WIDGET_ID)
>         >                 > >             { 
>         >                 > >                     throw new
>         >                 IllegalArgumentException("ID for the widget
>         component
>         >                 should
>         >                 > > be set to " 
>         >                 > >                                     +
>         WIDGET_ID);
>         >                 > >             }
>         >                 > >             widget.add(new
>         >                 JavascriptDocumentWritingBehavior()); 
>         >                 > >             add(widget);
>         >                 > >     }
>         >                 > >
>         >                 > >     /**
>         >                 > >      * Implementations should return the
>         component 
>         >                 that is to be widgetized.
>         >                 > >      *
>         >                 > >      * @param id
>         >                 > >      *          The id which should be
>         set on the 
>         >                 returned component.
>         >                 > >      *
>         >                 > >      * @see [EMAIL PROTECTED]
>         >                 JavascriptDocumentWritingBehavior}
>         >                 > >      * @return 
>         >                 > >      */
>         >                 > >     public abstract Component
>         getComponent(String
>         >                 id);
>         >                 > >
>         >                 > > } 
>         >                 > >
>         >                 > > JavascriptDocumentWritingBehavior.java:
>         >                 > >
>         >                 > > package com.company.ui.wicket.behaviors;
>         >                 > >
>         >                 > > import wicket.Component;
>         >                 > > import wicket.IRequestTarget;
>         >                 > > import wicket.MarkupContainer;
>         >                 > > import wicket.RequestCycle ;
>         >                 > > import wicket.Response;
>         >                 > > import wicket.behavior.AbstractBehavior;
>         >                 > > import wicket.markup.ComponentTag;
>         >                 > > import
>         >
>         wicket.markup.html.internal.HtmlHeaderContainer;
>         >                 > > import
>         >
>         wicket.markup.parser.filter.HtmlHeaderSectionHandler ;
>         >                 > > import
>         >
>         wicket.protocol.http.servlet.ServletWebRequest;
>         >                 > > import
>         >
>         wicket.request.target.component.ComponentRequestTarget ;
>         >                 > > import wicket.response.StringResponse ;
>         >                 > >
>         >                 > > import
>         >
>         com.company.ui.wicket.page.ComponentAsWidgetContainerPage ;
>         >                 > >
>         >                 > > /**
>         >                 > >  * This behavior encapsulates any
>         component in a
>         >                 > >  * "document.write
>         ('[renderedComponent]');" 
>         >                 javascript line. The main use
>         >                 > > of
>         >                 > >  * this is to be able to "widgetize" any
>         component
>         >                 to be used on any page 
>         >                 > >  * outside of the containing application
>         with a
>         >                 script tag in the form
>         >                 > > of:<br/><br/>
>         >                 > >  * 
>         >                 > >  * &lt;script
>         >                 > >  *
>         >                 > >
>         >
>         
> src="/mywebapp/app?wicket:bookmarkablePage=:com.company.app.pages.[ComponentContainerPage]"
>  
>         >                 > >  *
>         type="text/javascript"&gt;&lt;/script&gt; <br/>
>         >                 <br/> To be used with
>         >                 > >  * [EMAIL PROTECTED]
>         ComponentAsWidgetContainerPage} 
>         >                 > >  */
>         >                 > > public class
>         JavascriptDocumentWritingBehavior
>         >                 extends AbstractBehavior
>         >                 > > {
>         >                 > >     private static final long
>         serialVersionUID = 
>         >                 1L;
>         >                 > >     private Response renderToResponse;
>         >                 > >     private Response originalResponse;
>         >                 > >
>         >                 > >     @Override 
>         >                 > >     public void bind(Component
>         component)
>         >                 > >     {
>         >                 > >             IRequestTarget target = new
>         >                 ComponentRequestTarget(component); 
>         >                 > >
>         >                 RequestCycle.get().setRequestTarget(target);
>         >                 > >             super.bind(component);
>         >                 > >     }
>         >                 > > 
>         >                 > >     @Override
>         >                 > >     public void onComponentTag(Component
>         >                 component, ComponentTag tag)
>         >                 > >     {
>         >                 > >             renderToResponse = new 
>         >                 StringResponse();
>         >                 > >             originalResponse =
>         >
>         RequestCycle.get().setResponse(renderToResponse);
>         >                 > >
>         >                 > >             renderToResponse.reset();
>         >                 > >
>         >                 > >             renderHeader(component);
>         >                 > >
>         super.onComponentTag(component, tag);
>         >                 > >     } 
>         >                 > >
>         >                 > >     @Override
>         >                 > >     public void onRendered(Component
>         component)
>         >                 > >     {
>         >                 > >             String renderedComponent = 
>         >                 renderToResponse.toString().replaceAll("(
>         >                 > > ?[\\r\\n] ?)+", "")
>         >                 >
>         >                             .replaceAll("'", "\\\ 
>         >                 \'");
>         >                 > >             // Need to make sure any
>         relative
>         >                 server paths get the server prepended
>         >                 > >             String host =
>         ((ServletWebRequest) 
>         >                 > >
>         >
>         component.getRequest()).getHttpServletRequest().getHeader(
>         >                 > >                             "host");
>         >                 > >             renderedComponent = 
>         >                 renderedComponent.replaceAll("href=\"/",
>         >                 > > "href=\"http://"; + host + "/");
>         >                 > >             renderedComponent = 
>         >                 renderedComponent.replaceAll("src=\"/",
>         >                 > > "src=\"http://"; + host + "/");
>         >                 > >
>         >                 > > 
>         >                 originalResponse.write("document.write('");
>         >                 > >
>         >                 originalResponse.write(renderedComponent);
>         >                 > >
>         originalResponse.write("');");
>         >                 > >
>         >
>         RequestCycle.get().setResponse(originalResponse);
>         >                 > >
>         super.onRendered(component); 
>         >                 > >     }
>         >                 > >
>         >                 > >     /**
>         >                 > >      * Renders the header contributed
>         tags to the
>         >                 response. 
>         >                 > >      *
>         >                 > >      * @param response
>         >                 > >      * @param component
>         >                 > >      */
>         >                 > >     private void renderHeader(final
>         Component 
>         >                 component)
>         >                 > >     {
>         >                 > >             final HtmlHeaderContainer
>         header = new
>         >                 > >
>         >
>         HtmlHeaderContainer( HtmlHeaderSectionHandler.HEADER_ID);
>         >                 > >             if
>         >
>         (component.getPage().get(HtmlHeaderSectionHandler.HEADER_ID) !
>         = null)
>         >                 > >             { 
>         >                 > >
>         >                 component.getPage().replace(header);
>         >                 > >             }
>         >                 > >             else
>         >                 > >             { 
>         >                 > >
>         >                 component.getPage().add(header);
>         >                 > >             }
>         >                 > >
>         >                 > >             component.renderHead
>         (header);
>         >                 > >             component.detachBehaviors();
>         >                 > >             if (component instanceof
>         >                 MarkupContainer)
>         >                 > >             { 
>         >                 > >                     ((MarkupContainer)
>         >                 component).visitChildren(new
>         Component.IVisitor ()
>         >                 > >                     {
>         >                 > >                             public
>         Object 
>         >                 component(Component component)
>         >                 > >                             {
>         >                 > >                                     if
>         >                 ( component.isVisible ())
>         >                 > >                                     {
>         >                 > >
>         >                 component.renderHead(header);
>         >                 > >
>         >                 component.detachBehaviors ();
>         >                 > >
>         return
>         >                 CONTINUE_TRAVERSAL;
>         >                 > >                                     } 
>         >                 > >                                     else
>         >                 > >                                     {
>         >                 > >
>         return 
>         >                 CONTINUE_TRAVERSAL_BUT_DONT_GO_DEEPER;
>         >                 > >                                     }
>         >                 > >                             }
>         >                 > >                     }); 
>         >                 > >             }
>         >                 > >     }
>         >                 > > }
>         >                 > >
>         >                 > > ComponentAsWidgetContainerPage.html :
>         >                 > >
>         >                 > > <html
>         >
>         xmlns:wicket="http://wicket.sourceforge.net";>
>         >                 > > <body> 
>         >                 > >     <div
>         wicket:id="componentAsWidget" />
>         >                 > > </body>
>         >                 > > </html>
>         >                 > > 
>         >                 > >
>         >                 > > David Leangen-8 wrote:
>         >                 > >>
>         >                 > >>
>         >                 > >> Hello!
>         >                 > >> 
>         >                 > >> We are currently happily using Wicket
>         to develop
>         >                 our web applications.
>         >                 > >> Wicket rules!
>         >                 > >> 
>         >                 > >>
>         >                 > >> However, now we are required to make
>         "embeddable
>         >                 Ajax components", you
>         >                 > >> know, like Google Maps that anybody can
>         embed in 
>         >                 their own html.
>         >                 > >>
>         >                 > >>
>         >                 > >> Can anybody suggest an approach that
>         would allow
>         >                 us to keep as much 
>         >                 > >> overlap/reusability/cohabitation
>         between our
>         >                 existing Wicket apps and
>         >                 > >> these Ajax components that we now need
>         to make?
>         >                 > >>
>         >                 > >>
>         >                 > >> For instance, would a reasonable
>         approach be to
>         >                 use only Sciptaclous
>         >                 > >> components in Wicket so we can use the
>         exact same 
>         >                 lib for our embeddable
>         >                 > >> components?
>         >                 > >>
>         >                 > >> I guess ideally I'd like to be able to
>         serve the 
>         >                 XHRs from these
>         >                 > >> components directly from Wicket
>         (ultimate
>         >                 reusability/cohabitation), but
>         >                 > >> this doesn't look like it would be an
>         easy 
>         >                 task...
>         >                 > >>
>         >                 > >>
>         >                 > >> Any comments would be most welcome. I'm
>         new to
>         >                 this. :-) 
>         >                 > >>
>         >                 > >>
>         >                 > >> Cheers,
>         >                 > >> Dave
>         >                 > >>
>         >                 > >> 
>         >                 > >>
>         >                 > >>
>         >                 > >>
>         >
>         
> -------------------------------------------------------------------------
>         >                 > >> 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
>         >                 > >>
>         >                 > >> 
>         >                 > >
>         >                 > >
>         >                 >
>         >
>         >
>         >
>         
> -------------------------------------------------------------------------
>         >                 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
>         >
>         >
>         >
>         >
>         
> -------------------------------------------------------------------------
>         > 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
>         
>         
>         
> -------------------------------------------------------------------------
>         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 
> 
> -------------------------------------------------------------------------
> 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


-------------------------------------------------------------------------
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