1

I'm new to Dojo world. I tried to create a custom dojo widget from scratch.The problem that I'm facing is the widget is not getting parsed. I see that postCreate method of that widget is not getting called. The widget JS file is being downloaded from the server.

Here are the steps what I followed.

  1. Created a JavaScript file CustomWidget.js in test folder.

    dojo.provide('test.CustomWidget'); 
    dojo.require('dijit._Widget');
    
    dojo.declare('test.CustomWidget', dijit._Widget, {
    
        text: "Hello World",
    
        postCreate: function() {
            console.log(this.text+'text');
            this.domNode.innerHTML=this.text;
        }
    });
    
  2. In my jsp file,I imported test.CustomWidget using dojo.require.

    <script type="text/javascript">
    
        dojo.require('test.CustomWidget');
    
        dojo.addOnLoad(function(){ dojo.parser.parse("addFavorites"); });
    </script>
    <div id='addFavorites' dojoType='test.CustomWidget'>
    </div>
    

I can see that CustomWidget.js file is being downloaded, but I don't see the console statement being printed. Can someone plese help me?

1 Answer 1

2

Looks like you aren't instantiating the widget, do you have code like this somewhere?

<div dojoType="mindtree.CustomWidget">...</div>

Otherwise it's like declaring a class but never calling new.

Not the answer you're looking for? Browse other questions tagged or ask your own question.