You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by "Artem Morozov (JIRA)" <ji...@apache.org> on 2013/06/05 23:49:20 UTC

[jira] [Comment Edited] (WICKET-5217) Introduce interfaces for base wicket objects and use them in API.

    [ https://issues.apache.org/jira/browse/WICKET-5217?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13676388#comment-13676388 ] 

Artem Morozov edited comment on WICKET-5217 at 6/5/13 9:48 PM:
---------------------------------------------------------------

Let me try to explain :
There is panel class PanelA extends Panel implements SpecificInterface.
Component, that holds PanelA as child, knows only about SpicificInterface. For simplicity name it as ParentComponent.
ParentComponent uses ajax to manage non-trivial logic, and tryes to update SpecificInterface via AjaxRequestTarget.add(SpecificInterface). Obviously ParentComponent can not do this, since SpecificInterface is not a child of Component. Component is a class. The most simple way - just cast SpicificInterface to Component. But it does not work in tests, where SpecificInterface could be a mock object and casting failes during tests execution. There are several workarounds which help to solve this problem. For example: SpecificInterface could have method, which returns Component (returns "this" in implementation). So, the code could look like AjaxRequestTarget.add(SpecificInterface.asComponent());, But why make this tricks?

Why not to use
class PanelA extends Panel implements SpecificInterface, IComponent {}
and do all stuff in the most natural way.
                
      was (Author: a.morozov):
    Let me try to explain :
There is panel class PanelA extends Panel implements SpecificInterface.
Component, that holds PanelA as child, knows only about SpicificInterface. For simplicity name it as ParentComponent.
ParentComponent uses ajax to manage non-trivial logic, and tryes to update SpecificInterface via AjaxRequestTarget.add(SpecificInterface). Obviously ParentComponent can not do this, since SpecificInterface is not a child of Component. Component is a class. The most simple way - just cast SpicificInterface to Component. But it does not work in tests, where SpecificInterface could be a mock object and casting failes during tests execution. There are several workarounds which help to solve this problem. For example: SpecificInterface choud have method, which returns Component (returns "this" in implementation). So, the code could look like {code}AjaxRequestTarget.add(SpecificInterface.asComponent){/code}, But why make this tricks?
                  
> Introduce interfaces for base wicket objects and use them in API.
> -----------------------------------------------------------------
>
>                 Key: WICKET-5217
>                 URL: https://issues.apache.org/jira/browse/WICKET-5217
>             Project: Wicket
>          Issue Type: Improvement
>          Components: wicket
>            Reporter: Artem Morozov
>
> Introduce the following interfaces:
> * IComponent for Component class
> * IBehavior for Behavior
> .....
> Reason:
> There are lots of cases, where custom components/behaviour implements some custom interfaces.
> But usage of those components as interface refrences is difficult, because of wicket classes require interfaces.
> E. g.
> AjaxRequestTarget.add(Component..) <-- could be usefull adding IComponent there
> BaseWicketTester.getComponentFromLastRenderedPage(String path) <--- returns Component
> ...
> Thanks!

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira