I'm building a registration page for my wicket app, and I'm having trouble
getting an AjaxFallbackButton to work the way I would like it to.  I have
several fields for the user to fill out on my registration page, including
email, password, desired-username, etc.

What I want is to have an AjaxFallbackButton next to desired-username to see
if it is available and then display a label saying whether it is or isn't
available.  This works fine when AjaxFallbackButton's
setDefaultFormProcessing is set to true (as by default).  However, this runs
the onSubmit() of the form, not just the onSubmit() of the button itself as
I want it to.

If I do ajaxFallbackButton.setDefaultFormProcessing(false) then it gets
nothing from the model.


When I have used non-Ajax buttons in the past with Wicket, I called
textField.updateModel() and then called textField.getModelObject(), which
made it possible to retrieve values with defaultFormProcessing set to false
and therefore did not run the form's onSubmit() method.  However when I do
this with AjaxFallbackButton I get a null pointer execption :(.


If this is too incomprehensible, I can try to make a quickstart
demonstrating the problem.  I'm really not sure what appropriate behavior
with these forms/buttons is to begin with though, so I would really
appreciate help.  I have pasted my class which may help.

Thanks!
Jamie

-------------------------

package com.musictramp.wicket.pages.tests;

import org.apache.wicket.PageParameters;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.markup.html.form.AjaxFallbackButton;
import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.TextField;
import org.apache.wicket.model.Model;

@SuppressWarnings("unchecked")
public class TestPage extends WebPage{
    private static final long serialVersionUID = 1L;
    
    // *** INSTANCE VARS ***
    private TextField textField;
    private Label label;
    
    // *** CONSTRUCTOR ***
    public TestPage () {
        this(null);
    }
    public TestPage(PageParameters params) {        
        Form form = new Form("form"){
            @Override
            protected void onSubmit() {
                System.out.println(">>>>>> form onSubmit()");
            }
        };
        
        textField = new TextField("textField", new Model(""));
        textField.setOutputMarkupId(true);
        
        label = new Label("label", new Model(""));
        label.setOutputMarkupId(true);
        
        AjaxFallbackButton ajaxFallbackButton = new
AjaxFallbackButton("button", form) {
            @Override
            protected void onSubmit(AjaxRequestTarget target, Form form) {
                System.out.println(">>> Ajax button submit:");
                
                String s1 = textField.getModelObject().toString();
                System.out.println("s1=" + s1);
                label.setDefaultModelObject(s1);
                
                if (target != null) {
                    target.addComponent(label);
                }
            }            
        };
        
        // If this is uncommented, then s1 comes out blank:
//        ajaxFallbackButton.setDefaultFormProcessing(false);
        
        form.add(textField);
        form.add(label);
        form.add(ajaxFallbackButton);
        
        add(form);

        
    }


} // CLOSE CLASS.


-- 
View this message in context: 
http://www.nabble.com/AjaxFallbackButton-and-setDefaultFormProcessing%28false%29-tp20316060p20316060.html
Sent from the Wicket - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to