PoisonedYouth
01/03/2025, 12:05 PMI have the following HttpHandler:
private val renderer = ThymeleafTemplates().HotReload("src/main/resources/templates")
fun getUiUserHandler(userInputPort: UserInputPort): HttpHandler =
{
val result = userInputPort.getAllUsers()
result.fold(
ifLeft = { handleFailure(it) },
ifRight = { userList ->
renderer.renderToResponse(UserViewModel(
users = userList.map {
UserDto(
id = it.id,
username = it.username,
)
}
)
)
},
)
}
The UserViewModel
looks like below:
data class UserViewModel(
val users: List<UserDto>,
): ViewModel{
override fun template(): String {
return "UserViewModel.html"
}
}
The html file is using a basic table to show the list of users:
<table class="table table-striped">
<thead>
<tr>
<th>ID</th>
<th>Username</th>
</tr>
</thead>
<tbody>
<tr th:each="user : ${users}">
<td th:text="${user.id}"></td>
<td th:text="${user.username}"></td>
</tr>
</tbody>
</table>
Everything works fine, but there are no entries shown in the table. Do I miss something in the configuration? I could not find more information in the documentation besides https://www.http4k.org/ecosystem/http4k/reference/templating/dave
01/03/2025, 12:22 PMmodel.<field>
because effectively we need to pass a map intot he templatePoisonedYouth
01/03/2025, 12:30 PM