You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by "Liam Clarke (JIRA)" <ji...@apache.org> on 2010/06/03 04:59:57 UTC

[jira] Updated: (WICKET-2905) Select.isSelected fails when Wicket application is using REDIRECT_TO_RENDER render strategy.

     [ https://issues.apache.org/jira/browse/WICKET-2905?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Liam Clarke updated WICKET-2905:
--------------------------------

              Summary: Select.isSelected fails when Wicket application is using REDIRECT_TO_RENDER render strategy.  (was: Select.isSelected not using model comparison when rawInput available but request parameters not)
    Affects Version/s: 1.4.9
          Description: 
To reproduce using attached quick start:

1. Leave text field empty
2. Select a value in dropdown
3. Click submit link

The dropdown's selected value will always be the first available.

As the dropdown is updating its model via the AJAX behaviour, the selected value should remain.

We can workaround this like so: 

        final Select select = new Select("select", New Model<String>("")) {
            @Override
            protected void convertInput() {
                super.convertInput();
                clearInput();
            }
        };

As this removes the rawInput from Select, Select.isSelected then evaluates the models to determine the selected option. I have attached a patch in universal diff format that fixes this behaviour, and have tested it under all render strategies. I haven't written a unit test for this as the bug ultimately relied on submitted values not being available in a request, and I wasn't able to determine how to emulate this in a unit testing environment. (Pointers more than welcome. :) )

  was:
I'm not sure if this is a bug, a feature, or a symptom of another problem. I have been unable to produce a test case for it. The basic breakdown is as follows. We have a Wicket Extensions Select within a wizard step, which updates its model via an OnChangeAjaxBehaviour. When the wizard's next button is pressed and another component on the page fails to validate, the value of the select is reset to the first option.

The form is POSTed, and the Select's rawInput is populated with the selected option's value. Due to the validation failure, Wicket issues a 302 back to the page, and on the subsequent GET, the Select re-renders, which involves each SelectOption calling Select.isSelected. At this stage, the Select still has the rawInput field populated (with the path of the selected option component) which means that Select.isSelected attempts to retrieve the path of the selected option component from the request - which returns null, and isSelected simply returns false.

We workaround this like so: 

        final Select select = new Select("select", New Model<String>("")) {
            @Override
            protected void convertInput() {
                super.convertInput();
                clearInput();
            }
        };

As this removes the rawInput from Select, Select.isSelected then evaluates the models to determine the selected option. But it feels very hacky. I've attached a diff showing one possible 'solution' - if this is actually a problem, I'm entirely uncertain on that matter - it's a problem for me, but it may well be I'm doing something odd.



Significantly rewrote the bug description once we determined the origin of the problem and created a reproducible test case,

> Select.isSelected fails when Wicket application is using REDIRECT_TO_RENDER render strategy.
> --------------------------------------------------------------------------------------------
>
>                 Key: WICKET-2905
>                 URL: https://issues.apache.org/jira/browse/WICKET-2905
>             Project: Wicket
>          Issue Type: Bug
>          Components: wicket-extensions
>    Affects Versions: 1.4.9
>            Reporter: Liam Clarke
>            Priority: Minor
>         Attachments: select-bug_reproduction.zip
>
>
> To reproduce using attached quick start:
> 1. Leave text field empty
> 2. Select a value in dropdown
> 3. Click submit link
> The dropdown's selected value will always be the first available.
> As the dropdown is updating its model via the AJAX behaviour, the selected value should remain.
> We can workaround this like so: 
>         final Select select = new Select("select", New Model<String>("")) {
>             @Override
>             protected void convertInput() {
>                 super.convertInput();
>                 clearInput();
>             }
>         };
> As this removes the rawInput from Select, Select.isSelected then evaluates the models to determine the selected option. I have attached a patch in universal diff format that fixes this behaviour, and have tested it under all render strategies. I haven't written a unit test for this as the bug ultimately relied on submitted values not being available in a request, and I wasn't able to determine how to emulate this in a unit testing environment. (Pointers more than welcome. :) )

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.