[jboss-user] [JBoss Tools] - Overview of Context Dependency Injection Tools

Alexey Kazakov do-not-reply at jboss.com
Mon Jan 31 03:18:27 EST 2011

Alexey Kazakov [http://community.jboss.org/people/akazakov] modified the blog post:

"Overview of Context Dependency Injection Tools"

To view the blog post, visit: http://community.jboss.org/community/tools/blog/2011/01/31/overview-of-context-dependency-injection-tools

The very first version of Context Dependency Injection (CDI) Tools was introduced as a part of JBoss Tools 3.1.0. But now JBoss Tools 3.2 is moving to its first stable release. Let's have some review of main features of the improved and up coming CDI Tools in JBoss Tools 3.2.
h3. *Enabling CDI support*
First at all we need to enable CDI support for the project. If you already have some CDI project and don't want to start from scratch then just go to+Project Properties->CDI->CDI support+ to enable all the features.

 http://community.jboss.org/servlet/JiveServlet/showImage/38-3559-11251/00enableCDI.png  http://community.jboss.org/servlet/JiveServlet/downloadImage/38-3559-11251/450-340/00enableCDI.png 

If your project is Maven-based and the pom.xml references the CDI api jars CDI support will be enabled automatically. If you want to create a brand new WTP project with CDI support, just add a CDI facet to the list of installing facets.

See Max's blog  http://community.jboss.org/community/tools/blog/2010/12/10/simple-cdi-hello-world-in-eclipse Simple CDI Hello World with Eclipse and JBoss Tools for details.

Make sure you have CDI support enabled for all the related projects. For instance if you have a web project (is to deployed as WAR) which uses some Java project (JAR) then both projects should have CDI support enabled.

If you are interested in Weld examples (Weld is the reference implementation of CDI spec.) you can download it from JBoss Tools example site.+Help->Project Examples->Weld 1.0.1+
 +http://community.jboss.org/servlet/JiveServlet/showImage/38-3559-11252/01examples.png  http://community.jboss.org/servlet/JiveServlet/downloadImage/38-3559-11252/421-600/01examples.png 

h3. *CDI Wizards*

There are a set of CDI Wizards to help you to create basic CDI artifacts. The wizards are available in +File->New->Other...->CDI+
 http://community.jboss.org/servlet/JiveServlet/showImage/38-3559-11253/02wizards.png  http://community.jboss.org/servlet/JiveServlet/downloadImage/38-3559-11253/450-436/02wizards.png 

 http://community.jboss.org/servlet/JiveServlet/showImage/38-3559-11254/03newStereotype.png  http://community.jboss.org/servlet/JiveServlet/downloadImage/38-3559-11254/450-486/03newStereotype.png 

h3. *CDI validation*

CDI validation covers most of the rules declared in the JSR-299 specification. There are 100+ validation rules including definition errors and deployment problems. You can see the full list in the CDI Preferences, where you can also control which rules you want to be Errors, Warnings or simply Ignored.

 *http://community.jboss.org/servlet/JiveServlet/showImage/38-3559-11255/04validation.png  http://community.jboss.org/servlet/JiveServlet/downloadImage/38-3559-11255/450-434/04validation.png 

The CDI validator checks for problems in java source files, JSP, XHTML and beans.xml files.
Some of the validation problems can be fixed via Quick Fixes menu (Ctrl+1):

 http://community.jboss.org/servlet/JiveServlet/showImage/38-3559-11256/05nonBusinessProducer.png  http://community.jboss.org/servlet/JiveServlet/downloadImage/38-3559-11256/450-160/05nonBusinessProducer.png 
h3. *Code completion*

Another useful feature is a code completion. CDI tools provides two types of code completion. Code completion for @Named beans and their members which are available in EL expressions:

 http://community.jboss.org/servlet/JiveServlet/showImage/38-3559-11257/06elca.png  http://community.jboss.org/servlet/JiveServlet/downloadImage/38-3559-11257/450-228/06elca.png 

And code completion for the relevant types/annotations in beans.xml:

 http://community.jboss.org/servlet/JiveServlet/showImage/38-3559-11258/07beansXmlCA.gif  http://community.jboss.org/servlet/JiveServlet/downloadImage/38-3559-11258/450-280/07beansXmlCA.gif 

h3. *Hyperlinks (OpenOns)*

Hyperlinks help you to navigate between source files. For example Ctrl+Click or F3 on any EL will navigate you to the corresponding java source.

For Injection's it is a bit more tricky. The built-in Java hyperlink for its declared type will open the type. But for Injection there are additional relevant items to navigate to. CDI Tools offers you an alternative navigation to the actual bean which is to be injected.

 http://community.jboss.org/servlet/JiveServlet/showImage/38-3559-11259/08openOnInj.png  http://community.jboss.org/servlet/JiveServlet/downloadImage/38-3559-11259/450-196/08openOnInj.png 

If  the injection has multiple eligible beans, you can see a full list of these beans. Btw. you can fix the multiple eligible beans via a quick-fix (Ctrl+1).

 http://community.jboss.org/servlet/JiveServlet/showImage/38-3559-11260/09openOnsInj.png  http://community.jboss.org/servlet/JiveServlet/downloadImage/38-3559-11260/450-203/09openOnsInj.png 

Also you can open the corresponding class/interface mentioned in beans.xml via the same Ctrl+Click on the type name.
Observers and Events can be navigated to via OpenOn too.

 http://community.jboss.org/servlet/JiveServlet/showImage/38-3559-11261/10eventOpenons.png  http://community.jboss.org/servlet/JiveServlet/downloadImage/38-3559-11261/450-103/10eventOpenons.png 
 http://community.jboss.org/servlet/JiveServlet/showImage/38-3559-11262/11observerOpenOns.png  http://community.jboss.org/servlet/JiveServlet/downloadImage/38-3559-11262/450-159/11observerOpenOns.png 

As well as Producer and Disposer methods:

 http://community.jboss.org/servlet/JiveServlet/showImage/38-3559-11263/12producerOpenOn.png  http://community.jboss.org/servlet/JiveServlet/downloadImage/38-3559-11263/413-122/12producerOpenOn.png 

 http://community.jboss.org/servlet/JiveServlet/showImage/38-3559-11264/13disposerOpenOn.png  http://community.jboss.org/servlet/JiveServlet/downloadImage/38-3559-11264/450-127/13disposerOpenOn.png 

At last we also have:

* EL refactoring. For example if your name the method/field or class name of some bean using Java refactoring dialogs CDI Tools will offer you to update all the EL expressions that use this method/field/type.
* Related CDI Beans are added in search result for field/method references search. See  http://screencast.com/t/NGUxOTA5YmQt demo movie.

h3. Feedback
This was a quick overview of the main features of up coming JBoss Tools 3.2 for CDI developers.

If you think CDI Tools misses some useful functionality then please create a feature request in  https://issues.jboss.org/browse/JBIDE JIRA! We are working to help you to enjoy this exciting world of CDI  :)

Comment by going to Community

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/jboss-user/attachments/20110131/6228b26d/attachment-0001.html 

More information about the jboss-user mailing list