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 <mgrigo...@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.deh...@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
>>
>
>

Reply via email to