You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Martin Makundi <ma...@koodaripalvelut.com> on 2009/02/12 19:36:24 UTC

Checkbox OnChangeAjaxBehavior with defaultFormProcessing=false??

Hi!

My problem:
1. I have a form
2. The form has checkboxes
3. The form has other fields

The checkboxes are used to disable specific fields in the form.
Whenever the user changes the checkbox state, I want to use
AjaxEventBehavior or similar to update the form components dependent
on the particular checkbox (just to set them enabled/disabled).

The problem is that OnChangeAjaxBehavior does not submit the form
component values to the server so their original model values
displayed, which does not look cool if the user just wrote something
there... I tried using AjaxFormSubmitBehavior but that ended up
clearing the fields completely after toggling them into disabled state
and back.

The funny thing, again, is that I can get almost what I want by using
"wantOnSelectionChangedNotifications()=true". But that's not ajax, it
scrolls my page ;) How to make it ajax on a checkbox?

**
Martin

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Checkbox OnChangeAjaxBehavior with defaultFormProcessing=false??

Posted by Martin Makundi <ma...@koodaripalvelut.com>.
I could actually "hack" this feature by adding an AjaxButton onto the
page which has defaultFormProcessing=false and then hide that button
using css/style and always invoke that button when a checkbox is
clicked. But it would be betterto just make sure Wicket supports such
events for FormComponents.

:::

> Maybe a conversion error that prohibits updating the model?

I do not want to update the model. I want
"defaultFormProcessing=false" with the particular ajax event.

> In a way, yes, but sometimes purely client-side stuff can be
> easier purely on the client-side.

The functionality is already in Wicket because
wantOnSelectionChangedNotifications=true works (non-ajax). If it does
not yet exist for Ajax, I would like someone to guide me and I could
maybe code it myself.

**
Martin

>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Checkbox OnChangeAjaxBehavior with defaultFormProcessing=false??

Posted by Martin Makundi <ma...@koodaripalvelut.com>.
> Maybe a conversion error that prohibits updating the model?

I do not want to update the model. I want
"defaultFormProcessing=false" with the particular ajax event.

> In a way, yes, but sometimes purely client-side stuff can be
> easier purely on the client-side.

The functionality is already in Wicket because
wantOnSelectionChangedNotifications=true works (non-ajax). If it does
not yet exist for Ajax, I would like someone to guide me and I could
maybe code it myself.

**
Martin

>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Checkbox OnChangeAjaxBehavior with defaultFormProcessing=false??

Posted by Martin Makundi <ma...@koodaripalvelut.com>.
Actually one must hack even further to reject the "submitButton=1"
value being added at form submit javascript:

  /**
   * wicket-ajax:
   *
   * if (submitButton != null) {
   *   s += Wicket.Form.encode(submitButton) + "=1";
   * }
   *
   * @see org.apache.wicket.markup.html.form.FormComponent#getInputAsArray()
   */
  @Override
  public String[] getInputAsArray() {
    List<String> strings = Arrays.asList(super.getInputAsArray());
    strings.remove("1");
    return strings.toArray(new String[strings.size()]);
  }

  /**
   * @see org.apache.wicket.markup.html.form.AbstractSingleSelectChoice#getModelValue()
   */
  @Override
  public String getModelValue() {
    String value = super.getModelValue();
    if ("1".equals(value)) {
      throw new IllegalStateException("1 not supported because of
javaScript wicket-ajax:submitForm: function(form, submitButton)");
    }
    return value;
  }


Is there a feature request that would allow a normal component to
implement IFormSubmittingComponent without adding the =1 code?
wicket-ajax:
	// Submits a form using ajax.
	// This method serializes a form and sends it as POST body.
	submitForm: function(form, submitButton) {
	    var body = function() {
	    	var s = Wicket.Form.serialize(form);
	    	if (submitButton != null) {
		        s += Wicket.Form.encode(submitButton) + "=1";
		    }
		    return s;		
	    }
	    return this.request.post(body);
	},

**
Martin

2009/4/28 Martin Makundi <ma...@koodaripalvelut.com>:
> Ahh, now I know. I just need to make FormSubmittingCheckBox implements
> IFormSubmittingComponent and then checkBox.add(new
> AjaxFormSubmitBehavior("onchange")).
>
> Yippee!
>
> **
> Martin
>
> 2009/2/13 Timo Rantalaiho <Ti...@ri.fi>:
>> On Fri, 13 Feb 2009, Martin Makundi wrote:
>>> Yes, this is what I am trying to do, but disabling and enabling a
>>> textfield ends up clearing its value too if I use
>>> AjaxFormSumitBehavior. Don't know why.
>>
>> Maybe a conversion error that prohibits updating the model?
>> Though in the case of validation or conversion errors the
>> erroneous input could be preserved... but maybe the Ajax
>> update gets it from the model anyway?
>>
>> 0) raw input
>> 1) convert -> if succeeds, convertedInput
>> 2) validate -> if succeeds, model
>>
>> Do you have a feedback panel on the page?
>>
>> By debugging Form.process() you can probably see easily
>> what's going on.
>>
>>> I feel it is more consistent to use just plain Wicket.
>>
>> In a way, yes, but sometimes purely client-side stuff can be
>> easier purely on the client-side.
>>
>> Best wishes,
>> Timo
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>>
>>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Checkbox OnChangeAjaxBehavior with defaultFormProcessing=false??

Posted by Martin Makundi <ma...@koodaripalvelut.com>.
Ahh, now I know. I just need to make FormSubmittingCheckBox implements
IFormSubmittingComponent and then checkBox.add(new
AjaxFormSubmitBehavior("onchange")).

Yippee!

**
Martin

2009/2/13 Timo Rantalaiho <Ti...@ri.fi>:
> On Fri, 13 Feb 2009, Martin Makundi wrote:
>> Yes, this is what I am trying to do, but disabling and enabling a
>> textfield ends up clearing its value too if I use
>> AjaxFormSumitBehavior. Don't know why.
>
> Maybe a conversion error that prohibits updating the model?
> Though in the case of validation or conversion errors the
> erroneous input could be preserved... but maybe the Ajax
> update gets it from the model anyway?
>
> 0) raw input
> 1) convert -> if succeeds, convertedInput
> 2) validate -> if succeeds, model
>
> Do you have a feedback panel on the page?
>
> By debugging Form.process() you can probably see easily
> what's going on.
>
>> I feel it is more consistent to use just plain Wicket.
>
> In a way, yes, but sometimes purely client-side stuff can be
> easier purely on the client-side.
>
> Best wishes,
> Timo
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Checkbox OnChangeAjaxBehavior with defaultFormProcessing=false??

Posted by Timo Rantalaiho <Ti...@ri.fi>.
On Fri, 13 Feb 2009, Martin Makundi wrote:
> Yes, this is what I am trying to do, but disabling and enabling a
> textfield ends up clearing its value too if I use
> AjaxFormSumitBehavior. Don't know why.

Maybe a conversion error that prohibits updating the model?
Though in the case of validation or conversion errors the 
erroneous input could be preserved... but maybe the Ajax 
update gets it from the model anyway?

0) raw input
1) convert -> if succeeds, convertedInput
2) validate -> if succeeds, model

Do you have a feedback panel on the page?

By debugging Form.process() you can probably see easily 
what's going on.

> I feel it is more consistent to use just plain Wicket.

In a way, yes, but sometimes purely client-side stuff can be
easier purely on the client-side.

Best wishes,
Timo


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Checkbox OnChangeAjaxBehavior with defaultFormProcessing=false??

Posted by Martin Makundi <ma...@koodaripalvelut.com>.
> If you repaint the component from the server, and want to
> retain its input, you have to submit to the server and store
> it to the model (with a suitable *submittingbehavior) so
> that it will have the correct value on the repaint.

Yes, this is what I am trying to do, but disabling and enabling a
textfield ends up clearing its value too if I use
AjaxFormSumitBehavior. Don't know why.

> Another option is to do it purely on the client side --

I feel it is more consistent to use just plain Wicket.

**
Martin

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Checkbox OnChangeAjaxBehavior with defaultFormProcessing=false??

Posted by Timo Rantalaiho <Ti...@ri.fi>.
On Thu, 12 Feb 2009, Martin Makundi wrote:
> 1. I have a form
> 2. The form has checkboxes
> 3. The form has other fields
> 
> The checkboxes are used to disable specific fields in the form.
> Whenever the user changes the checkbox state, I want to use
> AjaxEventBehavior or similar to update the form components dependent
> on the particular checkbox (just to set them enabled/disabled).

If you repaint the component from the server, and want to
retain its input, you have to submit to the server and store
it to the model (with a suitable *submittingbehavior) so
that it will have the correct value on the repaint.  Because
the Ajax response content always comes directly from the
server it has only access to submitted data. So, if you have
one checkbox that toggles several input elements, you must
use a behavior that submits the whole form.

Another option is to do it purely on the client side --
toggle the input DOM element properties with javascript 
attached on the correct event handler ("onclick" I think?)
of the checkboxes. Your favourite Javascript library (e.g.
http://acko.net/files/jQuery%20-%2023%20March%202007.pdf )
can come handy there. 

Best wishes,
Timo

-- 
Timo Rantalaiho           
Reaktor Innovations Oy    <URL: http://www.ri.fi/ >

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org