Introduction
In the previous article, I covered SIcore's "Mockup = Implementation" concept — how static HTML mockups become implementation code.
This time, I'll explain "Dynamic List Rendering" — how SIcore automatically expands array data from the server into table rows or list elements using templates.
What This Article Covers
- What dynamic list rendering is
- Automatic row generation using templates
- Implementation steps and code examples
- Benefits
What is Dynamic List Rendering?
In SIcore, array data [{}, {}] returned from the server is automatically expanded into row elements using HTML templates.
Traditional JSP requires loop constructs like <c:forEach>, but SIcore only requires defining a template row — the array data expands automatically.
Implementation Steps and Code Examples
Step 1: Define the Template Row
Define a template row inside the <tbody> tag using <script type="text/html">.
Static HTML (template row only):
<table>
<tbody id="list">
<script type="text/html">
<tr>
<td><input name="list.pet_nm"></td>
<td><input name="list.weight_kg"></td>
</tr>
</script>
</tbody>
</table>
Key points:
- Add
id="list"to the<tbody>tag - Wrap the template row in
<script type="text/html">(planned migration to<template>) - Use the naming pattern
list.field_namefor thenameattributes (wherelistmatches the JSON key)
Step 2: Fetch Array Data from Server and Display
JavaScript:
// Generate request JSON from browser input
const req = PageUtil.getValues();
const res = await HttpUtil.callJsonService('/services/exmodule/ExampleListSearch', req);
// Response JSON
// {
// "list": [
// {"pet_nm": "Pochi", "weight_kg": "5.0"},
// {"pet_nm": "Tama", "weight_kg": "2.5"}
// ]
// }
// Auto-generate rows from response JSON
PageUtil.setValues(res);
Result: Rows Added to HTML
Result HTML (template row + generated rows):
<table>
<tbody id="list">
<script type="text/html">
<tr>
<td><input name="list.pet_nm"></td>
<td><input name="list.weight_kg"></td>
</tr>
</script>
<tr>
<td><input name="list.pet_nm" value="Pochi"></td>
<td><input name="list.weight_kg" value="5.0"></td>
</tr>
<tr>
<td><input name="list.pet_nm" value="Tama"></td>
<td><input name="list.weight_kg" value="2.5"></td>
</tr>
</tbody>
</table>
PageUtil.setValues(res) automatically expands the array data into table rows.
Explicit Row Addition
You can also explicitly add rows via JavaScript without receiving array data:
// Add a single row
PageUtil.addRow('list', {pet_nm: 'Pochi', weight_kg: '5.0'});
// Add multiple rows
PageUtil.addRow('list', [
{pet_nm: 'Pochi', weight_kg: '5.0'},
{pet_nm: 'Tama', weight_kg: '2.5'}
]);
Benefits
1. No Loop Construct Needed
You don't need constructs like JSP's <c:forEach> or Thymeleaf's th:each. Just define a template row, and array data expands automatically.
2. Easy Transition from HTML Mockups
Simply wrap table rows created during the mockup phase in <script type="text/html"> to turn them into implementation code.
3. Server Just Returns JSON
The server (Java) doesn't need to worry about loop processing — just return array data as JSON.
// Java code
public void doExecute(Io io) {
// Database query
final IoRows rows = SqlUtil.selectBulk(getDbConn(), SQL_SEL_PET);
// Set result rows
io.putRows("list", rows);
}
Conclusion
SIcore's dynamic list rendering feature makes displaying array data simple and concise.
Next time, I'll introduce SIcore's custom HTML attributes.
Related Articles
Check out the other articles in this series!
- 001 I built a lightweight framework for Japan's SI projects
- 002 Direct URL-to-Class Mapping
- 003 JSON-Only Communication
- 004 Static Mockup = Implementation
- 005 Dynamic List Rendering (this article)
- 006 Custom HTML Attributes
- 007 Map-Based Design
SIcore Framework Links
All implementation code and documentation are available here:
- GitHub: https://github.com/sugaiketadao/sicore-ja
- How to check sample pages: https://github.com/sugaiketadao/sicore-ja#%EF%B8%8F-%E3%82%B5%E3%83%B3%E3%83%97%E3%83%AB%E7%94%BB%E9%9D%A2%E3%81%AE%E7%A2%BA%E8%AA%8D%E6%96%B9%E6%B3%95---vs-code
- Getting started with AI development: https://github.com/sugaiketadao/sicore-ja#-ai%E9%96%8B%E7%99%BA%E3%81%AE%E5%A7%8B%E3%82%81%E6%96%B9
Thank you for reading!
💖 If you found this helpful, I'd appreciate a like!
Top comments (0)