Skip to content

Commit

Permalink
Merge branch 'development'
Browse files Browse the repository at this point in the history
  • Loading branch information
Frank Hossfeld committed Sep 3, 2019
2 parents 33ec121 + 8053cdd commit 1c7550a
Show file tree
Hide file tree
Showing 91 changed files with 2,287 additions and 1,665 deletions.
338 changes: 337 additions & 1 deletion etc/wiki/08. Router.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,340 @@ Nalu offers a caching feature. With this feature controllers and/or composites (

To cache a controller, use: `this.router.storeInCache(this);` inside a controller. To remove the controller from the cache, so that it will be created again, use: `this.router.removeFromCache(this);`.

You can also cache composites.
You can also cache composites.

# Router
The router is the main component inside a Nalu application. It is used to navigate inside the application, generate a url, get the start parameter and cache a controller.

The instance of the router is injected into:

* every controller
* every filter
* every handler.

The router can be used to:

* route inside the navigation
* to generate a route
* provides url parameters from the start url
* manages the caching

## Routing
To navigate inside a Nalu application you can use the `route`-method. The `route`-method accepts a route and a number of parameters (0 - n). For a successful navigation, the route must be valid. This means, there must be at least one controller, that accepts the route.

A route without parameters can be called like this:

```java
this.router.route("myShell/myRoute01/myRoute02");
```

In case the route has parameters, add them as to the method:

```java
this.router.route("myShell/myRoute01/myRoute02", parameter01, parameter02);
```

In this case Nalu will add the parameters at the end of the route. The resulting route will look like this:

```
myShell/myRoute01/myRoute02/parameter01/parameter02
```

To set a parameter inside the route, use a '\*' inside the route:

```java
this.router.route("myShell/myRoute01/*/myRoute02", parameter01, parameter02);
```

This will create the following route:

```
myShell/myRoute01/parameter01/myRoute02/parameter02
```

Using this method:

```java
this.router.route("myShell/myRoute01/" + parameter01 + "/myRoute02/" + parameter02);
```

will create a similar result.

**Attention:**

If you are using `useColonForParametersInUrl = true` inside the Application annotation, you need to add a ':' before every parameter:

```java
this.router.route("myShell/myRoute01/:" + parameter01 + "/myRoute02/:" + parameter02);
```

In case the routing is used in this way:

```java
this.router.route("myShell/myRoute01/*/myRoute02", parameter01, parameter02);
```

there is no need to add ':' before parameters, because Nalu will do that for you.

## Generating a Route
In case there is a need for a route inside a link, you can use the `generate`-method of the router. The method accepts a route and a list of parameters (0 - n) and will return the route. Calling the method with the following code:

```java
this.router.route("myShell/myRoute01/*/myRoute02", parameter01, parameter02);
```

will return a String that looks like that:

```
myShell/myRoute01/parameter01/myRoute02/parameter02
```

## Providing Start Parameters (since 1.1.0)
In case the application is called with parameters, Nalu provides a method inside the router to retrieve this parameter. Calling `getStartQueryParameters()` without parameters will return a `Map<String, String>` containing all start parameters.

For example, if the application is called with this url:

`http://localhost:8080/myApp/index.html?param1=value01&param2=value02`

and you want to access the `param2`, you can use this code:

```java
String value = this.router.getStartQueryParameters().get("param1");
```

to get the value of *param1*.

## Caching
Nalu offers a caching feature. With this feature controllers and/or composites (since v1.3.1) can be cached. This means, once Nalu has routed to a controller and this controller is cached, the instance of this controller (and of course the view) is cached and will be reused in case Nalu routes to this controller again.

To cache a controller, use: `this.router.storeInCache(this);` inside a controller. To remove the controller from the cache, so that it will be created again, use: `this.router.removeFromCache(this);`.

You can also cache composites.

## RouterStateEvent (since 1.3.1)
Nalu will fire a `RouterStateEvent` in case a routing occurs. The `RouterStateEvent` provides two inforamtions:

1. state of routing [START_ROUTING|ROUTING_ABORTED|ROUTING_DONE];
2. the current route
# Router
The router is the main component inside a Nalu application. It is used to navigate inside the application, generate a url, get the start parameter and cache a controller.

The instance of the router is injected into:

* every controller
* every filter
* every handler.

The router can be used to:

* route inside the navigation
* to generate a route
* provides url parameters from the start url
* manages the caching

## Routing
To navigate inside a Nalu application you can use the `route`-method. The `route`-method accepts a route and a number of parameters (0 - n). For a successful navigation, the route must be valid. This means, there must be at least one controller, that accepts the route.

A route without parameters can be called like this:

```java
this.router.route("myShell/myRoute01/myRoute02");
```

In case the route has parameters, add them as to the method:

```java
this.router.route("myShell/myRoute01/myRoute02", parameter01, parameter02);
```

In this case Nalu will add the parameters at the end of the route. The resulting route will look like this:

```
myShell/myRoute01/myRoute02/parameter01/parameter02
```

To set a parameter inside the route, use a '\*' inside the route:

```java
this.router.route("myShell/myRoute01/*/myRoute02", parameter01, parameter02);
```

This will create the following route:

```
myShell/myRoute01/parameter01/myRoute02/parameter02
```

Using this method:

```java
this.router.route("myShell/myRoute01/" + parameter01 + "/myRoute02/" + parameter02);
```

will create a similar result.

**Attention:**

If you are using `useColonForParametersInUrl = true` inside the Application annotation, you need to add a ':' before every parameter:

```java
this.router.route("myShell/myRoute01/:" + parameter01 + "/myRoute02/:" + parameter02);
```

In case the routing is used in this way:

```java
this.router.route("myShell/myRoute01/*/myRoute02", parameter01, parameter02);
```

there is no need to add ':' before parameters, because Nalu will do that for you.

## Generating a Route
In case there is a need for a route inside a link, you can use the `generate`-method of the router. The method accepts a route and a list of parameters (0 - n) and will return the route. Calling the method with the following code:

```java
this.router.route("myShell/myRoute01/*/myRoute02", parameter01, parameter02);
```

will return a String that looks like that:

```
myShell/myRoute01/parameter01/myRoute02/parameter02
```

## Providing Start Parameters (since 1.1.0)
In case the application is called with parameters, Nalu provides a method inside the router to retrieve this parameter. Calling `getStartQueryParameters()` without parameters will return a `Map<String, String>` containing all start parameters.

For example, if the application is called with this url:

`http://localhost:8080/myApp/index.html?param1=value01&param2=value02`

and you want to access the `param2`, you can use this code:

```java
String value = this.router.getStartQueryParameters().get("param1");
```

to get the value of *param1*.

## Caching
Nalu offers a caching feature. With this feature controllers and/or composites (since v1.3.1) can be cached. This means, once Nalu has routed to a controller and this controller is cached, the instance of this controller (and of course the view) is cached and will be reused in case Nalu routes to this controller again.

To cache a controller, use: `this.router.storeInCache(this);` inside a controller. To remove the controller from the cache, so that it will be created again, use: `this.router.removeFromCache(this);`.

You can also cache composites.

# Router
The router is the main component inside a Nalu application. It is used to navigate inside the application, generate a url, get the start parameter and cache a controller.

The instance of the router is injected into:

* every controller
* every filter
* every handler.

The router can be used to:

* route inside the navigation
* to generate a route
* provides url parameters from the start url
* manages the caching

## Routing
To navigate inside a Nalu application you can use the `route`-method. The `route`-method accepts a route and a number of parameters (0 - n). For a successful navigation, the route must be valid. This means, there must be at least one controller, that accepts the route.

A route without parameters can be called like this:

```java
this.router.route("myShell/myRoute01/myRoute02");
```

In case the route has parameters, add them as to the method:

```java
this.router.route("myShell/myRoute01/myRoute02", parameter01, parameter02);
```

In this case Nalu will add the parameters at the end of the route. The resulting route will look like this:

```
myShell/myRoute01/myRoute02/parameter01/parameter02
```

To set a parameter inside the route, use a '\*' inside the route:

```java
this.router.route("myShell/myRoute01/*/myRoute02", parameter01, parameter02);
```

This will create the following route:

```
myShell/myRoute01/parameter01/myRoute02/parameter02
```

Using this method:

```java
this.router.route("myShell/myRoute01/" + parameter01 + "/myRoute02/" + parameter02);
```

will create a similar result.

**Attention:**

If you are using `useColonForParametersInUrl = true` inside the Application annotation, you need to add a ':' before every parameter:

```java
this.router.route("myShell/myRoute01/:" + parameter01 + "/myRoute02/:" + parameter02);
```

In case the routing is used in this way:

```java
this.router.route("myShell/myRoute01/*/myRoute02", parameter01, parameter02);
```

there is no need to add ':' before parameters, because Nalu will do that for you.

## Generating a Route
In case there is a need for a route inside a link, you can use the `generate`-method of the router. The method accepts a route and a list of parameters (0 - n) and will return the route. Calling the method with the following code:

```java
this.router.route("myShell/myRoute01/*/myRoute02", parameter01, parameter02);
```

will return a String that looks like that:

```
myShell/myRoute01/parameter01/myRoute02/parameter02
```

## Providing Start Parameters (since 1.1.0)
In case the application is called with parameters, Nalu provides a method inside the router to retrieve this parameter. Calling `getStartQueryParameters()` without parameters will return a `Map<String, String>` containing all start parameters.

For example, if the application is called with this url:

`http://localhost:8080/myApp/index.html?param1=value01&param2=value02`

and you want to access the `param2`, you can use this code:

```java
String value = this.router.getStartQueryParameters().get("param1");
```

to get the value of *param1*.

## Caching
Nalu offers a caching feature. With this feature controllers and/or composites (since v1.3.1) can be cached. This means, once Nalu has routed to a controller and this controller is cached, the instance of this controller (and of course the view) is cached and will be reused in case Nalu routes to this controller again.

To cache a controller, use: `this.router.storeInCache(this);` inside a controller. To remove the controller from the cache, so that it will be created again, use: `this.router.removeFromCache(this);`.

You can also cache composites.

## RouterStateEvent (since 1.3.1)
Nalu will fire a `RouterStateEvent` in case a routing occurs. The `RouterStateEvent` provides two informations:

1. state of routing [START_ROUTING | ROUTING_ABORTED | ROUTING_DONE];
2. the current route

16 changes: 15 additions & 1 deletion nalu-plugin-core-web/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<parent>
<groupId>com.github.nalukit</groupId>
<artifactId>nalu-parent</artifactId>
<version>1.3.1</version>
<version>1.3.2</version>
</parent>

<artifactId>nalu-plugin-core-web</artifactId>
Expand Down Expand Up @@ -104,6 +104,20 @@
<artifactId>elemental2-dom</artifactId>
<version>${elemental2.version}</version>
</dependency>

<!-- only for testing -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>${junit-jupiter.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit-jupiter.version}</version>
<scope>test</scope>
</dependency>
</dependencies>


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
public abstract class AbstractLogger
implements IsLogger {

static final String INDENT = "..";
protected static final String INDENT = "..";

protected String createLog(String message,
int depth) {
Expand Down
Loading

0 comments on commit 1c7550a

Please sign in to comment.