Thanks to all for your help and suggestions.

I wrote an AjaxFallbackSubmitButton component as Igor suggested. It 
inherits from Button and checks if javascript is enabled in the 
onSubmit() (non-ajax) method. There it can decide whether to call 
onSubmit(AjaxRequestTarget,Form) with null parameters (js not enabled), 
or do nothing because the onSubmit(AjaxRequestTarget,Form) will be 
called by ajax.

I used

    
((WebClientInfo)getSession().getClientInfo()).getProperties().getBoolean(ClientProperties.NAVIGATOR_JAVA_ENABLED)

to check if javascript is enabled, but it throws a 
RestartResponseAtInterceptPageException when it is called for the first 
time (thrown from WebRequestCycle.newClientInfo()), and then a blank 
page is shown. There's a message 'If you see this, it means that both 
javascript and meta-refresh are not support by your browser 
configuration. Please click here to continue to the original 
destination' . Anyone knows why is this? I'm using wicket 1.2.3. Firefox 
2. javascript is enabled.
(I am doing getRequestCycleSettings().setGatherExtendedBrowserInfo(true) 
in my application init() method, as indicated by Eelco.)

Anyone knows why this might be happening? Any way to prevent that page 
from showing? Otherwise it works.

This is the class:

/**
 * Ajax submit button that can fallback to a normal request if 
javascript is not enabled.
 * It checks if javascript is enabled calling
 * <code>new WebClientInfo((WebRequestCycle) 
getRequestCycle()).getProperties().getBoolean(ClientProperties.NAVIGATOR_JAVA_ENABLED)</code>
 * When javascript is not enabled, the methods 
onSubmit(AjaxRequestTarget, Form) is
 * called with null parameters.
 *
 * This class goal is to combine the behavior of a an AjaxSubmitButton 
with fallback behavior if js is not present.
 * 
 * @author flavia.paganelli
 *
 */
public abstract class AjaxFallbackSubmitButton extends Button {

    public AjaxFallbackSubmitButton(String id, final Form form) {
        super(id);

        add(new AjaxFormSubmitBehavior(form, "onclick")
        {

            private static final long serialVersionUID = 1L;

            protected void onSubmit(AjaxRequestTarget target)
            {
                AjaxFallbackSubmitButton.this.onSubmit(target, form);
            }
           
            protected void onError(AjaxRequestTarget target)
            {
                AjaxFallbackSubmitButton.this.onError(target, form);
            }

            protected CharSequence getEventHandler()
            {
                return new 
AppendingStringBuffer(super.getEventHandler()).append("; return false;");
            }

            protected IAjaxCallDecorator getAjaxCallDecorator()
            {
                return new 
CancelEventIfNoAjaxDecorator(AjaxFallbackSubmitButton.this
                        .getAjaxCallDecorator());
            }

        });
    }

    /**
     * Returns the [EMAIL PROTECTED] IAjaxCallDecorator} that will be used to 
modify the
     * generated javascript. This is the preferred way of changing the
     * javascript in the onclick handler
     *
     * @return call decorator used to modify the generated javascript or 
null
     *         for none
     */
    protected IAjaxCallDecorator getAjaxCallDecorator()
    {
        return null;
    }

    protected void onComponentTag(ComponentTag tag)
    {
        checkComponentTag(tag, "input");

        final String type = tag.getAttributes().getString("type");
        if (!"button".equals(type) && !"image".equals(type) && 
!"submit".equals(type))
        {
            findMarkupStream().throwMarkupException(
                    "Component " + getId() + " must be applied to a tag 
with 'type'"
                            + " attribute matching 'submit', 'button' or 
'image', not '" + type
                            + "'");
        }

        super.onComponentTag(tag);
    }

    /**
     * Listener method invoked on form submit with no errors
     *
     * @param target
     * @param form
     */
    protected abstract void onSubmit(AjaxRequestTarget target, Form form);

    /**
     * Listener method invoked on form submit with errors
     *
     * @param target
     * @param form
     *
     */
    protected void onError(AjaxRequestTarget target, Form form) {
    }

    /**
     * If javascript is not enabled, the method onSubmit() is called 
with null values as parameters.
     * Otherwise, this method does nothing.
     */
    @Override
    protected void onSubmit() {
        if (!isJavascriptEnabled()) {
            // call the ajax onSubmit method with target = null only if 
java is disabled
            onSubmit(null, null);
        }
    }

    private boolean isJavascriptEnabled() {
        return 
((WebClientInfo)getSession().getClientInfo()).getProperties().getBoolean(ClientProperties.NAVIGATOR_JAVA_ENABLED);
    }
   
   
}

I'd like to understand why that page is shown the first time I try to 
access the properties (when the newClientInfo() method is called). For 
the rest, I guess the class works ok...

saludos,

Flavia

From: "Igor Vaynberg" <[EMAIL PROTECTED]>

    you say you want it to work even if javascript is disabled, but then you
    cannot submit the form using a link! so you have to user a button to
    submit
    it, and that is easy then, just look at the sourcecode from
    AjaxFallbackLink
    and add the ajax behavior to a button instead of a link.

    -igor



On 1/30/07, Flavia Paganelli <[EMAIL PROTECTED]> 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
> >
> > 

-- 
Flavia Paganelli
Func. Internet Integration
W http://www.func.nl
T +31 20 4230000
F +31 20 4223500


-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier.
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Wicket-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/wicket-user

Reply via email to