You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by francisco treacy <fr...@gmail.com> on 2008/06/19 21:03:24 UTC
help with ajax behavior
hi!
a few days ago i posted a NicEditTextAreaBehavior. thanks to some
exchange with another wicketer, we managed to get a working version.
in order to use it and post an updated version of the field contents
(hence correctly updating the underlying Model), nicEdit textarea
requires the user to call a javascript snippet [
wicketNicEditor.nicInstances[0].saveContent(); ].
the approach that worked for me was decorating the ajax button call,
preppending the mentioned js code. i was just wondering if there was a
more elegant way, i.e. not having to explicitly call
protected IAjaxCallDecorator getAjaxCallDecorator() {
return behavior.NICEDIT_AJAX_BUTTON_DECORATOR;
}
is there a way to encapsulate 100% functionality inside the behavior,
maybe through an implicit ajax callback to the behavior? i tried but
couldn't it figure out.
thanks,
francisco
usage:
(...)
final NicEditTextAreaBehavior behavior = new NicEditTextAreaBehavior();
textarea.add(behavior);
(...)
form.add(new AjaxFallbackButton("submit", form) {
@Override
protected IAjaxCallDecorator getAjaxCallDecorator() {
return behavior.NICEDIT_AJAX_BUTTON_DECORATOR;
}
(...)
});
(...)
public class NicEditTextAreaBehavior extends AbstractAjaxBehavior {
private Boolean fullPanel = Boolean.TRUE;
private static final ResourceReference NICEDIT_JAVASCRIPT =
new
JavascriptResourceReference(NicEditTextAreaBehavior.class,
"nicEdit.js");
private static final ResourceReference NICEDIT_ICONS = new
ResourceReference(NicEditTextAreaBehavior.class,
"nicEditorIcons.gif");
public static final AjaxCallDecorator NICEDIT_AJAX_BUTTON_DECORATOR =
new AjaxCallDecorator() {
@Override
public CharSequence decorateScript(final CharSequence script) {
return
"wicketNicEditor.nicInstances[0].saveContent();" + script;
}
};
public NicEditTextAreaBehavior() {
}
public NicEditTextAreaBehavior(Boolean fullPanel) {
this.fullPanel = fullPanel;
}
@Override
protected void onBind() {
super.onBind();
getComponent().setOutputMarkupId(true);
}
@Override
public void onRequest() {
}
@Override
public void renderHead(IHeaderResponse response) {
super.renderHead(response);
response.renderJavascriptReference(NICEDIT_JAVASCRIPT);
response.renderJavascript("var wicketNicEditor; function
wicketNicEditorUpdate() {
wicketNicEditor.nicInstances[0].saveContent(); };", null);
response.renderOnDomReadyJavascript("wicketNicEditor = new
nicEditor({iconsPath : '"+ RequestCycle.get().urlFor(
NICEDIT_ICONS) +"', fullPanel : "+
fullPanel +"}).panelInstance('"
+ getComponent().getMarkupId() + "');");
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org