You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by "Collinson, Alasdair" <Al...@senacor.com> on 2015/11/09 19:16:59 UTC

Recreating Select Choices produces weird error handling

Hello everyone!


I've been experiencing a weird behavior with Wicket (version 6.19.0, though I think it should be the same with a newer version). The problem is this:

When I have a Select (from wicket-extensions) to which I add a SelectOptions which has "recreateOptions" set to true, the method Select#isSelected(SelectOption<?>) will no longer work if there is an error while submitting the form. So for example I have two such Selects, both are required, I only select an option for one of them and submit. The result is, that neither has a selected value.


Here's an example of what one of those selects may look like:


Select<String> nameSelect = new Select<String>("name", model);
SelectOptions<String> options = new SelectOptions<String>("options", possibleNamesModel, new IOptionRenderer<String>() {
    @Override
    public String getDisplayValue(String object) {
        if (object == null) {
            return "Please choose";
        }
        return object;
    }

    @Override
    public IModel<String> getModel(String value) {
        return Model.of(value);
    }
});
options.setRecreateChoices(true);
nameSelect.add(options);
nameSelect.setRequired(true);


Am I missing something here or is this a bug? I've created a QuickStart which I could upload if I were to create a ticket.


Thanks,

Alasdair

Alasdair Collinson
______________________________
Senacor Technologies AG
Joseph-Schumpeter-Allee 1
53227 Bonn

T +49 (228) 7636 - 247
F +49 (228) 7636 - 100
M +49 (171) 3019 990

Alasdair.Collinson@senacor.com
www.senacor.com


Senacor Technologies Aktiengesellschaft - Sitz: Schwaig b. Nbg. - Amtsgericht Nbg.- Reg.-Nr.: HRB 23098
Vorstand: Matthias Tomann, Marcus Purzer - Aufsichtsratsvorsitzender: Mathias J. Lindermeir

Diese E-Mail inklusive Anlagen enth?lt vertrauliche und/oder rechtlich gesch?tzte Informationen. Wenn Sie
nicht der richtige Adressat sind oder diese E-Mail irrt?mlich erhalten, informieren Sie bitte den  Absender
und vernichten Sie diese E-Mail. Das unerlaubte Kopieren sowie die unbefugte Weitergabe dieser  E-Mail ist
nicht gestattet.

This e-mail including any attachments may contain confidential and/or privileged information. If you are
not the intended recipient (or have received this e-mail in error) please notify the sender immediately and
destroy this e-mail. Any unauthorized copying, disclosure or distribution of the materials in this e-mail is
strictly forbidden.

Re: AW: Recreating Select Choices produces weird error handling

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

in case of a form validation error, calling "isSelected()" as fallback 
would not give you the currently selected item, but the original one 
from the model.

I don't think this would be better, since the actual user selection 
would get lost unnoticed.

Have fun
Sven


On 10.11.2015 10:40, Collinson, Alasdair wrote:
> Hi Sven!
>
> While I agree that this will solve the problem, it seems more like a workaround than an actual solution. The comparison in "isSelected" only fails if there is raw data; if there isn't "isSelected(Model<?>)" is called which works just fine. So maybe rather than returning "false" immediately if the comparison fails the method "isSelected(Model<?>)" could be called?
>
> Thanks,
> Alasdair
> ________________________________________
> Von: Sven Meier <sv...@meiers.net>
> Gesendet: Montag, 9. November 2015 20:30
> An: users@wicket.apache.org
> Betreff: Re: Recreating Select Choices produces weird error handling
>
> Hi Alasdair,
>
> see https://issues.apache.org/jira/browse/WICKET-5606
>
> I must admit that the 'fix' isn't easy to find.
>
> Have fun
> Sven
>
> On 09.11.2015 19:16, Collinson, Alasdair wrote:
>> Hello everyone!
>>
>>
>> I've been experiencing a weird behavior with Wicket (version 6.19.0, though I think it should be the same with a newer version). The problem is this:
>>
>> When I have a Select (from wicket-extensions) to which I add a SelectOptions which has "recreateOptions" set to true, the method Select#isSelected(SelectOption<?>) will no longer work if there is an error while submitting the form. So for example I have two such Selects, both are required, I only select an option for one of them and submit. The result is, that neither has a selected value.
>>
>>
>> Here's an example of what one of those selects may look like:
>>
>>
>> Select<String> nameSelect = new Select<String>("name", model);
>> SelectOptions<String> options = new SelectOptions<String>("options", possibleNamesModel, new IOptionRenderer<String>() {
>>       @Override
>>       public String getDisplayValue(String object) {
>>           if (object == null) {
>>               return "Please choose";
>>           }
>>           return object;
>>       }
>>
>>       @Override
>>       public IModel<String> getModel(String value) {
>>           return Model.of(value);
>>       }
>> });
>> options.setRecreateChoices(true);
>> nameSelect.add(options);
>> nameSelect.setRequired(true);
>>
>>
>> Am I missing something here or is this a bug? I've created a QuickStart which I could upload if I were to create a ticket.
>>
>>
>> Thanks,
>>
>> Alasdair
>>
>> Alasdair Collinson
>> ______________________________
>> Senacor Technologies AG
>> Joseph-Schumpeter-Allee 1
>> 53227 Bonn
>>
>> T +49 (228) 7636 - 247
>> F +49 (228) 7636 - 100
>> M +49 (171) 3019 990
>>
>> Alasdair.Collinson@senacor.com
>> www.senacor.com
>>
>>
>> Senacor Technologies Aktiengesellschaft - Sitz: Schwaig b. Nbg. - Amtsgericht Nbg.- Reg.-Nr.: HRB 23098
>> Vorstand: Matthias Tomann, Marcus Purzer - Aufsichtsratsvorsitzender: Mathias J. Lindermeir
>>
>> Diese E-Mail inklusive Anlagen enth?lt vertrauliche und/oder rechtlich gesch?tzte Informationen. Wenn Sie
>> nicht der richtige Adressat sind oder diese E-Mail irrt?mlich erhalten, informieren Sie bitte den  Absender
>> und vernichten Sie diese E-Mail. Das unerlaubte Kopieren sowie die unbefugte Weitergabe dieser  E-Mail ist
>> nicht gestattet.
>>
>> This e-mail including any attachments may contain confidential and/or privileged information. If you are
>> not the intended recipient (or have received this e-mail in error) please notify the sender immediately and
>> destroy this e-mail. Any unauthorized copying, disclosure or distribution of the materials in this e-mail is
>> strictly forbidden.
>>
>
> ---------------------------------------------------------------------
> 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
>


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


AW: Recreating Select Choices produces weird error handling

Posted by "Collinson, Alasdair" <Al...@senacor.com>.
Hi Sven!

While I agree that this will solve the problem, it seems more like a workaround than an actual solution. The comparison in "isSelected" only fails if there is raw data; if there isn't "isSelected(Model<?>)" is called which works just fine. So maybe rather than returning "false" immediately if the comparison fails the method "isSelected(Model<?>)" could be called?

Thanks,
Alasdair
________________________________________
Von: Sven Meier <sv...@meiers.net>
Gesendet: Montag, 9. November 2015 20:30
An: users@wicket.apache.org
Betreff: Re: Recreating Select Choices produces weird error handling

Hi Alasdair,

see https://issues.apache.org/jira/browse/WICKET-5606

I must admit that the 'fix' isn't easy to find.

Have fun
Sven

On 09.11.2015 19:16, Collinson, Alasdair wrote:
> Hello everyone!
>
>
> I've been experiencing a weird behavior with Wicket (version 6.19.0, though I think it should be the same with a newer version). The problem is this:
>
> When I have a Select (from wicket-extensions) to which I add a SelectOptions which has "recreateOptions" set to true, the method Select#isSelected(SelectOption<?>) will no longer work if there is an error while submitting the form. So for example I have two such Selects, both are required, I only select an option for one of them and submit. The result is, that neither has a selected value.
>
>
> Here's an example of what one of those selects may look like:
>
>
> Select<String> nameSelect = new Select<String>("name", model);
> SelectOptions<String> options = new SelectOptions<String>("options", possibleNamesModel, new IOptionRenderer<String>() {
>      @Override
>      public String getDisplayValue(String object) {
>          if (object == null) {
>              return "Please choose";
>          }
>          return object;
>      }
>
>      @Override
>      public IModel<String> getModel(String value) {
>          return Model.of(value);
>      }
> });
> options.setRecreateChoices(true);
> nameSelect.add(options);
> nameSelect.setRequired(true);
>
>
> Am I missing something here or is this a bug? I've created a QuickStart which I could upload if I were to create a ticket.
>
>
> Thanks,
>
> Alasdair
>
> Alasdair Collinson
> ______________________________
> Senacor Technologies AG
> Joseph-Schumpeter-Allee 1
> 53227 Bonn
>
> T +49 (228) 7636 - 247
> F +49 (228) 7636 - 100
> M +49 (171) 3019 990
>
> Alasdair.Collinson@senacor.com
> www.senacor.com
>
>
> Senacor Technologies Aktiengesellschaft - Sitz: Schwaig b. Nbg. - Amtsgericht Nbg.- Reg.-Nr.: HRB 23098
> Vorstand: Matthias Tomann, Marcus Purzer - Aufsichtsratsvorsitzender: Mathias J. Lindermeir
>
> Diese E-Mail inklusive Anlagen enth?lt vertrauliche und/oder rechtlich gesch?tzte Informationen. Wenn Sie
> nicht der richtige Adressat sind oder diese E-Mail irrt?mlich erhalten, informieren Sie bitte den  Absender
> und vernichten Sie diese E-Mail. Das unerlaubte Kopieren sowie die unbefugte Weitergabe dieser  E-Mail ist
> nicht gestattet.
>
> This e-mail including any attachments may contain confidential and/or privileged information. If you are
> not the intended recipient (or have received this e-mail in error) please notify the sender immediately and
> destroy this e-mail. Any unauthorized copying, disclosure or distribution of the materials in this e-mail is
> strictly forbidden.
>


---------------------------------------------------------------------
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: Recreating Select Choices produces weird error handling

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

see https://issues.apache.org/jira/browse/WICKET-5606

I must admit that the 'fix' isn't easy to find.

Have fun
Sven

On 09.11.2015 19:16, Collinson, Alasdair wrote:
> Hello everyone!
>
>
> I've been experiencing a weird behavior with Wicket (version 6.19.0, though I think it should be the same with a newer version). The problem is this:
>
> When I have a Select (from wicket-extensions) to which I add a SelectOptions which has "recreateOptions" set to true, the method Select#isSelected(SelectOption<?>) will no longer work if there is an error while submitting the form. So for example I have two such Selects, both are required, I only select an option for one of them and submit. The result is, that neither has a selected value.
>
>
> Here's an example of what one of those selects may look like:
>
>
> Select<String> nameSelect = new Select<String>("name", model);
> SelectOptions<String> options = new SelectOptions<String>("options", possibleNamesModel, new IOptionRenderer<String>() {
>      @Override
>      public String getDisplayValue(String object) {
>          if (object == null) {
>              return "Please choose";
>          }
>          return object;
>      }
>
>      @Override
>      public IModel<String> getModel(String value) {
>          return Model.of(value);
>      }
> });
> options.setRecreateChoices(true);
> nameSelect.add(options);
> nameSelect.setRequired(true);
>
>
> Am I missing something here or is this a bug? I've created a QuickStart which I could upload if I were to create a ticket.
>
>
> Thanks,
>
> Alasdair
>
> Alasdair Collinson
> ______________________________
> Senacor Technologies AG
> Joseph-Schumpeter-Allee 1
> 53227 Bonn
>
> T +49 (228) 7636 - 247
> F +49 (228) 7636 - 100
> M +49 (171) 3019 990
>
> Alasdair.Collinson@senacor.com
> www.senacor.com
>
>
> Senacor Technologies Aktiengesellschaft - Sitz: Schwaig b. Nbg. - Amtsgericht Nbg.- Reg.-Nr.: HRB 23098
> Vorstand: Matthias Tomann, Marcus Purzer - Aufsichtsratsvorsitzender: Mathias J. Lindermeir
>
> Diese E-Mail inklusive Anlagen enth?lt vertrauliche und/oder rechtlich gesch?tzte Informationen. Wenn Sie
> nicht der richtige Adressat sind oder diese E-Mail irrt?mlich erhalten, informieren Sie bitte den  Absender
> und vernichten Sie diese E-Mail. Das unerlaubte Kopieren sowie die unbefugte Weitergabe dieser  E-Mail ist
> nicht gestattet.
>
> This e-mail including any attachments may contain confidential and/or privileged information. If you are
> not the intended recipient (or have received this e-mail in error) please notify the sender immediately and
> destroy this e-mail. Any unauthorized copying, disclosure or distribution of the materials in this e-mail is
> strictly forbidden.
>


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