Hi,
Have a look at the AjaxBehavior demo in the Click distribution, it shows how to call the link's
AjaxBehavior:
http://click.avoka.com/click-examples/ajax/ajax-behavior.htm
Calling the behavior on a Panel should be no different. The URL only needs to specify the Panel's ID
and that will instruct Click to process the Panel. If the panel had an id of "mypanel" a URL could
look like:
http://localhost/click-examples/ajax/ajax-behavior.htm?mypanel=1
As a test modify the AjaxBehavior demo and replace the ActionLink with a Panel.
regards
Bob
On 2011/07/16 19:27 PM, Nicholas Dierauf wrote:
Wonderful. Thanks very much for your explanation. I will definitely investigate
this.
I implemented a kludgy work-around by adding an additional ActionLink to my form with a
"visibility" style of "none" and added a DefaultAjaxBehavior. Then, after the behavior
for the Submit button was executed, the JavaScript code then performs an onclick event on this hidden link to
update other controls. Not so elegant, but works ... Your suggestion sounds much more elegant. Either way, it
is a lot of hoops to jump through in order to achieve a more "desktop" app look and feel :-).
I am still interested in understanding how I can attach an AjaxBehavior to a
control such as a Panel and how I can call that behavior via JavaScript. In a
subsequent email from Bob Schellink (thanks Bob), he mentions that I would need
to send the Control's ID in an Ajax request in order to target that Control and
it's behavior. I feel like I've tried this with no success. I'm probably doing
it wrong somehow. I would be interested in seeing what a URL would look like to
call the targeted Control and behavior. Some sample code would be lovely!
Thanks very much Mike and Bob.
Nick.
-----Original Message-----
From: Mike Hoolehan [mailto:[email protected]]
Sent: Saturday, July 16, 2011 12:22 AM
To: [email protected]
Subject: Re: Update multiple panels using Ajax?
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.