Spring MVC or Wicket?
Asked Answered
O

4

13

I have a long (and happy so far) experience with Spring MVC, but lately I'm getting interested in Wicket.

My question is also on how to handle (with Wicket) DI, Transaction Mgmt, JDBC connections and all that stuff? Is it okay to mix certain parts of the Springsource suite with Wicket? Wicket & Weld? Wicket & Guice?

Ontine answered 29/2, 2012 at 21:51 Comment(4)
I should have added the ability to test your stuff (i find SpringJUnit4ClassRunner very very useful for testing spring controllers)Ontine
Wicket has some basic support for testing as well. It is easy to test UI pages (or parts thereof) via unit tests. As long as you dont want to test Ajax functionsVisionary
Ajax behaviors is also covered by WicketTester. Testing of plain JavaScript is not part of Wicket's business.Swanky
As tetsuo and Tomasz point out, you can use both. Personally I've been quite happy using Spring for database connection, DAO and service layer, and Wicket for UI. It's possible to have a reasonably clean architecture this way.Diffraction
D
19

Wicket is a presentation-layer framework. It will not handle DI, transactions or connections.

But it can be easily integrated with a number of frameworks, including Spring, Guice (official Wicket modules, wicket-spring and wicket-guice) and CDI/Weld (wicket-cdi, a side project from Igor Vaynberg, one of the Wicket committers).

Wicket Wiki: Integration guides

Below, a simple Wicket application with Spring. The transaction bits are plain old Spring configuration, so I didn't bother including them.

HelloWorldService.java

public class HelloWorldService {
    private String message;
    public void setMessage(String message) {
        this.message = message;
    }
    public String getMessage() {
        return message;
    }
}

applicationContext.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd">

  <bean id="helloWorldService" class="minimal.wicketspring.HelloWorldService">
    <property name="message" value="Hello, World!" />
  </bean>
</beans>

WicketApplication.java

public class WicketApplication extends WebApplication {
    @Override
    public void init() {
        super.init();
        getComponentInstantiationListeners().add(new SpringComponentInjector(this));
    }
    @Override
    public Class<HomePage> getHomePage() {
        return HomePage.class;
    }
}

HomePage.java

public class HomePage extends WebPage {
    @SpringBean
    private HelloWorldService helloWorldService;

    public HomePage() {
        add(new FeedbackPanel("feedback"));
        add(new Link<Void>("link") {
            @Override
            public void onClick() {
                info(helloWorldService.getMessage());
            }
        });
    }
}

HomePage.html

<!DOCTYPE html>
<html xmlns:wicket="http://wicket.apache.org">
<body>
  <div wicket:id="feedback"></div>
  <a wicket:id="link">Show Message</a>
</body>
</html>

web.xml

<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5">

  <listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>

  <filter>
    <filter-name>wicket.wicket-spring</filter-name>
    <filter-class>org.apache.wicket.protocol.http.WicketFilter</filter-class>
    <init-param>
      <param-name>applicationClassName</param-name>
      <param-value>minimal.wicketspring.WicketApplication</param-value>
    </init-param>
  </filter>

  <filter-mapping>
    <filter-name>wicket.wicket-spring</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>
</web-app>
Derzon answered 1/3, 2012 at 17:43 Comment(0)
K
14

Wicket effectively replaces Spring MVC, but not the Spring container itself. Wicket integrates easily with Spring via @SpringBean annotation which allows you to inject Spring beans (services, DAOs, etc.) directly to pages. You cannot perform DI the other way around - for a good reason.

It is a smart choice to use Spring and Wicket together. 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).

Everything else works exactly the same - AOP, JDBC, etc.

Kathie answered 29/2, 2012 at 22:0 Comment(1)
Actually, you can use @Transactional on Wicket components' methods, if you use AspectJ+@Configurable. But I'm not sure if I'd recommend using it, though.Derzon
A
8

I would recommend to leave Spring entirely and try the Java EE 6 + Wicket 6.x. I was using Spring MVC, then Spring + Wicket in the days of Java EE 5 but Java EE 6 as the middleware layer simply beats Spring solutions.

Update 2017: With the new goodies in Java 7 and 8 (lambdas, method refereces, default interface method implementations, ...), the Java EE 7 + Wicket 8 combo is even more appealing. Although Spring MVC is quite popular and might have better learning curve, once you try Wicket you'll miss it when you get to the "next cool thing" (Angular2 in my case).

Note: I am paid by Red Hat, but the above is my honest opinion. In 2011, I'd tell you to go with Spring.

Autry answered 6/3, 2013 at 18:46 Comment(0)
B
0

Just forget on wickets. Simple spring MVC, Twitter bootstrap layout and whole spring portfolio let you create scalable and top high performance applications, with top security. Wickets is pain as soon as you go behind your first impress and start real development.

http://www.slideshare.net/mraible/comparing-jvm-web-frameworks-february-2014 hope thi help make decision for me this presentation was realy helpfull.

Bogart answered 24/8, 2015 at 7:31 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.