You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by thomas jaeckle <ma...@gmail.com> on 2007/11/20 16:45:14 UTC

Problems with spring to manage all webpages

Hi everyone.
I am trying to manage all of my WebPages via spring. 
Every page is derived from "AbstractIndex" which contains the Border (the
page layout: header, navigation):

public abstract class AbstractIndex extends WebPage {
  @SpringBean
  protected Border border;

  AbstractIndex(PageParameters parameters) {
    super(parameters);
    
    assert border!=null : "border is NULL";
    border.setTransparentResolver(true);
    add(border);
  }
...
}

And an example page:

public class PortalPage extends AbstractIndex {
  public PortalPage(PageParameters parameters) {
    super(parameters);
    ...
  }
...
}

In WicketApplication I have to set the homePage:

public class WicketApplication extends SpringWebApplication {
  public Class getHomePage() {
    return PortalPage.class;
  }
}


Now the problem: I have to initialize all pages lazy (lazy-init="true") in
the Spring applicationContext, because they can be initialized only when
WicketApplication is running already in the main-thread.
But now in WicketApplication the homePage ist set - and the "PortalPage" (in
this case) has not yet been initialized, so the AssertionError (assert
border!=null : "border is NULL";) from "AbstractIndex" is thrown.

It is a chicken-egg-problem ... at least I think so.
Does someone have an idea how to solve this? 


regards
Thomas
-- 
View this message in context: http://www.nabble.com/Problems-with-spring-to-manage-all-webpages-tf4844256.html#a13859451
Sent from the Wicket - User mailing list archive at Nabble.com.


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


Re: Problems with spring to manage all webpages

Posted by Al Maw <wi...@almaw.com>.
thomas jaeckle wrote:
> 
> 
> igor.vaynberg wrote:
>> make that bean a prototype?
>>
> Hm, I don't see the benefit of this. The problem remains:
> I can't initialize the pages before the WebApplication is initialized (in
> this case I would become a "There is no application attached to current
> thread main" Exception). But when I initialize them lazy, they don't get
> their attributes injected before Wicket displays the homePage ...

I'd stop right now and think more carefully about what you're doing if I 
were you. You need a better understanding of why page instances are 
created in Wicket and why.

It's important to realise that Wicket doesn't currently have a 
PageFactory type thing - instead we effectively just go 
getHomePage.newInstance() when the user lands on the home page URL.

Therefore, at the moment, you cannot get Spring to manage all your pages 
for you.

What's more, you probably don't want to, as this would introduce 
serialization issues with things like DAO beans, which is specifically 
why wicket-ioc and wicket-spring/wicket-spring-annot exist in the first 
place.

Pages are not singletons - they are specific instances created due to 
hitting a bookmarkable URL or whatever. You don't want to be sharing 
your Wicket Components (e.g. your Border) across pages, so those 
shouldn't be singletons either.

Regards,

Al

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


Re: Problems with spring to manage all webpages

Posted by thomas jaeckle <ma...@gmail.com>.


igor.vaynberg wrote:
> 
> make that bean a prototype?
> 
Hm, I don't see the benefit of this. The problem remains:
I can't initialize the pages before the WebApplication is initialized (in
this case I would become a "There is no application attached to current
thread main" Exception). But when I initialize them lazy, they don't get
their attributes injected before Wicket displays the homePage ...
-- 
View this message in context: http://www.nabble.com/Problems-with-spring-to-manage-all-webpages-tf4844256.html#a13873117
Sent from the Wicket - User mailing list archive at Nabble.com.


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


Re: Problems with spring to manage all webpages

Posted by Igor Vaynberg <ig...@gmail.com>.
make that bean a prototype?

-igor


On Nov 20, 2007 7:45 AM, thomas jaeckle <ma...@gmail.com> wrote:
>
> Hi everyone.
> I am trying to manage all of my WebPages via spring.
> Every page is derived from "AbstractIndex" which contains the Border (the
> page layout: header, navigation):
>
> public abstract class AbstractIndex extends WebPage {
>   @SpringBean
>   protected Border border;
>
>   AbstractIndex(PageParameters parameters) {
>     super(parameters);
>
>     assert border!=null : "border is NULL";
>     border.setTransparentResolver(true);
>     add(border);
>   }
> ...
> }
>
> And an example page:
>
> public class PortalPage extends AbstractIndex {
>   public PortalPage(PageParameters parameters) {
>     super(parameters);
>     ...
>   }
> ...
> }
>
> In WicketApplication I have to set the homePage:
>
> public class WicketApplication extends SpringWebApplication {
>   public Class getHomePage() {
>     return PortalPage.class;
>   }
> }
>
>
> Now the problem: I have to initialize all pages lazy (lazy-init="true") in
> the Spring applicationContext, because they can be initialized only when
> WicketApplication is running already in the main-thread.
> But now in WicketApplication the homePage ist set - and the "PortalPage" (in
> this case) has not yet been initialized, so the AssertionError (assert
> border!=null : "border is NULL";) from "AbstractIndex" is thrown.
>
> It is a chicken-egg-problem ... at least I think so.
> Does someone have an idea how to solve this?
>
>
> regards
> Thomas
> --
> View this message in context: http://www.nabble.com/Problems-with-spring-to-manage-all-webpages-tf4844256.html#a13859451
> Sent from the Wicket - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

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


Re: Problems with spring to manage all webpages

Posted by Timo Rantalaiho <Ti...@ri.fi>.
On Tue, 20 Nov 2007, thomas jaeckle wrote:
> The benefit would be that inhertitance and reusability is much easier to
> manage.
> If I go with straight Java, I have to create lots of more classes and the
> code becomes uglier.

Concrete examples would be interesting, as most of us prefer
the Wicket way of programming in Java rather than in XML :)

Best wishes,
Timo


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


Re: Problems with spring to manage all webpages

Posted by thomas jaeckle <ma...@gmail.com>.

Timo Rantalaiho wrote:
> 
> Why are you trying to make Spring create your component
> instances? What benefit would that give?
> 
The benefit would be that inhertitance and reusability is much easier to
manage.
If I go with straight Java, I have to create lots of more classes and the
code becomes uglier.

I came so far with Spring and wicket now that I can't believe that it isn't
possible ...
-- 
View this message in context: http://www.nabble.com/Problems-with-spring-to-manage-all-webpages-tf4844256.html#a13864455
Sent from the Wicket - User mailing list archive at Nabble.com.


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


Re: Problems with spring to manage all webpages

Posted by Timo Rantalaiho <Ti...@ri.fi>.
On Tue, 20 Nov 2007, thomas jaeckle wrote:
> I am trying to manage all of my WebPages via spring. 

I think that this is the problem :) Wicket is by its very 
nature an unmanaged framework, where the developer is in 
control of creating new component instances.

Why are you trying to make Spring create your component
instances? What benefit would that give?

Best wishes,
Timo


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