mvysny / vaadin-on-kotlin

Writing full-stack statically-typed web apps on JVM at its simplest
https://www.vaadinonkotlin.eu/
MIT License
186 stars 17 forks source link

Getting Started Tutorial: Listing All Articles #61

Closed max-bertinetti closed 3 years ago

max-bertinetti commented 3 years ago

Hi @mvysny.

I'm following the tutorial and when I arrive to section 5.8 Listing All Articles I get stuck:

vok-helloworld-app-v10/web/src/main/kotlin/com/example/vok/ArticlesView.kt: (6, 41): Unresolved reference: dataProvider

 package com.example.vok

import com.github.mvysny.karibudsl.v10.*
import com.vaadin.flow.component.grid.Grid
import com.vaadin.flow.router.*
import eu.vaadinonkotlin.vaadin10.vokdb.dataProvider

@Route("articles")
class ArticlesView: KComposite(), AfterNavigationObserver {
    private lateinit var grid: Grid<Article>
    private val root = ui {
        verticalLayout {
            setSizeFull()
            h1("Listing Articles")
            grid = grid(dataProvider = Article.dataProvider) {
                isExpand = true; setSizeFull()
                addColumnFor(Article::id)
                addColumnFor(Article::title)
                addColumnFor(Article::text)
            }
        }
    }

    override fun afterNavigation(event: AfterNavigationEvent) {
        grid.refresh()
    }
}
mvysny commented 3 years ago

Thank you, good catch. Let me take a look at that but it should most probably be dataLoader = Article.dataLoader

max-bertinetti commented 3 years ago

@mvysny I finally make it work like this, but I don't know if it's the right way:

package com.example.vok

import com.github.mvysny.karibudsl.v10.*
import com.vaadin.flow.component.grid.Grid
import com.vaadin.flow.router.*
import com.github.vokorm.dataloader.dataLoader
import eu.vaadinonkotlin.vaadin10.vokdb.asDataProvider

@Route("articles")
class ArticlesView: KComposite(), AfterNavigationObserver {
    private lateinit var grid: Grid<Article>
    private val root = ui {
        verticalLayout {
            setSizeFull()
            h1("Listing Articles")
            grid = grid( dataProvider = Article.dataLoader.asDataProvider()) {
                isExpand = true; setSizeFull()
                addColumnFor(Article::id)
                addColumnFor(Article::title)
                addColumnFor(Article::text)
            }
        }
    }

    override fun afterNavigation(event: AfterNavigationEvent) {
        grid.refresh()
    }
}
max-bertinetti commented 3 years ago

package com.example.vok

5.10 Adding Some Validation

import com.github.vokorm.*
import com.gitlab.mvysny.jdbiorm.Dao
import org.hibernate.validator.constraints.Length
import javax.validation.constraints.NotNull

data class Article(
        override var id: Long? = null,

        @field:NotNull
        @field:Length(min = 5)
        var title: String? = null,

        @field:NotNull
        @field:Length(min = 2)
        var text: String? = null
) : KEntity<Long> {
    companion object : Dao<Article, Long>(Article::class.java)
}

org.hibernate.validator is not imported I actually changed thevalidation with import

javax.validation.constraints.*

and

@field:Size(min = 5, max = 80)

Doing this the invalid form is also returned back without changing the button

max-bertinetti commented 3 years ago
import com.github.vokorm.getById

Unresolved reference: getById everywhere

max-bertinetti commented 3 years ago

Documentation contributions section is missing

I will love to contribute to this lovely project

mvysny commented 3 years ago

Thank you so much :) you're right, the contribution docs is missing - I'll add it. But basically simply create a pr for files located at https://github.com/mvysny/vaadin-on-kotlin/tree/master/docs

mvysny commented 3 years ago

The contributing guide is now present at https://www.vaadinonkotlin.eu/contributing.html :+1:

max-bertinetti commented 3 years ago

Ok. Can you please confirm that what I do in the above case for finish the tutorial is the right way?

mvysny commented 3 years ago

Unresolved reference: getById everywhere

You're right - the function is no longer an extension function but is baked into the Dao class and thus doesn't need any import. I'll fix this.

max-bertinetti commented 3 years ago

What about my solution for org.hibernate.validator.constraints.Length and dataprovider? Are the right one?

@mvysny sorry to bother you, but I'm quite new to Kotlin and I don't do Java from 1.4

mvysny commented 3 years ago

No problem! I think the tutorial doesn't probably mention that a dependency on Hibernate-validator needs to be added. I'll fix the docs in this regard as well.

Meanwhile, while the docs is fixed: please take a look at https://github.com/mvysny/vok-helloworld-app-v10 the "complete" branch. That's the full application sources which compile and work for me; while the docs are out-of-date, please find the correct code samples there.

max-bertinetti commented 3 years ago

Oh thank you! I don't see that branch lol!

I sended you an email.

mvysny commented 3 years ago

There's a branch switcher combobox in GitHub which will take you to the branch; however here's a link to the "complete" sources: https://github.com/mvysny/vok-helloworld-app-v10/tree/complete

max-bertinetti commented 3 years ago

No, I know how Git and Github works, only I don't think about searching for it and is not mentioned in the tutorial.

mvysny commented 3 years ago

Ah, you're right; added in 37f8cda2988c9ce4e030a6ca99e484fc71aba8df

mvysny commented 3 years ago

@maxbertinetti you have done a wonderful job with the new documentation site. With your permission I'm closing this issue; please feel free to open new tickets if you discover something else not working (or simply create a PR for the docs :+1: )