Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to output result data in Thymeleaf #888

Closed
AppyCat opened this issue Sep 17, 2019 · 2 comments
Closed

How to output result data in Thymeleaf #888

AppyCat opened this issue Sep 17, 2019 · 2 comments

Comments

@AppyCat
Copy link

AppyCat commented Sep 17, 2019

Hi, I got ActiveJDBC working fine. This is my view:

In the view it is as:

`

`

And here's what shows up in the browser.

Model: com.ac3.ac3.model.Contact, table: 'contacts', attributes: {body=test content, id=2, title=# 7}

I've tried ${r1.body} but get an error message, would appreciate any tip, thank you.

@AppyCat
Copy link
Author

AppyCat commented Sep 17, 2019

I figured it out from an example:

<tr th:each="r1 : ${res1}">
                <td th:utext="${r1.get('id')}"></td>
                <td th:utext="${r1.get('title')}"></td>
                <td th:utext="${r1.get('body')}"></td>
</tr>

If there's a more correct approach, let me know. Thanks.

@ipolevoy
Copy link
Member

ipolevoy commented Sep 17, 2019

you can also write the getters for your attributes:

public class Contact extends Model {
   ...
      public String getTitle(){
             return getString("title");
      }
   ...
}

See: http://javalite.io/setters_and_getters

You can also use Freemarker which works as expected out of the box:

<#list contacts as contact>
   <tr>
                <td th:utext="${contact.id}"></td>
                <td th:utext="${contact.title}"></td>
                <td th:utext="${contact.body}"></td>
  </tr>
</#list>

If you use ActiveWeb, Freemarker is built-in.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants