define page root() {
    init{
    log("Init called");
    }

    actionLink("Do something", doSomethingAction())[ajax]

    action doSomethingAction(){

    }
}

When clicking the “Do something” link, init gets called twice.

The log, after link click, is:

Init called
Init called

Init shouldn’t be called at all for ajax actions

Submitted by Victor Hurdugaci on 28 March 2010 at 17:45

On 29 March 2010 at 08:04 Danny Groenewegen commented:

The difference between normal and ajax actions is that ajax actions are called from Javascript while normal actions rely on the browser form submit. This allows ajax actions to do e.g. replacements in the page, because the Javascript response handler knows about these special operations. Note that ajax templates, or anything rendered as part of a replace will automatically get ajax submits, also the actionlink is always an ajax submit (so in your example the [ajax] modifier is not necessary).

Other than how they are called, they are like normal actions and can refer to page variables. So you could have:

var i := 0
init{ i:=1; }
actionLink("Do something", doSomethingAction())
action doSomethingAction(){
  log(i); // 1
}

Inits are invoked for normal and ajax actions. If there is a data validation error, then all changes are thrown away, and the templates are reinitialized to get the original values (2nd init). Unfortunately, there are still some problems with data validation in combination with ajax, sometimes the messages are not shown. If you have a small example where this happens please submit it to yellowgrass. It can help to view the response of the server in Firebug, to see what happened.

Related discussion about different type of ajax action call:
https://yellowgrass.org/issue/WebDSL/75

Example of ‘manual’ ajax data validation:
http://webdsl.org/singlepage/ajaxexamplevalidation

Log in to post comments