The only problem right now is the cast to Component[]. The fix is
easy, just change it to Object[]. The optimization makes a lot of
sense and there is reason why it can't really be simple.

-Matej

On Mon, Dec 1, 2008 at 2:29 AM, jWeekend <[EMAIL PROTECTED]> wrote:
>
> MarkupContainer's children field is declared as an Object and can refer to
>
> a ChildList - which is a List, hopefully (until it's genericised) of
> Components,
> an Object[] - again, hopefully of Components,
> a Component - ie a single child, or, even
> a ComponentSourceEntry - a bare-bones representation of only the
> "essentials" of a Component from which it can be reconstructed.
>
> I assume MarkupContainer's implementation was refactored (_from_ something
> much more straight-forward) as an optimisation, in particular related to
> serialisation, with the argument probably along the lines of: it is common
> for a MarkupContainer to have just a single child, so we don't want the
> luggage of a List in those cases etc ...
>
> All this can make MarkupContainer pretty fragile, easy to accidentally
> break. If the optimisation argument is really strong enough (I expect it
> must have been at the time and may still be), at the very least, all the
> messy operations on "children" could be encapsulated in a class (perhaps
> called FunkyChildren, possibly as an inner class if it necessarily needs
> access to its owning MarkupContainer instance's guts and is never used
> outside this context) that exposes only friendly methods like
> set(int index,Component child) and
> remove(Component child)
> etc ...
>
> Apart from simplifying MarkupContainer, the above design would also have the
> benefit of making it possible to address the problem in hand (with the
> illegal runtime array cast), mend what's broken and test this funky,
> edge-case(?) behaviour without having to interfere with MarkupContainer.
> And, if there's a simpler/better/more efficient FunkyChildren possible for
> 1.5 just plug in the new implementation. Importantly, as this an internal
> change (internal to MarkupContainer), there will be no API break (neither
> within Wicket nor in the public API).
>
> Regards - Cemal
> http://www.jWeekend.co.uk http://jWeekend.co.uk
>
>
>
> Matej Knopp-2 wrote:
>>
>> this
>>
>> sorted = Arrays.asList((Component[])children);
>>
>> doesn't look right. I think it should have been (Object[])children
>> although a type check would be appropriate.
>>
>> -Matej
>>
>> On Fri, Nov 28, 2008 at 7:30 PM, jWeekend <[EMAIL PROTECTED]>
>> wrote:
>>>
>>> Not quite.
>>> String[] bO = (String[])(new Object[]{"yes","we","can"});
>>> compiles but fails at run time.
>>>
>>> Regards - Cemal
>>> http://www.jWeekend.co.uk  http://jWeekend.co.uk
>>>
>>>
>>>
>>> Valentine2008 wrote:
>>>>
>>>> It will bring the compilation error when trying to cast arrays in Java.
>>>>
>>>> So you mean it is a bug in Wicket?
>>>>
>>>>
>>>> Timo Rantalaiho wrote:
>>>>>
>>>>> On Thu, 27 Nov 2008, Valentine2008 wrote:
>>>>>> java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to
>>>>>> [Lorg.apache
>>>>>> .wicket.Component;
>>>>>>         at
>>>>>> org.apache.wicket.MarkupContainer.iterator(MarkupContainer.java:478)
>>>>>> .........
>>>>>>
>>>>>> The code on line 478 of MarkupContainer.java is:
>>>>>> sorted = Arrays.asList((Component[])children);
>>>>>>
>>>>>> Is it a bug of Wicket?
>>>>>
>>>>> No, I think it's a limitation of Java. You cannnot cast
>>>>> arrays.
>>>>>
>>>>> Best wishes,
>>>>> Timo
>>>>>
>>>>> --
>>>>> Timo Rantalaiho
>>>>> Reaktor Innovations Oy    <URL: http://www.ri.fi/ >
>>>>>
>>>>> ---------------------------------------------------------------------
>>>>> To unsubscribe, e-mail: [EMAIL PROTECTED]
>>>>> For additional commands, e-mail: [EMAIL PROTECTED]
>>>>>
>>>>>
>>>>>
>>>>
>>>>
>>>
>>> --
>>> View this message in context:
>>> http://www.nabble.com/Bug-of-Wicket-1.3.4-when-iterate-the-form-using-iterator%28Comparator%29--tp20723903p20738179.html
>>> Sent from the Wicket - User mailing list archive at Nabble.com.
>>>
>>>
>>> ---------------------------------------------------------------------
>>> 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]
>>
>>
>>
>
> --
> View this message in context: 
> http://www.nabble.com/Bug-of-Wicket-1.3.4-when-iterate-the-form-using-iterator%28Comparator%29--tp20723903p20764684.html
> Sent from the Wicket - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> 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]

Reply via email to