I wrote the following component, it can be attached to a submit button. 
I edited it a bit so it probably won't compile as it is.
Use it as you will.

Regards,
     Erik.


package nl.amsterdam.rbrb.web.component;

import nl.amsterdam.rbrb.util.StringHelper;
import nl.amsterdam.rbrb.web.RbrbApplication;

import org.apache.commons.lang.StringEscapeUtils;

import wicket.ajax.AjaxRequestTarget;
import wicket.ajax.IAjaxCallDecorator;
import wicket.ajax.calldecorator.AjaxPostprocessingCallDecorator;
import wicket.ajax.markup.html.form.AjaxSubmitButton;
import wicket.markup.html.form.Form;

/**
 * Ajax button that will show ajax indicator and disable the button.
 * Optionally changes the text of the button when it is submitted.
 * 
 * <p>The class of the style is appended with 'disabled'.
 * For example class='formbutton' is changed to class='formbuttondisabled'.</p>
 * 
 * <p>Note: the button text is not reverted. It is assumed that the button
 * will be refreshed on the screen.</p>
 * 
 * @author erik.van.oosten
 */
public abstract class AutoDisablingAjaxSubmitButton extends AjaxSubmitButton {
    private String submittedText;

    /**
     * @param id the component id (not null)
     * @param form the Form (not null)
     * @param submittedText the text to display upon submission, or null for no 
alternative text
     */
    public AutoDisablingAjaxSubmitButton(String id, Form form, String 
submittedText) {
        super(id, form);
        setOutputMarkupId(true);
        if (StringHelper.isTrimmedEmpty(submittedText)) {
            this.submittedText = null;
        } else {
            this.submittedText = 
StringEscapeUtils.escapeJavaScript(submittedText.trim());
        }
    }

    /** [EMAIL PROTECTED] */
    protected IAjaxCallDecorator getAjaxCallDecorator() {
        return new 
AjaxPostprocessingCallDecorator(super.getAjaxCallDecorator()) {
            /** [EMAIL PROTECTED] */
            public CharSequence postDecorateScript(CharSequence script) {
                // Hide the submit button.
                return "var button=wicketGet('" + 
AutoDisablingAjaxSubmitButton.this.getMarkupId() + "');"
                    + "button.setAttribute('oldClassName',button.className);"
                    + "button.setAttribute('oldValue',button.value);"
                    + 
"button.className=button.className+'disabled';button.disabled=true;"
                    + (submittedText == null ? "" : "button.value='" + 
submittedText + "';")
                    + script;
            }

            /** [EMAIL PROTECTED] */
            public CharSequence postDecorateOnFailureScript(CharSequence 
script) {
                return "var button=wicketGet('" + 
AutoDisablingAjaxSubmitButton.this.getMarkupId() + "');"
                    + "button.className=button.getAttribute('oldClassName');"
                    + "button.value=button.getAttribute('oldValue');"
                    + "button.disabled=false;"
                    + script
                    + "alert('" + FAILURE_ALERT_MESSAGE + "');";
            }

            /** [EMAIL PROTECTED] */
            public CharSequence postDecorateOnSuccessScript(CharSequence 
script) {
                // Assume that the button is refreshed
                return script;
            }
        };
    }

    /** [EMAIL PROTECTED] */
    protected abstract void onError(AjaxRequestTarget target, Form form);
}




Flavia Paganelli wrote:
> Hi!
>
> I'm working on a page that provides ajax behavior but also supports 
> simple request-response without javascript.
> I realized I need a component that provides the behavior of both 
> AjaxFallbackLink and AjaxSubmitLink at the same time. On one hand I need 
> it to be a submit link, because on click it has to access the data 
> entered by the user. And on the other hand I also would like that my 
> form worked even when javascript is not enabled.
>
> Both requirements don't seem so odd, so I wonder if someone already had 
> the same problem and found a solution for it. I've been looking at the 
> classes to try to implement a new component with this characteristics, 
> but I got lost.
>
> Maybe there is an alternative solution that I'm not seeing...
>
> Any help will be very much appreciated.
>
> saludos,
>
> Flavia
>
>   

-- 
Erik van Oosten
http://www.day-to-day-stuff.blogspot.com/


-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Wicket-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/wicket-user

Reply via email to