Monday, July 27, 2009

[vim] Send the output of a command straight into vim

Here is a pretty cool tip I learn from the Ubuntu groups on LinkedIn.

You are working with vim on a file and, for some reason, you need the output of a command (i.e. ls to get the list of files in folder).

1) First solution is to open a new shell and type 'ls', copy the result and paste it in the file that you are currently working on
2)You can use redirection by closing the file you are working on and type:

ls >> myfile.txt

3)This cool trick from vim (and vi).
Place your cursor where you want the output to be pasted
Type

:!r<command>

In our example, it will be

:!rls

and the result of the ls will be pasted where you have place the cursor.

Tip can be found here . You may need to join the Ubuntu group.

Sunday, July 19, 2009

[SpringMVC] Enabling annotation

The Spring MVC framework allows one to configure an application in 2 different ways :
- via a XML configuration file
- via annotations

I use the Netbeans IDE (6.7) for Spring development.
When you create a Spring MVC project, the template generated is using the XML configuration (to specify the mapping between URL patterns and Controllers)

To enable annotation:
-in ${project}-servlet.xml, remove/comment out the declarations regarding the
  • ControllerClassNameHandlerMapping
  • SimpleUrlHandlerMapping
  • ParameterizableViewController

-in the applicationContext.xml, add the following declarations:

*When declaring the <beans> root,
  • add the 'context' namespace declaration: xmlns:context="http://www.springframework.org/schema/context
  • Add the following to the xsi:schemaLocation:
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
*Add the below beans declarations:
<bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping" />
<
context:component-scan base-package="com.myapp"/>

From the documentation of Spring 2.5, DefaultAnnotationHandlerMapping is an
"implementation of the HandlerMapping interface that maps handlers based on HTTP paths expressed through the RequestMapping annotation at the type or method level. "

You will have to declare in your Java classes (POJO) a @RequestMapping which will represent an URL pattern.

The component-scan will tell Spring to scan the base-package for classes that have been annotated (@Controller, @RequestMapping...)

See more info on DefaultAnnotationHandlerMapping here