Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 814307
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T01:29:58+00:00 2026-05-15T01:29:58+00:00

for some reasons I am trying to translate the following RoR view code to

  • 0

for some reasons I am trying to translate the following RoR view code to a GSP view:

List<Object> objectscontains the data I want to display in 3 columns

<% 
modulo_objects = @objects.length % 3
base = @objects.length / 3
base = base.ceil
case modulo_objects
  when 0
 cols = [base, base, base]
  when 1
 cols = [base, base + 1, base]
  when 2
 cols = [base + 1, base, base + 1]
end

counter = 0
%>

<% 3.times do |i| %>
 <td width="220" align="center" style="padding-right: 15px;">
      <% cols[i].times do %>
  <h1><a href="/objects/show/<%= @objects[counter].urlname %>" ><%= @objects[counter].name %></a></h1>
  <% counter = counter + 1 %>
  <% end %>
 </td>
<% end %>

This is what I got so far:

#{extends 'main.html' /}
%{
modulo_objects = objects.size() % 3
base = objects.size() / 3
base = Math.ceil(base)
if(modulo_objects == 0)
    cols = [base, base, base]
else if(modulo_objects == 1)
    cols = [base, base + 1, base]
else if(modulo_objects == 2)
    cols = [base + 1, base, base + 1]
endif

counter = 0

}%

 #{list items:1..3, as:'i'}
     <td width="220" align="center" style="padding-right: 15px;">
         #{list items:cols[i]}
            <a href="@{Objects.show(objects.get(counter).name.replaceAll(" ", "-"))}" >${objects.get(counter).name}</a>
            %{ counter = counter + 1 }%
         #{/list}
     </td>
 #{/list}

The idea is to keep the items organised in 3 columns like 1|0|1 4|5|4 or 5|4|5 for example,
I don’t really understand if #{list items:cols[i]} will reproduce ruby’s cols[i].times do.

So far the Java view is does not display more than two elements.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T01:29:58+00:00Added an answer on May 15, 2026 at 1:29 am
      public static List<Object>[] splitIn(List<Object> objects, int i) {
    
        int base_objects = objects.size() / i;
        int modulo_objects = objects.size() % i;
        int[] colSize = new int[i];
    
        switch (modulo_objects) {
            case 0:
                colSize[0] = base_objects;
                colSize[1] = base_objects;
                colSize[2] = base_objects;
                break;
            case 1:
                colSize[0] = base_objects;
                colSize[1] = base_objects + 1;
                colSize[2] = base_objects;
                break;
            case 2:
                colSize[0] = base_objects + 1;
                colSize[1] = base_objects;
                colSize[2] = base_objects + 1;
                break;
        }
    
        List<Object>[] columns = new List[i];
    
        int count = 0;
        for (int x = 0; x < i; x++) {
            List<Object> col_objects = new ArrayList();
            int colCount = 0;
            while (colCount < colSize[x]) {
                Object Object = (Object) objects.get(count);
                col_objects.add(Object);
                colCount++;
                count++;
            }
            columns[x] = col_objects;
        }
        return columns;
    }
    
    
    
    
    
    
    #{list cols, as:'column'}
      <td width="220" align="center" style="padding-right: 15px;">
          #{list column, as:'object'}
                    <h1><a href="@{Objects.show(object.urlName())}" >${object.name}</a></h1>
          #{/list}
       </td>
       #{/list}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to use JQuery's autocomplete plug-in but for some reasons Internet Explorer is
I am trying to create an ordered list on IE7 but for some reason
I've been trying to display the box characters using PDCurses but for some reason
I'm trying to update some info into database but for some reasons it doesn't
I'm coming from C# and trying to translate some of my practices into C++.
I'm trying to compile the following Objective-C program on Ubuntu Hardy, but for some
I'm trying to get rid of cmake in my project for some reasons. I
I'm trying to translate the following macro from land of lisp into clojure: (defmacro
I'm trying to implement ping function in MonoTouch. for some reasons, Ping class from
I am trying to add a gradient layet to my UILabel for some reasons

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.