as described in dojo book - widget-lifecycle, a lifecycle-method called "startup" should be called after all the widgets child-widgets are created
well, i tested so much variants... there never was any startup method called
what do i want to do with startup?
i want to get all important nodes from the widget (which are created by a template), so i can set their values dynamically later on with remotely fetched values (e.g. by a datastore)
i would be happy for either a hint about how to correctly use "startup" or how else i can access the widgets domnodes (by being sure that they already exist... remember i have child-widgets in my template)
and why is postCreate not useful?
well... when i do
this._nodes.header = dojo.query(".Header")[0];
in postCreate, "this._nodes.header" is empty, so a console.dir(this._nodes.header) just throws nothing
here is the corresponding html from my template
<h2 class="Header">${headerLabel}</h2>
and before some ppl ask... the class "Header" is only given once in the whole DOM tree

When a widget is created
When a widget is created declaratively, its startup() method is called automatically. When it is created programmatically, it is the responsibility of the developer to call startup after any children have been added so that you can avoid resizing children more than is necessary. For example when creating a tab container programmatically, you would do:
var tabContainer = new dijit.layout.TabContainer({props: asdf},creationNode);
tabContainer.addChild(new dijit.layout.ContentPane({title: "one", href="foo.html"});
tabContainer.addChild(new dijit.layout.ContentPane({title: "two", href="foobar.html"});
tabContainer.addChild(new dijit.layout.ContentPane({title: "three", href="bar.html"});
tabContainer.startup();
hm, i dont understand the
hm, i dont understand
the layout widget, which creates the corresponding content widget doesnt know which widgets it creates and besides... it must not know it
my widgets are all blackboxed and they contain their logic inside, so all widgets can create each other without caring about what others do
1: LayoutWidget (it justs takes care where widgets are created, not "which" widgets)
2: ContentWidgets (they contain their business logic and they act fully independent, like in a blackbox... though they also can be layout widgets)
i would need sth like:
var tabContainer = new dijit.layout.TabContainer({props: asdf},creationNode);
// i dont know which widgets tabContainer needs... its handling that itself
// so it should startup(); itself
but when i try to handle the startup myself inside the widget... as described above... postCreate() isnt the right place to do so (though the content widget is templated and as i understood postCreate(), it should be invoked after the template has been substituted and attached to the domNode)
at which lifecycle point can i access the domNodes created by the template?
is there any clean solution to manage my problem?
I'm not sure i'm following
I'm not sure i'm following your issue, but you shouldnt' be doing things like calling starup() inside of your widget manually, as that defeats the purpose of the startup() call. Note that the startup() call doesn't make a widget need to know anything more than before, its there to make sure the browser doesn't need to do more work than it has to. When you create a widget declaratively, the containing widget's startup() method is called after all its children have already been instantiated. When you create a container widget programatically, you have the opportunity to addChild() before the startup is called so that if you add 20 children, the resizing routines that the container widget has doesn't need to get called 20 times. So basically you add whatever widgets you want to start with and then call startup(). If you don't have any widgets to start with, you can just call startup() after creating the widget and then do all the addChild()s you want.
I know this probably doesn't answer you exact question, but I'm not quite understanding what your question is yet so hopefully this allows you to think about how it is intended to be used.
during debugging i found sth
during debugging i found sth very strange about console.log()
dojo-core-support/can-console-log-be-trusted
it also shows my problem with postCreate()
what i basically want
what i basically want is...:
1.: create a widget which has a template
2.: make an ajax request to get the data for the template
3.: fill the data in the template when the ajax request is finished
so... i need:
1.: a template.. ok fine, i have one which is working
2.: a store for an ajax request... fine thats whats working too
3.: any possibility to fill in the data into the widgets HTML... sadly, we cant update the template, so i have to get the domNodes of the widget and fill them myself... thats what i have only as workaround (inside the onFetchDataSuccess Handler)
=> my widget:
constructor: initializes the widget
postCreate: start the ajax request
onAjaxRequestSuccess: get the domNodes and fill them
but what i would like to have is not just a workaround by getting the nodes inside the data request success handler.. i want to get them before i do the ajax request... i want clean and good structured code
so i thought: "hey okay, lets try to get them in postCreate"... but postCreate didnt work, cause there were no nodes to get... then i thought: "hm, if postCreate is to early, what about startup?" then i recognized that startup was never called and i wrote that thread here
but what i need is not to get startup called, i need a lifecycle state, where i know that the template is created and attached to the domNode, so i can get the nodes myself and fill them with data... i dont care if thats postCreate, startup or whatever else
well... dont mind, i have it working (though being dirty), i just expected that startup is that what i need to make it pretty
the template nodes and
the template nodes and attachEvents should be injected and available by postCreate iirc. though using AJAX from within your widget may cause a race condition?
>> he template nodes and
>> he template nodes and attachEvents should be injected and available by postCreate iirc.
no they are not.. exactly thats my problem
a dojo.query in postCreate doesnt give me the domNodes created by the template.. u can take a look at the link i posted above.. there u gonna see my debug outputs
>> though using AJAX from within your widget may cause a race condition?
there is no race condition... the onSuccessHandler is furthermore the only place where dojo.query gives me the nodes i need
yeeehaaaa!!!
finally, i got the solution.. not by startup, but with dojoAttachPoint
there is no need to get the domNodes by dojo.query at postCreate of startup or at any eventHandler... a simple dojoAttachPoint inside the templates is all i need
here how i handle the stuff:
template
dojoType="dijit.form.Form"
dojoAttachEvent="onExecute:formSubmitHandler";
dojoAttachPoint="formPoint"
action=""
>
<input
dojoType="dijit.form.TextBox"
dojoAttachPoint="formNamePoint"
type="text"
name="formName"
value=""
/>
<button ... >...</button>
</form>
inside my custom widget
{
console.dir(this.formPoint);
console.debug(this.formNamePoint.getValue());
}
sometimes... dojo is really magic!!!