Skip to content

Commit

Permalink
Merge branch 'release/0.2.4'
Browse files Browse the repository at this point in the history
  • Loading branch information
jeslopalo committed Oct 29, 2016
2 parents fa410f0 + 82ef459 commit ee27a2d
Show file tree
Hide file tree
Showing 19 changed files with 71 additions and 200 deletions.
7 changes: 6 additions & 1 deletion .codeclimate.yml
Expand Up @@ -6,7 +6,12 @@ engines:
checks:
com.puppycrawl.tools.checkstyle.checks.sizes.LineLengthCheck:
enabled: false

com.puppycrawl.tools.checkstyle.checks.javadoc.SummaryJavadocCheck:
enabled: false
com.puppycrawl.tools.checkstyle.checks.javadoc.NonEmptyAtclauseDescriptionCheck:
enabled: false
com.puppycrawl.tools.checkstyle.checks.imports.CustomImportOrderCheck:
enabled: false
pmd:
enabled: true
channel: "beta"
Expand Down
10 changes: 10 additions & 0 deletions CHANGELOG.md
@@ -1,3 +1,12 @@
### v0.2.4 (2016-10-29) - Fix some codeclimate issues

* [faded8e] Remove usage of wildcards in imports
* [f31f4bc] Fix codeclimate issues
* [0d7958a] Deactivate some codeclimate checks
* [249b200] Remove documentation duplication between README.md and sandbox.es
* [32fc0d9] Bump version to 0.2.4


### v0.2.3 (2016-10-29) - Fix some codeclimate issues

* [ad29b01] Fix cobertura.sh issues
Expand All @@ -12,6 +21,7 @@
* [b6064ba] Fix codeclimate issues
* [750f5d1] Disable a codeclimate check
* [15dae76] Bump version to 0.2.3
* [368f9da] Update CHANGELOG.md with 0.2.3 changes


### vv0.2.2 (2016-10-17) - Switch off doclint with java8
Expand Down
181 changes: 2 additions & 179 deletions README.md
Expand Up @@ -11,185 +11,8 @@ _An easy way to send & show *flash messages*_
|Coverity Scan |[![Coverity Scan Build Status](https://scan.coverity.com/projects/2142/badge.svg?branch=master)](https://scan.coverity.com/projects/2142?branch=master)|
|Code climate|[![Code Climate](https://codeclimate.com/github/jeslopalo/flash-messages/badges/gpa.svg)](https://codeclimate.com/github/jeslopalo/flash-messages)<br/>[![Test Coverage](https://codeclimate.com/github/jeslopalo/flash-messages/badges/coverage.svg)](https://codeclimate.com/github/jeslopalo/flash-messages/coverage)<br/>[![Issue Count](https://codeclimate.com/github/jeslopalo/flash-messages/badges/issue_count.svg)](https://codeclimate.com/github/jeslopalo/flash-messages)|

## Flash!

When applying the [Post/Redirect/Get](http://kcy.me/15fxw) pattern in web application development, I run always into the same problem: __how to communicate the result to the user after the redirection__.

While it is a known problem and it has been resolved in other platforms (like Ruby), Java does not seem to provide a simple and elegant solution.

*flash-messages* is an easy way to communicate flash messages after a redirection in Java web applications.

Today, you can use *flash-messages* in applications which use **spring-mvc** as web framework and **Jstl** to render views.

In future releases, it will be possible to use it in **JavaEE** applications and possibly with another view technologies like **Thymeleaf** or **Freemarker**.

Let's start!

## Features

- Seamless integration with ```@RequestMapping``` and ```@ExceptionHandler``` methods in the **spring-mvc** framework ```@Controller```'s
- Different levels of messages (ie. __SUCCESS__, __INFO__, __WARNING__, __ERROR__)
- Resolution of __i18n__ messages with arguments
- Resolution of __i18n__ arguments (ie Text, Link)
- Easy integration with the **Twitter Bootstrap** alerts

## Getting started

### Get it into your project

#### Maven

##### Bill Of Materials (BOM)

*flash-messages* artifacts are in **Maven Central** and includes a BOM ([Bill Of Materials](http://kcy.me/15g1b)) to facilitate the use of its modules.

```xml
<dependencyManagement>
<dependencies>
<dependency>
<groupId>es.sandbox.ui.messages</groupId>
<artifactId>flash-messages-bom</artifactId>
<version>0.2.2</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
```

##### Artifacts

After importing the *BOM* in your `pom.xml` you can easily declare the modules.

```xml
<dependencies>
...
<dependency>
<groupId>es.sandbox.ui.messages</groupId>
<artifactId>flash-messages-core</artifactId>
</dependency>
<dependency>
<groupId>es.sandbox.ui.messages</groupId>
<artifactId>flash-messages-spring</artifactId>
</dependency>
<dependency>
<groupId>es.sandbox.ui.messages</groupId>
<artifactId>flash-messages-taglibs</artifactId>
</dependency>
...
</dependencies>
```

#### Download

You can download the latest version directly from GitHub:

- `flash-messages-core` **(_[0.2.2](https://repo1.maven.org/maven2/es/sandbox/ui/messages/flash-messages-core/0.2.2/flash-messages-core-0.2.2.jar)_)**
- `flash-messages-spring` **(_[0.2.2](https://repo1.maven.org/maven2/es/sandbox/ui/messages/flash-messages-spring/0.2.2/flash-messages-spring-0.2.2.jar)_)**
- `flash-messages-taglibs` **(_[0.2.2](https://repo1.maven.org/maven2/es/sandbox/ui/messages/flash-messages-taglibs/0.2.2/flash-messages-taglibs-0.2.2.jar)_)**

#### Building from sources

You can build the latest version directly from source. Just run:

```sh
$ mkdir flash-messages-repository
$ cd flash-messages-repository
$ git clone https://github.com/jeslopalo/flash-messages.git
$ cd flash-messages
$ mvn clean package
```

### Configuration

*flash-messages* is configured using **spring** [JavaConfig](http://kcy.me/15fuu). It has been tested with versions greater or equal than **3.2.6.RELEASE**.

#### Default configuration

In order to obtain the default configuration, just add ```@EnableFlashMessages``` to a ```@Configuration``` class (the same with ```@EnableWebMvc``` should be enough).

```java
import es.sandbox.ui.messages.spring.config.annotation.EnableFlashMessages;

@Configuration
@EnableFlashMessages
@EnableWebMvc
public class WebMvcConfigurer {
...
@Bean
public MessageSource messageSource() {
ReloadableResourceBundleMessageSource messageSource= new ReloadableResourceBundleMessageSource();
messageSource.setBasenames("WEB-INF/i18n/messages");
return messageSource;
}
...
}
```

#### Custom configuration

To modify the default behavior of *flash-messages* just extend ```FlashMessagesConfigurerAdapter``` and override those methods that you want to customize.

```java
import es.sandbox.ui.messages.Level;
import es.sandbox.ui.messages.CssClassesByLevel;
import es.sandbox.ui.messages.spring.config.annotation.EnableFlashMessages;
import es.sandbox.ui.messages.spring.config.annotation.FlashMessagesConfigurerAdapter;

@Configuration
@EnableFlashMessages
public class CustomFlashMessagesConfigurer extends FlashMessagesConfigurerAdapter {

/**
* Sets the styles of flash-messages to be compatible
* with twitter bootstrap alerts
*/
@Override
public void configureCssClassesByLevel(CssClassesByLevel cssClasses) {
cssClasses.put(Level.ERROR, "alert alert-danger");
}
}
```

The main elements that can be configured or customized are: _levels of messages_, the _css classes applied to the levels_, the _strategy to resolve i18n messages_ or _modify the scope where messages are stored_.

### Writing messages

In order to write messages, just declare an argument of type ```Flash``` in the handler method (or in a ```@ExceptionHandler``` method), then you can add messages to the different levels.

```java
@RequestMapping(value="/target", method= RequestMethod.POST)
String post(Flash flash, @ModelAttribute FormBackingBean form, BindingResult bindingResult) {
if (bindingResult.hasErrors()) {
return "form";
}

Result result= this.service.doSomething(form.getValue());
if (result.isSuccessful()) {
flash.success("messages.success-after-post", result.getValue());
return "redirect:/successful-target-after-post";
}

flash.error("messages.error-in-service", form.getValue());
return "redirect:/error-target-after-post";
}

@ExceptionHandler(ServiceException.class)
String handle(ServiceException exception, Flash flash) {
flash.error("messages.service-exception");
return "somewhere";
}
```

### Painting messages

Finally, you must to include the ```<flash:messages />``` taglib in your views (or better in your decorator template).

```jsp
<%@ taglib prefix="flash" uri="http://sandbox.es/tags/flash-messages" %>
...
<flash:messages />
...
### Documentation

```
You can find the documentation in [http://sandbox.es/projects/flash-messages/](http://sandbox.es/projects/flash-messages/).
2 changes: 1 addition & 1 deletion flash-messages-bom/pom.xml
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>es.sandbox.ui.messages</groupId>
<artifactId>flash-messages-parent</artifactId>
<version>0.2.3</version>
<version>0.2.4</version>
<relativePath>../flash-messages-parent/pom.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion flash-messages-core/pom.xml
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>es.sandbox.ui.messages</groupId>
<artifactId>flash-messages-parent</artifactId>
<version>0.2.3</version>
<version>0.2.4</version>
<relativePath>../flash-messages-parent/pom.xml</relativePath>
</parent>

Expand Down
@@ -1,10 +1,11 @@
/**
*
*/
package es.sandbox.ui.messages;

import java.io.Serializable;
import java.util.*;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.EnumMap;
import java.util.List;


/**
Expand Down
Expand Up @@ -14,7 +14,9 @@
import static org.fest.assertions.api.Assertions.assertThat;
import static org.mockito.BDDMockito.given;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.*;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;

@RunWith(Enclosed.class)
public class ContextSpecs {
Expand Down
Expand Up @@ -7,7 +7,9 @@
import org.junit.experimental.runners.Enclosed;
import org.junit.runner.RunWith;

import static es.sandbox.test.assertion.ArgumentAssertions.*;
import static es.sandbox.test.assertion.ArgumentAssertions.arguments;
import static es.sandbox.test.assertion.ArgumentAssertions.assertThatConstructor;
import static es.sandbox.test.assertion.ArgumentAssertions.assertThatMethod;
import static org.fest.assertions.api.Assertions.assertThat;


Expand Down
Expand Up @@ -3,7 +3,11 @@
import org.apache.commons.lang3.RandomStringUtils;
import org.joda.time.DateTime;

import java.util.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.Random;

public class MessageFixturer {

Expand Down
Expand Up @@ -7,7 +7,9 @@
import org.junit.experimental.runners.Enclosed;
import org.junit.runner.RunWith;

import static es.sandbox.test.assertion.ArgumentAssertions.*;
import static es.sandbox.test.assertion.ArgumentAssertions.arguments;
import static es.sandbox.test.assertion.ArgumentAssertions.assertThatConstructor;
import static es.sandbox.test.assertion.ArgumentAssertions.assertThatMethod;
import static org.fest.assertions.api.Assertions.assertThat;


Expand Down
2 changes: 1 addition & 1 deletion flash-messages-parent/pom.xml
Expand Up @@ -4,7 +4,7 @@

<groupId>es.sandbox.ui.messages</groupId>
<artifactId>flash-messages-parent</artifactId>
<version>0.2.3</version>
<version>0.2.4</version>
<packaging>pom</packaging>

<name>Flash Messages POM</name>
Expand Down
2 changes: 1 addition & 1 deletion flash-messages-spring/pom.xml
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>es.sandbox.ui.messages</groupId>
<artifactId>flash-messages-parent</artifactId>
<version>0.2.3</version>
<version>0.2.4</version>
<relativePath>../flash-messages-parent/pom.xml</relativePath>
</parent>

Expand Down
Expand Up @@ -2,7 +2,11 @@

import org.springframework.context.annotation.Import;

import java.lang.annotation.*;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;


@Retention(RetentionPolicy.RUNTIME)
Expand Down
@@ -1,6 +1,10 @@
package es.sandbox.ui.messages.spring.config.annotation;

import es.sandbox.ui.messages.*;
import es.sandbox.ui.messages.Context;
import es.sandbox.ui.messages.ContextBuilder;
import es.sandbox.ui.messages.CssClassesByLevel;
import es.sandbox.ui.messages.Level;
import es.sandbox.ui.messages.StoreAccessorFactory;
import es.sandbox.ui.messages.resolver.MessageResolverStrategy;
import es.sandbox.ui.messages.spring.config.FlashMessagesHandlerInterceptor;
import es.sandbox.ui.messages.spring.config.FlashMessagesMethodArgumentResolver;
Expand Down
Expand Up @@ -12,7 +12,9 @@

import static es.sandbox.spring.fixture.MockedSpringHttpServletRequest.detachedHttpServletRequest;
import static org.fest.assertions.api.Assertions.assertThat;
import static org.mockito.Mockito.*;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.only;
import static org.mockito.Mockito.verify;


@RunWith(Enclosed.class)
Expand Down
@@ -1,7 +1,11 @@
package es.sandbox.ui.messages.spring.config;

import es.sandbox.spring.fixture.MockedSpringHttpServletRequest;
import es.sandbox.ui.messages.*;
import es.sandbox.ui.messages.Context;
import es.sandbox.ui.messages.ContextBuilder;
import es.sandbox.ui.messages.Flash;
import es.sandbox.ui.messages.Store;
import es.sandbox.ui.messages.StoreNotFoundException;
import es.sandbox.ui.messages.spring.scope.flash.FlashScopeStoreAccessorFactory;
import org.junit.Before;
import org.junit.Test;
Expand Down
2 changes: 1 addition & 1 deletion flash-messages-taglibs/pom.xml
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>es.sandbox.ui.messages</groupId>
<artifactId>flash-messages-parent</artifactId>
<version>0.2.3</version>
<version>0.2.4</version>
<relativePath>../flash-messages-parent/pom.xml</relativePath>
</parent>

Expand Down

0 comments on commit ee27a2d

Please sign in to comment.