You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Arun Chauhan <ar...@gmail.com> on 2012/12/27 11:11:41 UTC

Wicket integration with Spring

I am making an application in which I want to integrate Wicket + Spring.
Application is a grocery store on which user comes and buy something. I know
there are two ways to do this.

1. Using the *annotation *aprroach. Wicket-Spring integration shows various
ways on how to inject Spring   Beans into Wicket pages.

public class FormPage extends WebPage
{
  @SpringBean
  private IContact icontact;
  ...
  Form form = new Form("contactForm",
     new CompoundPropertyModel(contact))
  {
    private static final long serialVersionUID = 1L;

    protected void onSubmit(Contact contact)
    {               
      icontact.saveContact(contact);
    }
  }; 


2. The @SpringBean is of course valid and considered a best practice by
many. But there is also *another approach*, where your Wicket Application
has the services you need.

public class YourWicketApp extends WebApplication{
  public static YourWicketApp get(){
    return (YourWicketApp) Application.get();
  }
  private ServiceA serviceA;
  // getter and setter for serviceA here
}

Now in your component, call

YourWicketApp.get().getServiceA();



I want to know which is the best way to integrate spring with wicket.


/However as far as I remember Wicket pages and components aren't managed by
Spring container so you cannot use @Transactional annotation on them (which
is a bad idea anyway - transactions belong to deeper levels)./ *Is this
statement valid?*



--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Wicket-integration-with-Spring-tp4655077.html
Sent from the Users forum 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: Wicket integration with Spring

Posted by Arun Chauhan <ar...@gmail.com>.
Thanks Martin. Now I will go for Annotation @SpringBean approach. 



--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Wicket-integration-with-Spring-tp4655077p4655084.html
Sent from the Users forum 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: Wicket integration with Spring

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

There is also
https://github.com/wicketstuff/core/tree/master/jdk-1.6-parent/wicketstuff-springreference-parent
 / https://github.com/wicketstuff/core/wiki/SpringReference



On Thu, Dec 27, 2012 at 12:11 PM, Arun Chauhan <ar...@gmail.com>wrote:

> I am making an application in which I want to integrate Wicket + Spring.
> Application is a grocery store on which user comes and buy something. I
> know
> there are two ways to do this.
>
> 1. Using the *annotation *aprroach. Wicket-Spring integration shows various
> ways on how to inject Spring   Beans into Wicket pages.
>
> public class FormPage extends WebPage
> {
>   @SpringBean
>   private IContact icontact;
>   ...
>   Form form = new Form("contactForm",
>      new CompoundPropertyModel(contact))
>   {
>     private static final long serialVersionUID = 1L;
>
>     protected void onSubmit(Contact contact)
>     {
>       icontact.saveContact(contact);
>     }
>   };
>
>
> 2. The @SpringBean is of course valid and considered a best practice by
> many. But there is also *another approach*, where your Wicket Application
> has the services you need.
>
> public class YourWicketApp extends WebApplication{
>   public static YourWicketApp get(){
>     return (YourWicketApp) Application.get();
>   }
>   private ServiceA serviceA;
>   // getter and setter for serviceA here
> }
>
> Now in your component, call
>
> YourWicketApp.get().getServiceA();
>
>
>
> I want to know which is the best way to integrate spring with wicket.
>

I prefer @SpringBean because with approach 2) you tie every component with
this specific implementation of WebApplication. So you cannot reuse this
component in another application, and your WicketTester tests will need to
setup the whole application to be able to run. With approach 1) you need
just to make ServiceA available for the test of a given component.


>
>
> /However as far as I remember Wicket pages and components aren't managed by
> Spring container so you cannot use @Transactional annotation on them (which
> is a bad idea anyway - transactions belong to deeper levels)./ *Is this
> statement valid?*
>

Yes. Better create a Spring bean that cares about the transactions.
Something like: WicketComponent uses ServiceBean delegatesTo RepositoryBean


>
>
>
> --
> View this message in context:
> http://apache-wicket.1842946.n4.nabble.com/Wicket-integration-with-Spring-tp4655077.html
> Sent from the Users forum 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
>
>


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

Re: Wicket integration with Spring

Posted by Per Newgro <pe...@gmx.ch>.
With the 2nd approach you couple the application (in the role as service 
mother) to all your calling components.
Coupling is a bad idea. It's hard to test in separation and almost 
always you end in a hell of small single methods.
But if you inject your beans into the target component you can define 
your required dependeny there were you use them.
Another cool approach in wicket is the event system in 1.5+. So you 
throw events in child components and provide the
services in high ranking components (page, app ...)

Just my 2 ct.

Per

Am 27.12.2012 11:11, schrieb Arun Chauhan:
> I am making an application in which I want to integrate Wicket + Spring.
> Application is a grocery store on which user comes and buy something. I know
> there are two ways to do this.
>
> 1. Using the *annotation *aprroach. Wicket-Spring integration shows various
> ways on how to inject Spring   Beans into Wicket pages.
>
> public class FormPage extends WebPage
> {
>    @SpringBean
>    private IContact icontact;
>    ...
>    Form form = new Form("contactForm",
>       new CompoundPropertyModel(contact))
>    {
>      private static final long serialVersionUID = 1L;
>
>      protected void onSubmit(Contact contact)
>      {
>        icontact.saveContact(contact);
>      }
>    };
>
>
> 2. The @SpringBean is of course valid and considered a best practice by
> many. But there is also *another approach*, where your Wicket Application
> has the services you need.
>
> public class YourWicketApp extends WebApplication{
>    public static YourWicketApp get(){
>      return (YourWicketApp) Application.get();
>    }
>    private ServiceA serviceA;
>    // getter and setter for serviceA here
> }
>
> Now in your component, call
>
> YourWicketApp.get().getServiceA();
>
>
>
> I want to know which is the best way to integrate spring with wicket.
>
>
> /However as far as I remember Wicket pages and components aren't managed by
> Spring container so you cannot use @Transactional annotation on them (which
> is a bad idea anyway - transactions belong to deeper levels)./ *Is this
> statement valid?*
>
>
>
> --
> View this message in context: http://apache-wicket.1842946.n4.nabble.com/Wicket-integration-with-Spring-tp4655077.html
> Sent from the Users forum 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