Dashboard > People > Uwe Schaefer > Browse Space > News Items for
  codesmell Log In   View a printable version of the current page.  
  News Items for Okt 03, 2007
  2007/10/03
Last changed: Okt 03, 2007 19:24 by Uwe Schaefer
Labels: wicket, java, web, guice, dependency-injection

You know Wicket, at least, you´ve heard of it. What you might have missed, is that it integrates with Guice quite well through this project.
I´ve tried it and it´s marvellous. Consider this:

SomeForm.java
public final class SomeForm extends Form
{
        public SomeForm(final String componentName)
        {
            super(componentName);
            add(new FeedbackPanel("feedback"));
            [... populate form ...]
        }

	// this is where it gets guicy:
	
        @Inject
        private AuditService auditService;

        @Override
        public final void onSubmit()
        {
           auditService.doSomeAuditing(...);
           doSomethingImportant();
        }
        
        [...]
}

The beauty of this is the fact, is that this still works with Serialized forms (of course) and that together with Maven, you have a really good setting for prototyping with Wicket.
Just create your Wicket project, start prototyping your wicket GUI using mvn jetty:run and create/modify Service-interfaces as needed accompanied by Prototype-Implementations (aka NOP-Impls ).
You can later implement your Services for real and just plug them in by switching the Guice-Module:

AbstractWebApplication.java
public abstract class AbstractWebApplication extends WebApplication
{
    
    	@Override
    	protected void init()
    	{
	        super.init();
        	addComponentInstantiationListener(
			new GuiceComponentInjector(this,getModule());
    	} 

	private Module getModule()
	{
	        return isPrototyping() ? 
			getPrototypingModule() : getRuntimeModule();
	}
	
	protected Module getPrototypingModule()
    	{
        	return new Module()
        	{
                	public void configure(final Binder binder)
            		{
                		binder.bind(AuditService.class).
					toInstance(new AuditingServicePrototype());
                		[...]
            		}
        	};
        	// you get the idea.
    	}
}

Lightweight prototyping - Dependencies injected - no XML plus Guice-Scopes are available to give you further flexibility of Object creation.

I love it!

Posted at 03 Okt @ 6:38 PM by Uwe Schaefer | 2 comments

Oktober 2007
Sun Mon Tue Wed Thu Fri Sat
  1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31      

Okt 20, 2007
Sep 16, 2007

This site is powered by a free Atlassian Confluence Personal Server License. Evaluate Confluence for your organisation or read more about Confluence licensing here.
Powered by Atlassian Confluence, the Enterprise Wiki. (Version: 2.2.9 Build:#527 Sep 07, 2006) - Bug/feature request - Contact Administrators