You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Ondrej Zizka <oz...@redhat.com> on 2012/09/17 03:50:23 UTC

Using interfaces as param type for Page constructor?

Hi,

is there something what prevents Wicket use component constructor with
an interface param instead of concrete object?
I have two entities which share the same properties (leveraging
Hibernate's @Embeddable) :

   public class ProductRelease implements Serializable, IHasTraits
{ ... }
   public class ProductLine implements Serializable, IHasTraits { ... }

and

    public ReleaseTraitsBox( String id, final IHasTraits release )
{ ... }

But this throws upon constructing -  wicket complains it can't find the
constructor.

   Root cause:


  java.lang.NoSuchMethodError: org.jboss.essc.web._cp.pageBoxes.ReleaseTraitsBox.<init>(Ljava/lang/String;Lorg/jboss/essc/web/model/ProductRelease;)V
     at org.jboss.essc.web.pages.ReleasePage.init(ReleasePage.java:53)
     at org.jboss.essc.web.pages.ReleasePage.<init>(ReleasePage.java:39)
     at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
     at org.apache.wicket.session.DefaultPageFactory.newPage(DefaultPageFactory.java:170)


I had to do this:

    // Wicket needs this :(
    public ReleaseTraitsBox( String id, final ProductLine prod ) {
        this( id, prod, 0 );
    }
    public ReleaseTraitsBox( String id, final ProductRelease release ) {
        this( id, release, 0 );
    }

    public ReleaseTraitsBox( String id, final IHasTraits release, int
foo ) {
        super(id);

Is there a better way?
Wicket 1.5.

Thanks,
Ondra

Re: Using interfaces as param type for Page constructor?

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

Default impl of IPageFactory interface in Wicket knows how to
instantiate only pages with default (empty) constructor and with
PageParameters as only parameter.
If your page has your own parameters (like IHasTraits) then you need
either to instantiate the page yourself (e.g. setResponsePage(new
ProductRelease("someId", new SomeHasTraitsImpl())))
or setup a custom impl of IPageFactory that knows which impl to use
for the custom parameters (in your case String and IHasTraits).

On Mon, Sep 17, 2012 at 4:50 AM, Ondrej Zizka <oz...@redhat.com> wrote:
> Hi,
>
> is there something what prevents Wicket use component constructor with
> an interface param instead of concrete object?
> I have two entities which share the same properties (leveraging
> Hibernate's @Embeddable) :
>
>    public class ProductRelease implements Serializable, IHasTraits
> { ... }
>    public class ProductLine implements Serializable, IHasTraits { ... }
>
> and
>
>     public ReleaseTraitsBox( String id, final IHasTraits release )
> { ... }
>
> But this throws upon constructing -  wicket complains it can't find the
> constructor.
>
>    Root cause:
>
>
>   java.lang.NoSuchMethodError: org.jboss.essc.web._cp.pageBoxes.ReleaseTraitsBox.<init>(Ljava/lang/String;Lorg/jboss/essc/web/model/ProductRelease;)V
>      at org.jboss.essc.web.pages.ReleasePage.init(ReleasePage.java:53)
>      at org.jboss.essc.web.pages.ReleasePage.<init>(ReleasePage.java:39)
>      at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
>      at org.apache.wicket.session.DefaultPageFactory.newPage(DefaultPageFactory.java:170)
>
>
> I had to do this:
>
>     // Wicket needs this :(
>     public ReleaseTraitsBox( String id, final ProductLine prod ) {
>         this( id, prod, 0 );
>     }
>     public ReleaseTraitsBox( String id, final ProductRelease release ) {
>         this( id, release, 0 );
>     }
>
>     public ReleaseTraitsBox( String id, final IHasTraits release, int
> foo ) {
>         super(id);
>
> Is there a better way?
> Wicket 1.5.
>
> Thanks,
> Ondra



-- 
Martin Grigorov
jWeekend
Training, Consulting, Development
http://jWeekend.com

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org