1

I want to take some data from the database and arrange it into rows with each row having 4 columns. Tables or css come to mind. By the way, I do not need borders.

What's a clean way to do this? If I use tables, I would have to count how many cells have been done in a row and in the last row add some empty cells to that row. Right? What is a better way?

I am using Spring MVC JSPs and looked at the associated docs. http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/view.html

Thanks!

2 Answers 2

2

rendering data in jsp using spring controllers and different classes

I think it answer your question completely.

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you for your response. The link you shared shows how to loop over objects and how to display properties of that object in a table row. I was looking for how to loop over strings and have 4 of those strings in the same row. Also it would have to handle the case where the number of strings is not a multiple of 4. Thanks!
This is closest. Have a great day!
2

I would suggest something like this:

<table id="list">
<thead class="dataTableHeader">
    <tr>
        <td><fmt:message key="items.header"/></td>
    </tr>
</thead>
<tbody>
    <c:if test="${fn:length(yourForm.items.count) < 4}">
        <tr>
            //add some empty rows
        </tr>
    </c:if>
        <c:forEach var="item" items="${yourForm.items}">
            <tr>
                <td>${item.id}</td>
                                    // and other colums
            </tr>
        </c:forEach>
</tbody>

1 Comment

something like that, true. I think a counter would be used and once the 4th cell in a row is done it can complete the row and start another. A check would have to be done to handle the case of empty cells. Example: outputting 10 items results in 3 rows with the 3rd row containing 2 empty cells.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.