0

I have this code:

<%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic"%>

<% List<String> years = new ArrayList<String>(); %>

<logic:iterate name="ActiviteHolidayForm" property="holidayDays" id="line">
<%
if(!years.contains(line.toString().split("-")[0]))
    years.add(line.toString().split("-")[0]);
%>
</logic:iterate>

The problem is that this code inserts a huge number of blank lines in the source code (I suppose equal to the times the code iterates). Is there a way to avoid this? I mention that I have a single line before and after this code. Thanks!

Steven Benitez
  • 10,936
  • 3
  • 39
  • 50
radonys
  • 597
  • 1
  • 9
  • 20
  • 1
    Hi, at first I would have written all this code under one line and tried again. Is that what you meant in "I mention that I have a single line before and after this code." ? – Flavien Volken Sep 19 '11 at 12:19
  • possible duplicate of [Strip whitespace from jsp output](http://stackoverflow.com/questions/208736/strip-whitespace-from-jsp-output) – BalusC Sep 19 '11 at 12:29
  • Thanks! The return between _id="line">_ and _<%_ and the one between _%>_ and __ seem to cause the problem. – radonys Sep 19 '11 at 12:32
  • Bigger question is "why are you doing this in the JSP?" – Dave Newton Sep 19 '11 at 12:35
  • @Dave Newton The answer is simple: I don't like how it's done either, but I can't figure out how else to do it, and it works this way. I'm new to JSP and Struts. – radonys Sep 19 '11 at 12:51
  • Logic like that should be done in the action, or better still, a service called by the action. – Dave Newton Sep 19 '11 at 12:54

2 Answers2

2

Summary of New Features in JSP 2.1 Technology:

Removing Blank Lines: TrimWhiteSpace

Can be done by inserting <%@page trimDirectiveWhitespaces="true"%> in your JSP or by inserting the following part in your web.xml (Servlet 2.5 XSD):

<jsp-config>
    <jsp-property-group>
        <url-pattern>*.jsp</url-pattern>
        <trim-directive-whitespaces>true</trim-directive-whitespaces>
    </jsp-property-group>
</jsp-config>
Christopher
  • 694
  • 7
  • 15
  • I suppose my container doesn't support trimDirectiveWhitespaces because I get this: javax.servlet.ServletException Page directive has invalid attribute: trimDirectiveWhitespaces. – radonys Sep 19 '11 at 12:46
1

Struts is not inserting blank lines; you are inserting blank lines. Answer this question and you will understand why: "What characters do you have between %> and </logic:iterate>?"

DwB
  • 37,124
  • 11
  • 56
  • 82