You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@isis.apache.org by Erik de Hair <e....@pocos.nl> on 2015/01/02 17:40:58 UTC

replacing Wicket viewer components

Hi,

I tried to replace a component (just to try this out) but got stuck. As 
a first step I copied the ReferencePanelFactory (as 
PortalReferencePanelFactory, still using the ReferencePanal from Isis) 
and created a ComponenFactoryRegistrarDefault as 
PortalComponentFactoryRegistrar like documented at [1]. Then I 
configured the ComponenFactoryRegistrarDefault in the Wicket 
Application. As a result I get the message "??? ScalarModel 
objectAdapter oid: null" for each property when running the application.

Here's my code:

public class PortalReferencePanelFactory extends ComponentFactoryAbstract
{
     private static final long serialVersionUID = 1L;

     public PortalReferencePanelFactory() {
         super(ComponentType.SCALAR_NAME_AND_VALUE, ReferencePanel.class);
     }

     @Override
     public ApplicationAdvice appliesTo(final IModel<?> model) {
         if (!(model instanceof ScalarModel)) {
             return ApplicationAdvice.DOES_NOT_APPLY;
         }
         final ScalarModel scalarModel = (ScalarModel) model;
         final ObjectSpecification specification = 
scalarModel.getTypeOfSpecification();
         return appliesIf(!specification.containsFacet(ValueFacet.class));
     }

     @Override
     public Component createComponent(final String id, final IModel<?> 
model) {
         final ScalarModel scalarModel = (ScalarModel) model;
         return new ReferencePanel(id, scalarModel);
     }
}

@Singleton
public class PortalComponentFactoryRegistrar extends 
ComponentFactoryRegistrarDefault
{
     @Override
     public void addComponentFactories(ComponentFactoryList 
componentFactories) {
         super.addComponentFactories(componentFactories);
         componentFactories.replace(new PortalReferencePanelFactory());
     }
}

Should this be working?

Thanks,
Erik

[1] 
http://isis.apache.org/components/viewers/wicket/customizing-the-viewer.html

Re: replacing Wicket viewer components

Posted by Martin Grigorov <mg...@apache.org>.
Hi,

The difference is in the used ComponentType.
Some component types are handled by several component factories. The
factory uses additional information, like the component model, to decide
whether it could handle the request or not.

If there is only one component factory for a component type then #replace()
should work without problem.

Martin Grigorov
Wicket Training and Consulting
https://twitter.com/mtgrigorov

On Mon, Jan 5, 2015 at 10:18 AM, Erik de Hair <e....@pocos.nl> wrote:

> Hi Dan,
>
> Thanks for your help. Using "add" does the trick for ReferencePanel.
> "replace" however also works for EntityIconAndTitlePanelFactory (for
> example). It looks like there's an architectural difference between the
> ReferencePanel and the EntityIconandTitlePanel.
>
> Erik
>
>
> n 01/04/2015 11:13 AM, Dan Haywood wrote:
>
>> Hi Erik,
>>
>> I just tried this out using "replace", and reproduced the issue... so
>> thanks for bringing it to our attention.
>>
>> In the meantime, using "add" rather than "replace" seems to work ok.
>>
>> I've raised a ticket [2] to fix the issue with "replace", and I've updated
>> the website also [1].
>>
>> Thx
>> Dan
>>
>> [1]
>> http://isis.apache.org/components/viewers/wicket/
>> customizing-the-viewer.html
>> [2] https://issues.apache.org/jira/browse/ISIS-996.
>>
>>
>> On 2 January 2015 at 16:40, Erik de Hair <e....@pocos.nl> wrote:
>>
>>  Hi,
>>>
>>> I tried to replace a component (just to try this out) but got stuck. As a
>>> first step I copied the ReferencePanelFactory (as
>>> PortalReferencePanelFactory, still using the ReferencePanal from Isis)
>>> and
>>> created a ComponenFactoryRegistrarDefault as
>>> PortalComponentFactoryRegistrar like documented at [1]. Then I
>>> configured
>>> the ComponenFactoryRegistrarDefault in the Wicket Application. As a
>>> result I get the message "??? ScalarModel objectAdapter oid: null" for
>>> each
>>> property when running the application.
>>>
>>> Here's my code:
>>>
>>> public class PortalReferencePanelFactory extends ComponentFactoryAbstract
>>> {
>>>      private static final long serialVersionUID = 1L;
>>>
>>>      public PortalReferencePanelFactory() {
>>>          super(ComponentType.SCALAR_NAME_AND_VALUE,
>>> ReferencePanel.class);
>>>      }
>>>
>>>      @Override
>>>      public ApplicationAdvice appliesTo(final IModel<?> model) {
>>>          if (!(model instanceof ScalarModel)) {
>>>              return ApplicationAdvice.DOES_NOT_APPLY;
>>>          }
>>>          final ScalarModel scalarModel = (ScalarModel) model;
>>>          final ObjectSpecification specification = scalarModel.
>>> getTypeOfSpecification();
>>>          return appliesIf(!specification.containsFacet(ValueFacet.
>>> class));
>>>      }
>>>
>>>      @Override
>>>      public Component createComponent(final String id, final IModel<?>
>>> model) {
>>>          final ScalarModel scalarModel = (ScalarModel) model;
>>>          return new ReferencePanel(id, scalarModel);
>>>      }
>>> }
>>>
>>> @Singleton
>>> public class PortalComponentFactoryRegistrar extends
>>> ComponentFactoryRegistrarDefault
>>> {
>>>      @Override
>>>      public void addComponentFactories(ComponentFactoryList
>>> componentFactories) {
>>>          super.addComponentFactories(componentFactories);
>>>          componentFactories.replace(new PortalReferencePanelFactory());
>>>      }
>>> }
>>>
>>> Should this be working?
>>>
>>> Thanks,
>>> Erik
>>>
>>> [1] http://isis.apache.org/components/viewers/wicket/
>>> customizing-the-viewer.html
>>>
>>>
>

Re: replacing Wicket viewer components

Posted by Erik de Hair <e....@pocos.nl>.
Hi Dan,

Thanks for your help. Using "add" does the trick for ReferencePanel. 
"replace" however also works for EntityIconAndTitlePanelFactory (for 
example). It looks like there's an architectural difference between the 
ReferencePanel and the EntityIconandTitlePanel.

Erik

n 01/04/2015 11:13 AM, Dan Haywood wrote:
> Hi Erik,
>
> I just tried this out using "replace", and reproduced the issue... so
> thanks for bringing it to our attention.
>
> In the meantime, using "add" rather than "replace" seems to work ok.
>
> I've raised a ticket [2] to fix the issue with "replace", and I've updated
> the website also [1].
>
> Thx
> Dan
>
> [1]
> http://isis.apache.org/components/viewers/wicket/customizing-the-viewer.html
> [2] https://issues.apache.org/jira/browse/ISIS-996.
>
>
> On 2 January 2015 at 16:40, Erik de Hair <e....@pocos.nl> wrote:
>
>> Hi,
>>
>> I tried to replace a component (just to try this out) but got stuck. As a
>> first step I copied the ReferencePanelFactory (as
>> PortalReferencePanelFactory, still using the ReferencePanal from Isis) and
>> created a ComponenFactoryRegistrarDefault as
>> PortalComponentFactoryRegistrar like documented at [1]. Then I configured
>> the ComponenFactoryRegistrarDefault in the Wicket Application. As a
>> result I get the message "??? ScalarModel objectAdapter oid: null" for each
>> property when running the application.
>>
>> Here's my code:
>>
>> public class PortalReferencePanelFactory extends ComponentFactoryAbstract
>> {
>>      private static final long serialVersionUID = 1L;
>>
>>      public PortalReferencePanelFactory() {
>>          super(ComponentType.SCALAR_NAME_AND_VALUE, ReferencePanel.class);
>>      }
>>
>>      @Override
>>      public ApplicationAdvice appliesTo(final IModel<?> model) {
>>          if (!(model instanceof ScalarModel)) {
>>              return ApplicationAdvice.DOES_NOT_APPLY;
>>          }
>>          final ScalarModel scalarModel = (ScalarModel) model;
>>          final ObjectSpecification specification = scalarModel.
>> getTypeOfSpecification();
>>          return appliesIf(!specification.containsFacet(ValueFacet.class));
>>      }
>>
>>      @Override
>>      public Component createComponent(final String id, final IModel<?>
>> model) {
>>          final ScalarModel scalarModel = (ScalarModel) model;
>>          return new ReferencePanel(id, scalarModel);
>>      }
>> }
>>
>> @Singleton
>> public class PortalComponentFactoryRegistrar extends
>> ComponentFactoryRegistrarDefault
>> {
>>      @Override
>>      public void addComponentFactories(ComponentFactoryList
>> componentFactories) {
>>          super.addComponentFactories(componentFactories);
>>          componentFactories.replace(new PortalReferencePanelFactory());
>>      }
>> }
>>
>> Should this be working?
>>
>> Thanks,
>> Erik
>>
>> [1] http://isis.apache.org/components/viewers/wicket/
>> customizing-the-viewer.html
>>


Re: replacing Wicket viewer components

Posted by Dan Haywood <da...@haywood-associates.co.uk>.
Hi Erik,

I just tried this out using "replace", and reproduced the issue... so
thanks for bringing it to our attention.

In the meantime, using "add" rather than "replace" seems to work ok.

I've raised a ticket [2] to fix the issue with "replace", and I've updated
the website also [1].

Thx
Dan

[1]
http://isis.apache.org/components/viewers/wicket/customizing-the-viewer.html
[2] https://issues.apache.org/jira/browse/ISIS-996.


On 2 January 2015 at 16:40, Erik de Hair <e....@pocos.nl> wrote:

> Hi,
>
> I tried to replace a component (just to try this out) but got stuck. As a
> first step I copied the ReferencePanelFactory (as
> PortalReferencePanelFactory, still using the ReferencePanal from Isis) and
> created a ComponenFactoryRegistrarDefault as
> PortalComponentFactoryRegistrar like documented at [1]. Then I configured
> the ComponenFactoryRegistrarDefault in the Wicket Application. As a
> result I get the message "??? ScalarModel objectAdapter oid: null" for each
> property when running the application.
>
> Here's my code:
>
> public class PortalReferencePanelFactory extends ComponentFactoryAbstract
> {
>     private static final long serialVersionUID = 1L;
>
>     public PortalReferencePanelFactory() {
>         super(ComponentType.SCALAR_NAME_AND_VALUE, ReferencePanel.class);
>     }
>
>     @Override
>     public ApplicationAdvice appliesTo(final IModel<?> model) {
>         if (!(model instanceof ScalarModel)) {
>             return ApplicationAdvice.DOES_NOT_APPLY;
>         }
>         final ScalarModel scalarModel = (ScalarModel) model;
>         final ObjectSpecification specification = scalarModel.
> getTypeOfSpecification();
>         return appliesIf(!specification.containsFacet(ValueFacet.class));
>     }
>
>     @Override
>     public Component createComponent(final String id, final IModel<?>
> model) {
>         final ScalarModel scalarModel = (ScalarModel) model;
>         return new ReferencePanel(id, scalarModel);
>     }
> }
>
> @Singleton
> public class PortalComponentFactoryRegistrar extends
> ComponentFactoryRegistrarDefault
> {
>     @Override
>     public void addComponentFactories(ComponentFactoryList
> componentFactories) {
>         super.addComponentFactories(componentFactories);
>         componentFactories.replace(new PortalReferencePanelFactory());
>     }
> }
>
> Should this be working?
>
> Thanks,
> Erik
>
> [1] http://isis.apache.org/components/viewers/wicket/
> customizing-the-viewer.html
>

Re: replacing Wicket viewer components

Posted by Martin Grigorov <mg...@apache.org>.
Hi Erik,

Ignore my suggestion for the simplification. The API is different and it
doesn't work.
Your way should work though.

For my needs I've used ServiceLoader approach to add a custom component
factory.
The factory doesn't replace another one, as in your requirement, but still
it is asked before the standard factories so it would work for you too.


Martin Grigorov
Wicket Training and Consulting
https://twitter.com/mtgrigorov

On Sat, Jan 3, 2015 at 2:19 PM, Martin Grigorov <mg...@apache.org>
wrote:

> Hi Erik,
>
> I believe all this should work.
> I'd simplify the process by:
>
> 1) adding : @Inject ComponentFactoryRegistrar componentFactoryRegistrar;
> to MyWicketApplication.java
>
> 2) in MyWicketApplication#init() {super.init();
> componentFactoryRegistrar.replace(...); ...}
>
> Put some breakpoints in the related methods and see whether they are
> called.
>
> Martin Grigorov
> Wicket Training and Consulting
> https://twitter.com/mtgrigorov
>
> On Fri, Jan 2, 2015 at 6:40 PM, Erik de Hair <e....@pocos.nl> wrote:
>
>> Hi,
>>
>> I tried to replace a component (just to try this out) but got stuck. As a
>> first step I copied the ReferencePanelFactory (as
>> PortalReferencePanelFactory, still using the ReferencePanal from Isis) and
>> created a ComponenFactoryRegistrarDefault as
>> PortalComponentFactoryRegistrar like documented at [1]. Then I
>> configured the ComponenFactoryRegistrarDefault in the Wicket
>> Application. As a result I get the message "??? ScalarModel objectAdapter
>> oid: null" for each property when running the application.
>>
>> Here's my code:
>>
>> public class PortalReferencePanelFactory extends ComponentFactoryAbstract
>> {
>>     private static final long serialVersionUID = 1L;
>>
>>     public PortalReferencePanelFactory() {
>>         super(ComponentType.SCALAR_NAME_AND_VALUE, ReferencePanel.class);
>>     }
>>
>>     @Override
>>     public ApplicationAdvice appliesTo(final IModel<?> model) {
>>         if (!(model instanceof ScalarModel)) {
>>             return ApplicationAdvice.DOES_NOT_APPLY;
>>         }
>>         final ScalarModel scalarModel = (ScalarModel) model;
>>         final ObjectSpecification specification = scalarModel.
>> getTypeOfSpecification();
>>         return appliesIf(!specification.containsFacet(ValueFacet.class));
>>     }
>>
>>     @Override
>>     public Component createComponent(final String id, final IModel<?>
>> model) {
>>         final ScalarModel scalarModel = (ScalarModel) model;
>>         return new ReferencePanel(id, scalarModel);
>>     }
>> }
>>
>> @Singleton
>> public class PortalComponentFactoryRegistrar extends
>> ComponentFactoryRegistrarDefault
>> {
>>     @Override
>>     public void addComponentFactories(ComponentFactoryList
>> componentFactories) {
>>         super.addComponentFactories(componentFactories);
>>         componentFactories.replace(new PortalReferencePanelFactory());
>>     }
>> }
>>
>> Should this be working?
>>
>> Thanks,
>> Erik
>>
>> [1] http://isis.apache.org/components/viewers/wicket/
>> customizing-the-viewer.html
>>
>
>

Re: replacing Wicket viewer components

Posted by Martin Grigorov <mg...@apache.org>.
Hi Erik,

I believe all this should work.
I'd simplify the process by:

1) adding : @Inject ComponentFactoryRegistrar componentFactoryRegistrar;
to MyWicketApplication.java

2) in MyWicketApplication#init() {super.init();
componentFactoryRegistrar.replace(...); ...}

Put some breakpoints in the related methods and see whether they are called.

Martin Grigorov
Wicket Training and Consulting
https://twitter.com/mtgrigorov

On Fri, Jan 2, 2015 at 6:40 PM, Erik de Hair <e....@pocos.nl> wrote:

> Hi,
>
> I tried to replace a component (just to try this out) but got stuck. As a
> first step I copied the ReferencePanelFactory (as
> PortalReferencePanelFactory, still using the ReferencePanal from Isis) and
> created a ComponenFactoryRegistrarDefault as
> PortalComponentFactoryRegistrar like documented at [1]. Then I configured
> the ComponenFactoryRegistrarDefault in the Wicket Application. As a
> result I get the message "??? ScalarModel objectAdapter oid: null" for each
> property when running the application.
>
> Here's my code:
>
> public class PortalReferencePanelFactory extends ComponentFactoryAbstract
> {
>     private static final long serialVersionUID = 1L;
>
>     public PortalReferencePanelFactory() {
>         super(ComponentType.SCALAR_NAME_AND_VALUE, ReferencePanel.class);
>     }
>
>     @Override
>     public ApplicationAdvice appliesTo(final IModel<?> model) {
>         if (!(model instanceof ScalarModel)) {
>             return ApplicationAdvice.DOES_NOT_APPLY;
>         }
>         final ScalarModel scalarModel = (ScalarModel) model;
>         final ObjectSpecification specification = scalarModel.
> getTypeOfSpecification();
>         return appliesIf(!specification.containsFacet(ValueFacet.class));
>     }
>
>     @Override
>     public Component createComponent(final String id, final IModel<?>
> model) {
>         final ScalarModel scalarModel = (ScalarModel) model;
>         return new ReferencePanel(id, scalarModel);
>     }
> }
>
> @Singleton
> public class PortalComponentFactoryRegistrar extends
> ComponentFactoryRegistrarDefault
> {
>     @Override
>     public void addComponentFactories(ComponentFactoryList
> componentFactories) {
>         super.addComponentFactories(componentFactories);
>         componentFactories.replace(new PortalReferencePanelFactory());
>     }
> }
>
> Should this be working?
>
> Thanks,
> Erik
>
> [1] http://isis.apache.org/components/viewers/wicket/
> customizing-the-viewer.html
>