You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Arnaud Garcia <ar...@imagemed-87.com> on 2010/04/18 14:04:27 UTC
Formating String strategy
Hello,
I would like to format a text field as soon as the onblur event is fired.
( number:XXXXXXXX to XX XX XX XX)
I tried lot of things and I have some questions to improve my wicket
knowledge ;-)
0/ First I add a Validator because I want to be sure that my String is
formated correctly.
1/ If I add an AjaxEventBehavior on the onblur javascript event
=> I don't know how to retrieve the field value ? is it possible ?
2/ I swtich to an AjaxFormComponentUpdatingBehavior to start the full form
pipeline...
Since, the pipeline is : Required check -> Convert input -> validate ->...,
I though it will be ok. BUT as Igor said in a previous thread, the
convertToObject is not called for String (since we don't have to convert a
String to String ;-), well since I understand, in my case it would have been
pretty cool)
3/ Finally I move the convert method in the onUpdate of the
AjaxFormComponentUpdatingBehavior and it works...
=>It means that the Validator is called after the onUpdate ?
4/ finally, last question. When we have to format String dynamicaly which
is the best way ?
a) using the AjaxFormComponentUpdatingBehavior and adding the convert
inside the onUpdate
b) Simply using jQuery ?
thanks for answers in the sunny monday in France !
Arnaud
Re: Formating String strategy
Posted by Martin Makundi <ma...@koodaripalvelut.com>.
Try this:
/**
* @param <T>
* @param formComponent
* @return T
*/
@SuppressWarnings("unchecked")
public static <T> T getConvertedValue(FormComponent<T> formComponent) {
if (formComponent instanceof AbstractSingleSelectChoice) {
try {
return (T)
abstractSingleSelectChoiceConverterMethod.invoke(formComponent,
formComponent.getValue());
} catch (Exception e) {
throw new RuntimeException(e);
}
}
String value = formComponent.getValue();
if (Utils.isEmpty(value) &&
(!String.class.equals(formComponent.getType()))) {
value = null;
}
return (T) formComponent.getConverter(formComponent.getType()).convertToObject(value,
formComponent.getLocale());
}
2010/4/18 Arnaud Garcia <ar...@imagemed-87.com>:
> Hello,
>
> I would like to format a text field as soon as the onblur event is fired.
> ( number:XXXXXXXX to XX XX XX XX)
>
> I tried lot of things and I have some questions to improve my wicket
> knowledge ;-)
>
>
> 0/ First I add a Validator because I want to be sure that my String is
> formated correctly.
>
> 1/ If I add an AjaxEventBehavior on the onblur javascript event
> => I don't know how to retrieve the field value ? is it possible ?
>
> 2/ I swtich to an AjaxFormComponentUpdatingBehavior to start the full form
> pipeline...
>
> Since, the pipeline is : Required check -> Convert input -> validate ->...,
> I though it will be ok. BUT as Igor said in a previous thread, the
> convertToObject is not called for String (since we don't have to convert a
> String to String ;-), well since I understand, in my case it would have been
> pretty cool)
>
> 3/ Finally I move the convert method in the onUpdate of the
> AjaxFormComponentUpdatingBehavior and it works...
>
> =>It means that the Validator is called after the onUpdate ?
>
> 4/ finally, last question. When we have to format String dynamicaly which
> is the best way ?
>
> a) using the AjaxFormComponentUpdatingBehavior and adding the convert
> inside the onUpdate
> b) Simply using jQuery ?
>
>
> thanks for answers in the sunny monday in France !
>
> Arnaud
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org