Re: AjaxFallbackButton and setDefaultFormProcessing(false)

2008-11-04 Thread Michael Sparer

you could try nesting two forms - the inner form would then be the username
that gets submitted by the ajaxbutton.
if you then submit the outer form eventually the inner form gets resubmitted
as well ... AFAIK

and in case you're wondering: wicket supports nested forms (HTML doesn't)
and converts the inner form into a div ...

hope that helps,
Michael


jpswain wrote:
 
 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.
 
 
 


-
Michael Sparer
http://talk-on-tech.blogspot.com
-- 
View this message in context: 
http://www.nabble.com/AjaxFallbackButton-and-setDefaultFormProcessing%28false%29-tp20316060p20318750.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]



AjaxFallbackButton and setDefaultFormProcessing(false)

2008-11-03 Thread jpswain

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]



Re: AjaxFallbackButton and setDefaultFormProcessing(false)

2008-11-03 Thread Timo Rantalaiho
On Mon, 03 Nov 2008, jpswain wrote:
 I'm building a registration page for my wicket app, and I'm having trouble

Building... Designing, rather :)

  http://www.bleading-edge.com/Publications/C++Journal/abstract.htm

 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.

You have to do the submit to get the desired username to
server for checking, and then react accordingly. You could
make uniqueness check a validator and then models do not
get updated if the username is not unique.

Best wishes,
Timo

-- 
Timo Rantalaiho   
Reaktor Innovations OyURL: http://www.ri.fi/ 

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