You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@wicket.apache.org by Jean-Baptiste Quenot <jb...@apache.org> on 2006/10/19 19:54:40 UTC
Getting the selection from a CheckGroup before validation
Hi,
I currently have a typical use-case where a delete button removes
a selection of rows from a table. Typically, the delete button is
a submit button with setDefaultFormProcessing(true) to avoid
validation.
But in this case, I can't find a way to get the checked rows.
Indeed CheckGroup.getConvertedInput() returns null as form has not
been yet validated.
Please see the attached patch and tell me if it is worth to be
part of Wicket.
TIA,
--
Jean-Baptiste Quenot
aka John Banana Qwerty
http://caraldi.com/jbq/
Re: Getting the selection from a CheckGroup before validation
Posted by Igor Vaynberg <ig...@gmail.com>.
On 10/20/06, Jean-Baptiste Quenot <jb...@apache.org> wrote:
>
> * Igor Vaynberg:
>
> > 1) validate the component by calling formcomponent.validate()
>
> The user is not expected to have valid values when wishing to
> remove a row in a ListView.
these are checkboxes...how do you have an invalid list of checkboxes? i
didnt say validate the entire form - just the checkgroup
> 2) validate it to the point where you can get the value - by
> > calling convert()
>
> You said it's not good to call convert() because validation is
> skipped.
no, what i said was:
converted input should only be available after successful convert()
validation step - which you are specifically disabling.
so either let the framework do it, or do it yourself, but convert() has to
be called before you call getConvertedInput()
> --------------------------------8<--------------------------------
>
> Can you comment on my proposal to add a new method in CheckGroup,
> let's say getValues() (with an *s*) that will return a list of
> booleans, checked or unchecked (true or false)?
>
> Is it a good workaround?
no it is not a good work around - there is no list of booleans you can
return. what would the list of booleans represent? there is no order to the
checkboxes that checkgroup keeps, there is no idea of a "boolean" either.
the checkgroup is designed to populate a model that is a collection with the
model values of checks, there is no good way to go around that. also notice
i said collection not list.
maybe what you want to use is a bunch of CheckBox components instead - those
work with booleans.
-Igor
--
> Jean-Baptiste Quenot
> aka John Banana Qwerty
> http://caraldi.com/jbq/
>
Re: Getting the selection from a CheckGroup before validation
Posted by Jean-Baptiste Quenot <jb...@apache.org>.
* Igor Vaynberg:
> 1) validate the component by calling formcomponent.validate()
The user is not expected to have valid values when wishing to
remove a row in a ListView.
> 2) validate it to the point where you can get the value - by
> calling convert()
You said it's not good to call convert() because validation is
skipped.
--------------------------------8<--------------------------------
Can you comment on my proposal to add a new method in CheckGroup,
let's say getValues() (with an *s*) that will return a list of
booleans, checked or unchecked (true or false)?
Is it a good workaround?
--
Jean-Baptiste Quenot
aka John Banana Qwerty
http://caraldi.com/jbq/
Re: Getting the selection from a CheckGroup before validation
Posted by Igor Vaynberg <ig...@gmail.com>.
On 10/19/06, Jean-Baptiste Quenot <jb...@apache.org> wrote:
>
> * Igor Vaynberg:
>
> > i dont realy like this... converted input should only be
> > available after successful convert() validation step - which you
> > are specifically disabling.
>
> I understand your point, but then what do you propose to get the
> selected values?
there are a couple of options
1) validate the component by calling formcomponent.validate()
2) validate it to the point where you can get the value - by calling
convert()
The real problem is that FormComponent.getValue() returns a
> String, that doesn't make sense for a CheckGroup. We should maybe
> change the signature to Object, and return a List<Boolean> in the
> case of the CheckGroup. That way one could have a way to inspect
> the selected checkboxes, without calling convertValue().
getValue() returns the request parameter value that is assigned to the
formcomponent - if it was up to me this detail would be encapsulated
(private) - but unfortunately it is not up to just me.
the reason it would be encapsulated is because like you see in this case it
is really an implementation detail. to you its some incomprehensible
garbage, to checkgroup it is something it can decode and produce a list of
selected checkboxes for you. you shouldnt be messing with it directly.
so, imho, calling convert() followed by getConvertedValue() is the only way
you should have access to that data.
BTW the Javadoc for FormComponent.getValue() is far from being
> clear: «Gets current value for a form component».
i agree. sometimes it is hard to take a point of view of a user who doesnt
understand how wicket works because as committers we have intimate
knowledge. so a patch to the javadoc with your point of view would be most
welcome.
-Igor
Re: Getting the selection from a CheckGroup before validation
Posted by Jean-Baptiste Quenot <jb...@apache.org>.
* Igor Vaynberg:
> i dont realy like this... converted input should only be
> available after successful convert() validation step - which you
> are specifically disabling.
I understand your point, but then what do you propose to get the
selected values?
The real problem is that FormComponent.getValue() returns a
String, that doesn't make sense for a CheckGroup. We should maybe
change the signature to Object, and return a List<Boolean> in the
case of the CheckGroup. That way one could have a way to inspect
the selected checkboxes, without calling convertValue().
WDYT? I'm sure we can find a generic way to deal with this common
problem. It's not just for me ;-)
BTW the Javadoc for FormComponent.getValue() is far from being
clear: « Gets current value for a form component ».
Your comments are welcome,
--
Jean-Baptiste Quenot
aka John Banana Qwerty
http://caraldi.com/jbq/
Re: Getting the selection from a CheckGroup before validation
Posted by Igor Vaynberg <ig...@gmail.com>.
i dont realy like this...
converted input should only be available after successful convert()
validation step - which you are specifically disabling.
you can apply this patch to your own subclass of checkgroup, i dont think it
belongs in the core.
-Igor
On 10/19/06, Jean-Baptiste Quenot <jb...@apache.org> wrote:
>
> Hi,
>
> I currently have a typical use-case where a delete button removes
> a selection of rows from a table. Typically, the delete button is
> a submit button with setDefaultFormProcessing(true) to avoid
> validation.
>
> But in this case, I can't find a way to get the checked rows.
> Indeed CheckGroup.getConvertedInput() returns null as form has not
> been yet validated.
>
> Please see the attached patch and tell me if it is worth to be
> part of Wicket.
>
> TIA,
> --
> Jean-Baptiste Quenot
> aka John Banana Qwerty
> http://caraldi.com/jbq/
>
>
>