Our Blog

Let us find tech solutions together

Jul 20

Wicket and Spring

By kinabalu | Comments

Wicket makes it very easy to integrate directly with the Spring Framework.

In any Component (Page, Panel, etc) to include a Spring bean you would do:

1
2
    @SpringBean
    private MyBean myBean;

In your application-specific Application class you would do the following:

1
2
3
4
5
6
7
8
9
import org.apache.wicket.spring.injection.annot.SpringComponentInjector;

...

   @Override
    protected void init {
        addComponentInstantiationListener(new SpringComponentInjector(this));
        ...
    }

If you’re using Maven for your build management, you would pull in these dependencies assuming wicket 1.3:

1
2
3
4
5
6
7
8
9
10
11
        <dependency>
            <groupId>org.apache.wicket</groupId>
            <artifactId>wicket-spring</artifactId>
            <version>${wicket.version}</version>
        </dependency>

        <dependency>
            <groupId>org.apache.wicket</groupId>
            <artifactId>wicket-spring-annot</artifactId>
            <version>${wicket.version}</version>
        </dependency>
Read more
Jul 19

In Apache Wicket, the framework expects the HTML templates to mirror the class-file directory structure. The example below allows you to define a different path for your HTML files.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
public class PathStripperLocator extends ResourceStreamLocator {

    public PathStripperLocator() {
    }

    public IResourceStream locate(final Class clazz, final String path) {
        IResourceStream located = super.locate(clazz, trimFolders(path));
        if (located != null) {
            return located;
        }
        return super.locate(clazz, path);
    }

    private String trimFolders(String path) {
        return path.substring(path.lastIndexOf("/") + 1);
    }
}
1
2
3
4
5
6
7
8
public class MyApplication extends AuthDataApplication {
    @Override
    protected void init() {
        super.init();
        IResourceSettings resourceSettings = getResourceSettings();
        resourceSettings.addResourceFolder("src/main/webapp"); //this path should be changed
        resourceSettings.setResourceStreamLocator(new PathStripperLocator());
    }

(via wicket wiki)

Read more
Jul 19

A long running process that you’d like to show some indicator of progress or similar, usually means an indicator of some kind. Here we use an IndicatingAjaxButton to show some progress near the clicked submit button, and we use an IAjaxCallDecorator to disable the submit button so we don’t get multiple clicks

1
2
3
4
5
6
7
8
9
10
11
12
13
14
form.add(new IndicatingAjaxButton("submit", form) {

    @Override
    protected IAjaxCallDecorator getAjaxCallDecorator() {
        return new AjaxPostprocessingCallDecorator(super.getAjaxCallDecorator()) {
            private static final long serialVersionUID = 1L;

            @Override
            public CharSequence postDecorateScript(CharSequence script) {
                return script + "this.disabled = true;";
            }
        };
    }
}
Read more