Skip to content

Commit 9680822

Browse files
committed
docs
1 parent cefb451 commit 9680822

File tree

1 file changed

+21
-25
lines changed

1 file changed

+21
-25
lines changed

docs/tutorial.md

Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,8 @@ right-click the arrow and select "Debug 'Main'" from the menu. Your app is now r
287287
Running the app from Intellij in debug mode allows you to publish changes in your file directly to the running app easily.
288288
Simply edit the file, then press CTRL+F9 (or *Build / Build Project* from the menu) then reload the page in your browser.
289289

290+
To stop or restart the app from Intellij, simply hit the red square *Stop* button in the upper-right part of the screen.
291+
290292
## Getting Up and Running
291293

292294
Now that you've seen how to create a view, let's create something with a bit more substance.
@@ -297,7 +299,7 @@ read, update and destroy items for a resource and these operations are referred
297299
CRUD operations.
298300

299301
VoK provides a resources method which can be used to declare a standard REST resource. But first, let us define the article.
300-
Create the `web/src/main/kotlin/com/example/vok/Article.kt` file with the following contents:
302+
Create the `src/main/kotlin/com/example/vok/Article.kt` file with the following contents:
301303

302304
```kotlin
303305
package com.example.vok
@@ -347,8 +349,7 @@ In order to take these REST endpoints into use, in the `Bootstrap.kt`, edit the
347349

348350
```kotlin
349351
fun Javalin.configureRest(): Javalin {
350-
val gson = GsonBuilder().create()
351-
gson.configureToJavalin()
352+
gsonMapper(VokRest.gson)
352353
articleRest()
353354
return this
354355
}
@@ -382,7 +383,7 @@ In the next section, you will add the ability to create new articles in your app
382383

383384
It will look a little basic for now, but that's ok. We'll look at improving the styling for it afterwards.
384385

385-
Before going any further, please create a Kotlin file named `web/src/main/kotlin/com/example/vok/MainLayout.kt` with the following
386+
Before going any further, please create a Kotlin file named `src/main/kotlin/com/example/vok/MainLayout.kt` with the following
386387
contents:
387388

388389
```kotlin
@@ -393,11 +394,6 @@ import com.github.mvysny.karibudsl.v10.div
393394
import com.vaadin.flow.component.page.Viewport
394395
import com.vaadin.flow.router.RouterLayout
395396

396-
/**
397-
* The main layout:
398-
* * provides application frame around all views
399-
* * handles redirect to the [LoginView] if no user is logged in.
400-
*/
401397
@Viewport(Viewport.DEVICE_DIMENSIONS)
402398
class MainLayout : KComposite(), RouterLayout {
403399
private val root = ui {
@@ -502,14 +498,14 @@ created the database table for Article yet.
502498

503499
Luckily, we have already created the model - it's the `Article` entity class.
504500
We will use [VoK-ORM](https://github.com/mvysny/vok-orm) which will map
505-
the Article object to a relational database. By default it will map to the "Article" table.
501+
the Article object to a relational (SQL) database. By default, it will map to the "Article" table.
506502
To create the table, we will have to create the migration.
507503

508504
> **Note:** vok-orm is smart enough to automatically map column names to the Article class properties,
509505
> which means you don't have to provide the database name for every property
510506
> inside entities, as that will be done automatically by vok-orm.
511507
512-
To create the migration, create a file named `V01__CreateArticle.sql` in the `web/src/main/resources/db/migration` directory, with the following contents:
508+
To create the migration, create a file named `V01__CreateArticle.sql` in the `src/main/resources/db/migration` directory, with the following contents:
513509

514510
```sql
515511
create table Article(
@@ -536,7 +532,7 @@ rules in the [Flyway Versioned Migrations Guide](https://flywaydb.org/documentat
536532

537533
When Flyway runs this migration it will create an articles table with one string column and a text column.
538534

539-
At this point, you can simply kill and restart the server, to automatically run all migrations.
535+
At this point, you can simply kill and restart the app, to automatically run all migrations.
540536
Since we are currently using an in-memory H2 database, its contents are gone when the server is killed,
541537
and since we are starting with a fresh database, all migrations will run. When we'll use a persistent database,
542538
Flyway will make sure that only a newly defined migrations are run.
@@ -550,7 +546,7 @@ we will redirect to an `ArticleView` which we'll define later.
550546
> **Note:** You might be wondering why the A in Article is capitalized
551547
> above, whereas most other references to articles in this guide have used lowercase.
552548
> In this context, we are referring to the class named Article that is defined in `web/src/main/kotlin/com/example/vok/Article.kt`.
553-
> Class names in Kotlin must begin with a capital letter.
549+
> It's a convention for class names in Kotlin to begin with a capital letter.
554550
555551
> **Note:** As we'll see later, `binder.writeBeanIfValid()` returns a boolean indicating whether the article was saved or not.
556552
@@ -637,7 +633,7 @@ With this change, you should finally be able to create new articles. Visit
637633

638634
### Listing All Articles
639635

640-
We still need a way to list all our articles, so let's do that. We'll create the `web/src/main/kotlin/com/examples/vok/ArticlesView.kt` with the
636+
We still need a way to list all our articles, so let's do that. We'll create the `src/main/kotlin/com/examples/vok/ArticlesView.kt` with the
641637
following contents:
642638

643639
```kotlin
@@ -680,7 +676,7 @@ including sorting and filtering.
680676

681677
You can now create, show, and list articles. Now let's add some links to navigate through pages.
682678

683-
Open `web/src/main/kotlin/com/example/vok/MyWelcomeView.kt` and modify its contents as follows:
679+
Open `src/main/kotlin/com/example/vok/MyWelcomeView.kt` and modify its contents as follows:
684680

685681
```kotlin
686682
package com.example.vok
@@ -789,7 +785,7 @@ the `article` entity, but only if everything is valid.
789785

790786
We've covered the "CR" part of CRUD. Now let's focus on the "U" part, updating articles.
791787

792-
The first step we'll take is adding the `web/src/main/kotlin/com/example/vok/EditArticleView.kt`:
788+
The first step we'll take is adding the `src/main/kotlin/com/example/vok/EditArticleView.kt`:
793789

794790
```kotlin
795791
package com.example.vok
@@ -918,7 +914,7 @@ Our `EditArticleView` view looks very similar to the `CreateArticleView` view; i
918914
they both share the same code for displaying the form.
919915
Let's remove this duplication by using a common component.
920916

921-
Create a new file `web/src/main/kotlin/com/example/vok/ArticleEditor.kt` with the following content:
917+
Create a new file `src/main/kotlin/com/example/vok/ArticleEditor.kt` with the following content:
922918

923919
```kotlin
924920
package com.example.vok
@@ -1104,7 +1100,7 @@ It's time to add a second database table to the application. The second database
11041100

11051101
### Creating the 'Comments' Entity
11061102

1107-
We'll create a `Comment` entity to hold comments for an article. Create the following file: `web/src/main/kotlin/com/example/vok/Comment.kt` with the following contents:
1103+
We'll create a `Comment` entity to hold comments for an article. Create the following file: `src/main/kotlin/com/example/vok/Comment.kt` with the following contents:
11081104

11091105
```kotlin
11101106
package com.example.vok
@@ -1138,7 +1134,7 @@ which sets up an association. You'll learn a little about associations in the ne
11381134

11391135
Note the `article_id` column - it tells which Article the comment belongs to.
11401136
You can get a better understanding after analyzing the appropriate migration script. Just create
1141-
`web/src/main/resources/db/migration/V02__CreateComment.sql` file with the following contents:
1137+
`src/main/resources/db/migration/V02__CreateComment.sql` file with the following contents:
11421138

11431139
```sql
11441140
create TABLE Comment(
@@ -1356,13 +1352,13 @@ Now you can add articles and comments to your blog and have them show up in the
13561352
13571353
## Refactoring
13581354

1359-
Now that we have articles and comments working, take a look at the `web/src/main/kotlin/com/example/vok/ArticleView.kt` view.
1355+
Now that we have articles and comments working, take a look at the `src/main/kotlin/com/example/vok/ArticleView.kt` view.
13601356
It is getting long and awkward. We can create reusable components to clean it up.
13611357

13621358
### The Comments Component
13631359

13641360
First, we will extract a component which will show comments for given article. Since we will need to add a 'delete' link
1365-
in the future, the `div` component will no longer suffice. Create the `web/src/main/kotlin/com/example/vok/CommentsComponent.kt` file:
1361+
in the future, the `div` component will no longer suffice. Create the `src/main/kotlin/com/example/vok/CommentsComponent.kt` file:
13661362

13671363
```kotlin
13681364
package com.example.vok
@@ -1413,7 +1409,7 @@ You can learn more about how DSL works, from the [Writing Vaadin Apps In Kotlin
14131409
### Converting the Comments Form to a component
14141410

14151411
Let us also move that new comment section out to its own component. Create the file named
1416-
`web/src/main/kotlin/com/example/vok/NewCommentForm.kt` with the following contents:
1412+
`src/main/kotlin/com/example/vok/NewCommentForm.kt` with the following contents:
14171413

14181414
```kotlin
14191415
package com.example.vok
@@ -1580,7 +1576,7 @@ Adding security to Java WAR apps is usually done by letting the web server (e.g.
15801576
and verification, while our web app provides the login dialog. To keep this guide web server agnostic,
15811577
we'll do the verification ourselves.
15821578

1583-
We will implement a login service and a login form. Just create the `web/src/main/kotlin/com/example/vok/LoginService.kt` file:
1579+
We will implement a login service and a login form. Just create the `src/main/kotlin/com/example/vok/LoginService.kt` file:
15841580

15851581
```kotlin
15861582
package com.example.vok
@@ -1611,12 +1607,12 @@ class LoginService : Serializable {
16111607
val isLoggedIn get() = currentUser != null
16121608
}
16131609

1614-
val Session.loginService: LoginService get() = getOrPut { LoginService() }
1610+
val Session.loginService: LoginService get() = getOrPut(LoginService::class) { LoginService() }
16151611
```
16161612

16171613
This will handle user log in and will store current user along with the `LoginService` into the session.
16181614

1619-
Next is the `LoginView`: just create the `web/src/main/kotlin/com/example/vok/LoginView.kt` file:
1615+
Next is the `LoginView`: just create the `src/main/kotlin/com/example/vok/LoginView.kt` file:
16201616

16211617
```kotlin
16221618
package com.example.vok

0 commit comments

Comments
 (0)