Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

JET FAQ How do I get new lines in the right place when using iterate with delimiter?

Revision as of 09:49, 22 June 2007 by Pelder.ca.ibm.com (Talk | contribs) (New page: The <c:iterate> tag includes a delimiter attribute, which inserts a delimiter between blocks of code generated. But, if you try something like: <pre> public enum MyEnum { <c:iterate selec...)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

The <c:iterate> tag includes a delimiter attribute, which inserts a delimiter between blocks of code generated. But, if you try something like:

public enum MyEnum {
<c:iterate select="/def/elements" var="element" delimiter=",">
    <c:get select="upper-case($element/@name)"/>("<c:get select="$element/@alias"/>")
</c:iterate>
;

    private MyEnum(String alias) {
        // ...
    }
}

You end up with generated code looking like:

public enum MyEnum {
    BANK("bank")
,    RECORD("record")
,    MESSENGER("messenger")
;
    private MyEnum(String alias) {
        // ...
    }
}

JET is inserting the delimiter between each block generated by the iterate tag. But in this case, the tag's content includes a final new-line character - the delimiter is insert after this. One possibility is to make the new-line part of the delimiter itself:

public enum MyEnum {
<%-- The value of delimiter includes a new line. This not an accidental wrapping! --%>
<c:iterate select="/def/elements" var="element" delimiter=",
">
    <%-- and, the </c:iterate> tag is moved up, to eliminate the new line in content block --%>
    <%-- finally, the semi-colon is moved to onto the same line, too --%>
    <c:get select="upper-case($element/@name)"/>("<c:get select="$element/@alias"/>")</c:iterate>;

    private MyEnum(String alias) {
        // ...
    }
}

Return to the M2T-JET-FAQ.

Copyright © Eclipse Foundation, Inc. All Rights Reserved.