You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@wicket.apache.org by Matej Knopp <ma...@knopp.sk> on 2006/10/06 14:12:42 UTC

RadioChoice and null model object

Hi,

we've come across a problem of radio choice not selecting the default 
choice if the choice is null.

I've noticed this in RadioChoice class:

	@Override
	protected final void onComponentTagBody(final MarkupStream markupStream,
			final ComponentTag openTag)
	{
		// Iterate through choices
		final List<T> choices = getChoices();

		// Buffer to hold generated body
		final AppendingStringBuffer buffer = new 
AppendingStringBuffer((choices.size() + 1) * 70);

		// The selected value
		final String selected = getValue();
=========================================/\
			is this correct? shouldn't it be rather
			getChoiceRenderer().getIdValue(getModelObject())


-Matej

Re: RadioChoice and null model object

Posted by Johan Compagner <jc...@gmail.com>.
no getValue == the rawinput or the getModelValue and rawinput is always the
id
and getModelValue should also be the id.

see abstractsingleselectchoice:

public final String getModelValue()
    {
        final T object = getModelObject();
        if (object != null)
        {
            int index = getChoices().indexOf(object);
            return getChoiceRenderer().getIdValue(object, index);
        }
        return NO_SELECTION_VALUE;
    }


johan


On 10/6/06, Matej Knopp <ma...@knopp.sk> wrote:
>
> Hi,
>
> we've come across a problem of radio choice not selecting the default
> choice if the choice is null.
>
> I've noticed this in RadioChoice class:
>
>         @Override
>         protected final void onComponentTagBody(final MarkupStream
> markupStream,
>                         final ComponentTag openTag)
>         {
>                 // Iterate through choices
>                 final List<T> choices = getChoices();
>
>                 // Buffer to hold generated body
>                 final AppendingStringBuffer buffer = new
> AppendingStringBuffer((choices.size() + 1) * 70);
>
>                 // The selected value
>                 final String selected = getValue();
> =========================================/\
>                         is this correct? shouldn't it be rather
>                         getChoiceRenderer().getIdValue(getModelObject())
>
>
> -Matej
>