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.
Difference between revisions of "JET FAQ How do I get new lines in the right place when using iterate with delimiter?"
(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...) |
m |
||
Line 1: | Line 1: | ||
− | The <c:iterate> tag includes a delimiter attribute | + | == Problem == |
+ | The <c:iterate> tag includes a delimiter attribute which inserts a delimiter between blocks of code generated. But, if you try something like: | ||
<pre> | <pre> | ||
Line 28: | Line 29: | ||
</pre> | </pre> | ||
− | 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 | + | == Solution == |
+ | 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 inserted after this. One possibility is to make the new-line part of the delimiter itself: | ||
<pre> | <pre> |
Revision as of 09:51, 22 June 2007
Problem
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) { // ... } }
Solution
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 inserted 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.