Aug 12

Almost every modern web application provides the data and functionality via a REST interface (usually in XML and / or JSON format).

Web frameworks (like Rails and Grails) that simplify the creation of such a REST interface, are enjoying great popularity among Web developers.
Since at least Grails web framework in the background on the Spring put on, can also developers, Grails does not use or may want, Spring this functionality in their application to integrate with.

concrete example is a tutorial and matching it by StSMedia . The basic REST integration is in part 2 explained in more detail. The implementation of the ContentNegotiation, ie the delivery of different formats because of the request (in the Accept header or by extending the URL to the file extension) is there in Part 7 .

The complete source code of the Spring Finance Manager application on Google Code hosted and is available for download there. The version 0.5 is based still on Spring 3 M4, I was able to use the REST functionality implemented there but also easily with Spring 3.0.2.

Links:
REST article in SpringSource Blog

Similar items:

posted by gklinkmann \ \ tags: ,

Nov 23
Groovy Logo

In my view, Groovy , the dynamic language for the Java Virtual Machine, the big hype curve at the point of technical reality arrived at. With Scala and Clojure programming languages instead of just the 2 new community of disciples driven by Java.

It is time again to question what one has even implemented until now with Groovy, whether one remains, or at least jumping on the train Scala.

Dierk König, author of "Groovy in Action" (the best technical book I've read lately), once the following 7 Groovy usage patterns for identified:

Super Glue, Liquid Heart, Keyhole Surgery, Smart Configuration, Unlimited Openness, House-Elf Scripts, Prototype

Or not as prosaic as:

  • Link between Java components (such as Spring and Hibernate in Grails)
  • Outsourcing of Buisiness logic, to adapt it dynamically to changes or
  • Possibility of intervention in current applications
  • Enlargement of the configuration with the means of a programming language (to finally get rid of the clumsy XML)
  • the slight change of code at runtime
  • Help for all tasks arising through the programming (build automation, continuous integration, deployment, installer, service monitoring, reports, statistics, automated documentation, functional tests, HTML scraping, web remote control, XML-RPC, WebServices)
  • Tool for rapid creation of prototypes, with the possibility that they can later port it to Java.

But back to the starting point. What to do with Groovy?

First of all, I write 95% of all new tests in Groovy. The syntax crisp, the perfect interoperability with Java and the good (but improvable) integration in Eclipse make the creation of tests is much less annoying. There are also smaller Web and Web services applications based on Grails (the Webframwork, which also is based on Groovy itself) and tools that are written in Groovy pure.

Ultimately, one can say that the hype is gone and the daily Groovy fits perfectly into the daily work. With Griffon and GPars are two other frameworks for Swing applications and Concurrent Programming (threads) at Groovy basis. And a vibrant community has formed around this dynamic language. A transition to Scala or closure for me is therefore not currently eligible.

And to be quite wedded, when the children ask, "Daddy what are you doing?", "Sounds groovy I program" much cooler than "I like programming Scala". :-)

Links:
Groovy Usage Patterns by Dierk König

Similar items:

posted by gklinkmann \ \ tags: , , , , , , , ,

Oct 11

The week before the holiday is always a bit stressful. Therefore, there are only two links:

Start in Spring RC2 Roo
Who can use Grails can not or will receive a code generator Roo with Spring for web applications based on Spring, and Java.
WordPress with Lucene
The Free Library Search keeps a plugin entry in WordPress.

Similar items:

posted by gklinkmann \ \ tags: , , , ,

Oct 03

Throughout the week, there are always interesting articles on the net for me, to me a bookmark on delicious.com are worth. Some of the impetus for a review in my own blog, but most of accumulated knowledge (we are all hunters and gatherers), which may be viewed.

This week we have made following article in my link list:

Inspiration: The best CSS and design galleries
A good layout is just as important as the technology behind it. Here are a few examples.
Image Flow by Finn Rudolph
A very nice implementation of Apple's Cover Flow for the web.
10 Useful Findings and Usability Guidelines
The Smashing Magazine has released some results of his study on the usability of web sites - very interesting.
Stylish Charts Using jQuery CSS and PHP
So far I have always created as image maps on the fly. The solution with PHP and jQuery is also an interesting approach.
Browser with PHP remote control
Nils Langner of phphatesme Blog explains how you can with selenium and PHP to remotely control the browser. Automated functional tests are already very long list of subjects for my blog. It is time for a post.
Grails 1.2: Spring 3, Uri Rewriting and more
Very good article about the upcoming Grails 1.2 Release.

Similar items:

posted by gklinkmann \ \ tags: , , , , , ,

Oct 01
spring-icon

Since yesterday is the first release candidate of Spring Framework to download ready.
In this version of Java will be the first time, the JSR-303 (Bean Validation) and JSR-330 (Dependency Injection in support). can particularly on the implementation of the Bean Validation I was curious, as this one provided on his Annotations Beans with Constraints.

In a Spring based Web applications could make use of the Bean Validation as follows.

1st Blame the bean

  1
 2
 3
 4
 5
 6
 7
 { int id ; @NotNull @Size ( min = 1 ,max = 50 ) String description ; ... public class Event (int id; @ NotNull @ Size (min = 1, max = 50) String description; ... 

the two annotations (in validation-api-1.0.CR3.jar contained by) determines that the value for the attribute description may not be zero and a minimum number but up to 50 characters must contain.

2nd validate the bean within the controller

For validation, one needs an implementation of JSR-303, such as the Hibernate Validator (currently in version 4.0.0 CR1). He has, however, a lot of dependencies on Maven and must be compiled to.
Once you overcome this hurdle (and has integrated the resulting jar file in its project), you need the following libraries still not a runtime error produced:

  • validation-api-1.0.CR3.jar
  • slf4j-api-1.5.6.jar
  • slf4j-1.5.6.jar-log4j12
  • log4j-1.2.14.jar
  • commons-logging-1.0.4.jar (you need not necessarily, but was used in the example)

these are but anyway before the local Maven repository.

  1
 2
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
  "/event/save" , method = RequestMethod. POST ) @ Request Mapping (value = "/ event / save" method = Request Method. POST)
 save ( Event event,BindingResult bindingResult, Model model ) { public String save (Event event, BindingResult bindingResult, Model model) (
    LocalValidatorFactoryBean ( ) ; LocalValidatorFactoryBean validator = new LocalValidatorFactoryBean ();
    HibernateValidationProvider. class ) ; validator. setProviderClass (HibernateValidationProvider. class);
    ; validator. afterPropertiesSet ();

    event,bindingResult ) ; validator. validate event (bindingResult);

    ! bindingResult. hasErrors ( ) ) { if (! bindingResult. hasErrors ()) (
       / / Save ...
       "message" , "update successfully" ) ; model. addAttribute ("message", "update successfully");         
    { ) Else (
       FieldError e : bindingResult. getFieldErrors ( ) ) { for (Field Error e bindingResult. getFieldErrors ()) (
          e. getField ( ) + ": " + e. getDefaultMessage ( ) ) ; log. warn (e. getField () + ":" + e. getDefaultMessage ());            
       )
       "errors" , bindingResult. getFieldErrors ( ) ) ; model. addAttribute ("errors", bindingResult. getFieldErrors ());
    )
    "event" , event ) ; model. addAttribute ("event", event);

    ; return "update";
 ) 

In lines 3-5 an instance of the Hibernate Validator is created. In line 7 is then validated at last. Whether validation error occurred are in the can with the method hasErrors() check (line 9). Access to all the errors (eg for logging) to get on the method getFieldErrors() (lines 13-15).
In line 16 to pass the mistakes of the View.

3rd Output of error in the View

For output, the error is the JSP Standard Tag Library used.

  1
 2
 3
 4
 5
 6
 7
 8
  <p> $ (message) </ p>
 <c:if test="${!empty errors}">
    <ul>
    <c:forEach var="error" items="${errors}">
       <li> error.field $ (): $ (error.defaultMessage) </ li>         
    </ C:> forEach
    </ Ul>
 </ C: if> 

Similar items:

posted by gklinkmann \ \ tags: , ,