You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* * handles redirect to the [LoginView] if no user is logged in.
400
-
*/
401
397
@Viewport(Viewport.DEVICE_DIMENSIONS)
402
398
classMainLayout : KComposite(), RouterLayout {
403
399
privateval root = ui {
@@ -502,14 +498,14 @@ created the database table for Article yet.
502
498
503
499
Luckily, we have already created the model - it's the `Article` entity class.
504
500
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.
506
502
To create the table, we will have to create the migration.
507
503
508
504
> **Note:** vok-orm is smart enough to automatically map column names to the Article class properties,
509
505
> which means you don't have to provide the database name for every property
510
506
> inside entities, as that will be done automatically by vok-orm.
511
507
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:
513
509
514
510
```sql
515
511
createtableArticle(
@@ -536,7 +532,7 @@ rules in the [Flyway Versioned Migrations Guide](https://flywaydb.org/documentat
536
532
537
533
When Flyway runs this migration it will create an articles table with one string column and a text column.
538
534
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.
540
536
Since we are currently using an in-memory H2 database, its contents are gone when the server is killed,
541
537
and since we are starting with a fresh database, all migrations will run. When we'll use a persistent database,
542
538
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.
550
546
> **Note:** You might be wondering why the A in Article is capitalized
551
547
> above, whereas most other references to articles in this guide have used lowercase.
552
548
> 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.
554
550
555
551
> **Note:** As we'll see later, `binder.writeBeanIfValid()` returns a boolean indicating whether the article was saved or not.
556
552
@@ -637,7 +633,7 @@ With this change, you should finally be able to create new articles. Visit
637
633
638
634
### Listing All Articles
639
635
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
641
637
following contents:
642
638
643
639
```kotlin
@@ -680,7 +676,7 @@ including sorting and filtering.
680
676
681
677
You can now create, show, and list articles. Now let's add some links to navigate through pages.
682
678
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:
684
680
685
681
```kotlin
686
682
packagecom.example.vok
@@ -789,7 +785,7 @@ the `article` entity, but only if everything is valid.
789
785
790
786
We've covered the "CR" part of CRUD. Now let's focus on the "U" part, updating articles.
791
787
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`:
793
789
794
790
```kotlin
795
791
packagecom.example.vok
@@ -918,7 +914,7 @@ Our `EditArticleView` view looks very similar to the `CreateArticleView` view; i
918
914
they both share the same code for displaying the form.
919
915
Let's remove this duplication by using a common component.
920
916
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:
922
918
923
919
```kotlin
924
920
packagecom.example.vok
@@ -1104,7 +1100,7 @@ It's time to add a second database table to the application. The second database
1104
1100
1105
1101
### Creating the 'Comments' Entity
1106
1102
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:
1108
1104
1109
1105
```kotlin
1110
1106
packagecom.example.vok
@@ -1138,7 +1134,7 @@ which sets up an association. You'll learn a little about associations in the ne
1138
1134
1139
1135
Note the `article_id` column - it tells which Article the comment belongs to.
1140
1136
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:
1142
1138
1143
1139
```sql
1144
1140
createTABLEComment(
@@ -1356,13 +1352,13 @@ Now you can add articles and comments to your blog and have them show up in the
1356
1352
1357
1353
## Refactoring
1358
1354
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.
1360
1356
It is getting long and awkward. We can create reusable components to clean it up.
1361
1357
1362
1358
### The Comments Component
1363
1359
1364
1360
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:
1366
1362
1367
1363
```kotlin
1368
1364
packagecom.example.vok
@@ -1413,7 +1409,7 @@ You can learn more about how DSL works, from the [Writing Vaadin Apps In Kotlin
1413
1409
### Converting the Comments Form to a component
1414
1410
1415
1411
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:
1417
1413
1418
1414
```kotlin
1419
1415
packagecom.example.vok
@@ -1580,7 +1576,7 @@ Adding security to Java WAR apps is usually done by letting the web server (e.g.
1580
1576
and verification, while our web app provides the login dialog. To keep this guide web server agnostic,
1581
1577
we'll do the verification ourselves.
1582
1578
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:
1584
1580
1585
1581
```kotlin
1586
1582
packagecom.example.vok
@@ -1611,12 +1607,12 @@ class LoginService : Serializable {
0 commit comments