click-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Bob Schellink <sab...@gmail.com>
Subject Re: Click, Dependency Injection, and Annotations
Date Wed, 24 Apr 2013 11:22:14 GMT
Hi Dennis,

Isn't CDI part of J2EE not Servlets? If so CDI should be an optional extra
for those who are interested in it, similar to SpringServlet.

Easiest way to contribute is create a JIRA and attached a patch for the
changes that need to be made.

Kind regards

Bob

On 2013/04/23 19:40, Dennis M. J. Yerger wrote:

I don't know if anyone has dealt with this yet, but dependency injection is
a popular concept these days. Spring is the best example of such a
framework. Some of Click's online examples are even based on Spring.
However, Java EE has a new standard called Contexts and Dependency
Injection (CDI). This specification has less dependence on XML than a
typical Spring configuration. That means you can add your classes to your
project and CDI will automatically detect them at startup. Detected classes
can be filtered with qualifier annotations.

Page interceptors can be automatically registered with Click by using
standard CDI annotations such as ApplicationScoped. Consider the following
example:

@RequestScoped
public class TestInterceptor implements PageInterceptor {...}

I propose adding an extension to Click to support CDI technology. I have
already written working code to test this support, but I am not sure how to
submit it. Any help is appreciated.

On a separate but related subject, Click makes little use of annotations in
its configuration. The Bindable annotation makes request parameters easy to
work with, but there are other possible uses for annotations. They can also
be used for mapping a path to a page class. Consider the following example
based on my test code:

@PagePaths("test.htm")
public class TestPage extends Page {
}

This is a very simple example. As you can see, the name of the annotation
is PagePaths, implying that multiple paths can be mapped to the same class.
Page headers are another place where annotations would be useful. Click
should have a facility for detecting such annotations and including them in
the overall configuration.

Mime
View raw message