I came across something similar when evaluating Click and here's the
solution I came up with.  I don't know if it precisely answers your
question, but maybe it will help.   The sample code has jquery
dependency, but you could recode without.

The overview: A custom ActionResult child is used to trigger a DOM
event of any given type.   One or more target elements are bound this
event type by a custom Behavior, which causes custom js to be executed
whenever the event is "heard".  So in your case your initial Ajax
request would result in a simple event trigger, and all the other
panels and forms would listen for it.  When they heard it, they would
each send out their own ajax requests to retrieve their new content.

Here's my addEvent method on  ActionResultWithDomEvent which extends
ActionResult:
    public void addEvent(String name) {
        if (this.getContent() != null)
            this.setContent(this.getContent() +
"jQuery('body').trigger('" + name + "');");
        else
            this.setContent("jQuery('body').trigger('" + name + "');");
    }
Note the content type is set to javascript for by constructors.

And here's a sample Behavior class that causes some Jquery effect when
the event is heard.  There really should be a base class
"JavascriptOnEventBehavior" and then you could make your own
"AjaxCallOnEventBehavior" or something that inherits... Anyway:

public class JqueryEffectOnEventBehavior implements Behavior {
   ... effect settings and so on....
     protected String effect_type = "default_effect_evt";

     public void preRenderHeadElements(Control source) {
        String id = source.getId();
        String fxOptionString = JSONValue.toJSONString(this.options);
        String jsText = "$('body').bind('" + this.event_type + "',
                                          function(event){" + "$('#" +
id + "').effect('" + this.effect_type + "',"

                     + fxOptionString + "," + this.speed + ");});";
        JsScript jsScript = new JsScript(jsText);
        jsScript.setExecuteOnDomReady(true);
        source.getHeadElements().add(jsScript);
    }

Mike


On Fri, Jul 15, 2011 at 23:17, Nicholas Dierauf
<[email protected]> wrote:
> Hello,
>
>
>
> I have figured out to dynamically update a single control using behaviors
> and Ajax, but I need to dynamically update multiple controls (panels and
> forms) when a user clicks a button. I know that I can return a response of
> concatenated html for each of these controls and have the resulting
> JavaScript parse out and update the controls. But I am looking for a more
> elegant solution. Is it possible to make individual Ajax calls to return
> html for each of the controls, and if so, how would I set up AjaxBehviors
> (on a Panel, for example) and call these Behaviors (url’s, parameters, etc)?
>
>
>
> Thank you,
>
> Nick.

Reply via email to