Translation of a RoR view to Java

Posted by mnml on Stack Overflow See other posts from Stack Overflow or by mnml
Published on 2010-05-25T18:06:40Z Indexed on 2010/05/26 12:31 UTC
Read the original article Hit count: 254

Hi, 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.

© Stack Overflow or respective owner

Related posts about java

Related posts about ruby-on-rails