a note about AbstractSingleSelectChoice

2008-02-07 Thread Sergiy Yevtushenko
Hi all,

In my app I was ought to subclass DropDownChoice just because of one small
implementation detail of AbstractSingleSelectChoice.getModelValue():

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

In case when getModelObject() returns, for example string (or any other kind of
key value) while list contains something different (for example POJOs with
key-value pairs), getChoices().indexOf(object) returns -1. It happens because
indexOf() usually implemented so it calls equals() for passed key and provides
element list as a value, while in this case element list is more smart and can
match itself to passed key (of course with proper equals() method). Probably it
worth to consider replace call to indexOf() with loop and reverse the check
(i.e. call equals() for list elements passing key as a parameter). This should
not cause problems with existing code, but may slightly simplify life in cases
similar to the above. Similar issue also exists in
ListMultipleChoice.getModelValue().

Regards,
Sergiy.
*-
[EMAIL PROTECTED]

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: a note about AbstractSingleSelectChoice

2008-02-07 Thread Igor Vaynberg
please add to jira...

-igor


On Feb 7, 2008 2:08 AM, Sergiy Yevtushenko [EMAIL PROTECTED] wrote:
 Hi all,

 In my app I was ought to subclass DropDownChoice just because of one small
 implementation detail of AbstractSingleSelectChoice.getModelValue():

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

 In case when getModelObject() returns, for example string (or any other kind 
 of
 key value) while list contains something different (for example POJOs with
 key-value pairs), getChoices().indexOf(object) returns -1. It happens because
 indexOf() usually implemented so it calls equals() for passed key and provides
 element list as a value, while in this case element list is more smart and 
 can
 match itself to passed key (of course with proper equals() method). Probably 
 it
 worth to consider replace call to indexOf() with loop and reverse the check
 (i.e. call equals() for list elements passing key as a parameter). This should
 not cause problems with existing code, but may slightly simplify life in cases
 similar to the above. Similar issue also exists in
 ListMultipleChoice.getModelValue().

 Regards,
 Sergiy.
 *-
 [EMAIL PROTECTED]

 -
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]



-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: a note about AbstractSingleSelectChoice

2008-02-07 Thread Sergiy Yevtushenko
Igor Vaynberg wrote:
 please add to jira...

Done. Issue WICKET-1331.

Regards,
Sergiy.
*-
[EMAIL PROTECTED] http://es.os2.ru/

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]