You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Entropy <bl...@gmail.com> on 2013/03/27 15:43:29 UTC

Ajax and validators

I had an ajaxbutton to add selected items from a multiple choice control to
another multiple choice control.  This worked spendidly with me getting the
selected via the getInput() method.  Well, along comes time for me to write
and add a validator to the form, and suddenly the event does not arrive. 
Pull the validator back out and everything works.  So clearly the validator
is in the way, but it shouldn't be...it's not validation time yet!

Question 1: Why would a form validator interfere with an ajaxbutton's event? 
It was NOT a submit button.

Then a co-worker suggested I try to use AjaxLink instead of button, but tie
it to a button.  This allows the event in (Hooray!) but now getInput()
returns null.  As if AjaxLink doesn't bring any screen controls other than
itself.

Question 2: Why is AjaxLink making getInput() null?  If there is some other
mechanism to get form data, what is that mechanism?  

The AjaxLink code looks like:

		add(new AjaxLink("addSelected") {
			private static final long serialVersionUID = 1L;
			@Override
			public void onClick(AjaxRequestTarget target) {
				onAddSelected(target);
			}
		});

	private void onAddSelected(AjaxRequestTarget target) {
		if(listUsers.getInput()!=null) {  //listUsers is null
			List<String> newChoices = (List<String>) listUsers.getChoices();
			List<String> selChoices = new ArrayList<String>();
			for(String index: listUsers.getInputAsArray()) 
				selChoices.add(newChoices.get(Integer.parseInt(index)));
			mergeUniquelyIntoRecipients(recipients, selChoices);
		}
		listUsers.setModelObject(new ArrayList<String>());
		target.addComponent(listUsers);
		target.addComponent(selected);
	}




--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Ajax-and-validators-tp4657570.html
Sent from the Users forum mailing list archive at Nabble.com.

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


Re: Ajax and validators

Posted by Sven Meier <sv...@meiers.net>.
AjaxLink doesn't submit the form, thus no input for FormComponents.

Sven

On 03/27/2013 06:34 PM, Entropy wrote:
> Thanks Sven, that was what I needed.
>
> Just for my learning, why doesn't AjaxLink report the user input?  If it is
> not meant to, it doesn't seem to serve a purpose, so I have to assume I did
> something wrong there as well.
>
>
>
> --
> View this message in context: http://apache-wicket.1842946.n4.nabble.com/Ajax-and-validators-tp4657570p4657586.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> 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: Ajax and validators

Posted by Entropy <bl...@gmail.com>.
Thanks Sven, that was what I needed.  

Just for my learning, why doesn't AjaxLink report the user input?  If it is
not meant to, it doesn't seem to serve a purpose, so I have to assume I did
something wrong there as well.



--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Ajax-and-validators-tp4657570p4657586.html
Sent from the Users forum mailing list archive at Nabble.com.

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


Re: Ajax and validators

Posted by Sven Meier <sv...@meiers.net>.
Hi,

an ajaxbutton submits the form, see its javadoc.

You probably want to use #setDefaultFormProcessing(false) on your button.

Sven

On 03/27/2013 03:43 PM, Entropy wrote:
> I had an ajaxbutton to add selected items from a multiple choice control to
> another multiple choice control.  This worked spendidly with me getting the
> selected via the getInput() method.  Well, along comes time for me to write
> and add a validator to the form, and suddenly the event does not arrive.
> Pull the validator back out and everything works.  So clearly the validator
> is in the way, but it shouldn't be...it's not validation time yet!
>
> Question 1: Why would a form validator interfere with an ajaxbutton's event?
> It was NOT a submit button.
>
> Then a co-worker suggested I try to use AjaxLink instead of button, but tie
> it to a button.  This allows the event in (Hooray!) but now getInput()
> returns null.  As if AjaxLink doesn't bring any screen controls other than
> itself.
>
> Question 2: Why is AjaxLink making getInput() null?  If there is some other
> mechanism to get form data, what is that mechanism?
>
> The AjaxLink code looks like:
>
> 		add(new AjaxLink("addSelected") {
> 			private static final long serialVersionUID = 1L;
> 			@Override
> 			public void onClick(AjaxRequestTarget target) {
> 				onAddSelected(target);
> 			}
> 		});
>
> 	private void onAddSelected(AjaxRequestTarget target) {
> 		if(listUsers.getInput()!=null) {  //listUsers is null
> 			List<String> newChoices = (List<String>) listUsers.getChoices();
> 			List<String> selChoices = new ArrayList<String>();
> 			for(String index: listUsers.getInputAsArray())
> 				selChoices.add(newChoices.get(Integer.parseInt(index)));
> 			mergeUniquelyIntoRecipients(recipients, selChoices);
> 		}
> 		listUsers.setModelObject(new ArrayList<String>());
> 		target.addComponent(listUsers);
> 		target.addComponent(selected);
> 	}
>
>
>
>
> --
> View this message in context: http://apache-wicket.1842946.n4.nabble.com/Ajax-and-validators-tp4657570.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> 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