Class ExtWidget

  • All Implemented Interfaces:
    Serializable, org.apache.wicket.IComponentAwareEventSink, org.apache.wicket.markup.html.IComponentAwareHeaderContributor, org.apache.wicket.util.io.IClusterable, IPlugin, org.wicketstuff.js.ext.IExtObservable

    public abstract class ExtWidget
    extends org.wicketstuff.js.ext.ExtObservable
    implements IPlugin

    An Ext widget an Ext component that is not instantiated when rendered. Instead, we render the configuration properties that should be passed to their Javascript constructor. These configuration properties are automatically registered in the global Hippo.ExtWidgets registry. The registration key is the Ext xtype. It is then possible to instantiate a widget multiple times in Javascript by retrieving its configuration from the registry and passing it to Ext. Since ExtWidgets are also CMS plugins, they can be easily bootstrapped via plugin configuration node in the repository.

    Here's a simple example of an Ext widget.

    Repository configuration:

    
     <?xml version="1.0" encoding="UTF-8"?>
     <sv:node sv:name="my-ext-widget" xmlns:sv="http://www.jcp.org/jcr/sv/1.0">
       <sv:property sv:name="jcr:primaryType" sv:type="Name">
         <sv:value>frontend:plugin</sv:value>
       </sv:property>
       <sv:property sv:name="plugin.class" sv:type="String">
         <sv:value>com.example.MyExtWidget</sv:value>
       </sv:property>
     </sv:node>
     

    MyExtWidget.java:

    
    @ExtClass("MyExtWidget")
     public class MyExtWidget extends ExtWidget {
    
         public MyExtWidget(IPluginContext context, IPluginConfig config) {
             super("myextwidget", context);
             add(JavascriptPackageResource.getHeaderContribution(MyExtWidget.class, "MyExtWidget.js"));
         }
    
        @Override
         protected void onRenderProperties(final JSONObject properties) throws JSONException {
             super.onRenderProperties(properties);
             properties.put("exampleProperty", "somevalue");
         }
     }
     

    MyExtWidget.js:

    
     MyExtWidget = Ext.extend(Ext.Panel, {
    
         constructor: function(config) {
             alert(config.exampleProperty);
             MyExtWidget.superclass.constructor.call(this, config);
         }
    
     }
     

    The xtype 'myextwidget' is passed to the Java superclass, and automatically registered with the Ext component manager.

    An Ext widget can also be registered from Javascript alone: MyExtWidget.js:

    
     MyExtWidget = ...
     Hippo.ExtWidgets.register('myextwidget', MyExtWidget);
     

    Using the widget, like adding it to a panel, could be then done with:

    
     var somePanel = new Ext.Panel({
         items: [ Hippo.ExtWidgets.getConfig('myextwidget') ]
     });
     
    Instantiating a widget can also be done by the registry itself:
    
     var myWidget = Hippo.ExtWidgets.create('myextwidget');
     
    It is also possible to provide additional configuration when instantiating a widget:
    
     var myWidget = Hippo.ExtWidgets.create('myextwidget', {
         someproperty: 'foo'
     });
     

    See Also:
    Serialized Form
    • Field Summary

    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void buildInstantiationJs​(StringBuilder js, String extClass, org.json.JSONObject properties)  
      String getXType()  
      void start()
      This method can be implemented by plugins to delay part of the initialization until subclasses have finished their construction.
      void stop()
      Release references to external resources.
      • Methods inherited from class org.wicketstuff.js.ext.ExtObservable

        add, add, addEventListener, bind, getExtObservables, getJsObjectId, getProperties, isExtRoot, newExtEventBehavior, onRenderExtHead, onRenderProperties, postRenderExtHead, preRenderExtHead, renderHead
      • Methods inherited from class org.apache.wicket.behavior.Behavior

        afterRender, beforeRender, canCallListener, detach, getStatelessHint, isEnabled, isTemporary, onAttribute, onComponentTag, onConfigure, onEvent, onException, onRemove, onTag, unbind
    • Method Detail

      • getXType

        public String getXType()
      • start

        public void start()
        Description copied from interface: IPlugin
        This method can be implemented by plugins to delay part of the initialization until subclasses have finished their construction.
        Specified by:
        start in interface IPlugin
      • stop

        public void stop()
        Description copied from interface: IPlugin
        Release references to external resources. It is not necessary to unregister services or trackers; this is handled by the framework.
        Specified by:
        stop in interface IPlugin
      • buildInstantiationJs

        public void buildInstantiationJs​(StringBuilder js,
                                         String extClass,
                                         org.json.JSONObject properties)
        Overrides:
        buildInstantiationJs in class org.wicketstuff.js.ext.ExtObservable