Title: "if last in loop" tag???

Help!

It strikes me that with all the iterative 'loop' tags (block tags) within XDoclet, there must be a generic tag that checks the condition "this is the last / first / nth iteration in the loop"...  I can't find one though!

I'm writing an xdoclet template to auto-generate JUnit tests for the EJBs I'm making in my current project, and part of my template looks like this:

MyObject = new MyObject(
    <XDtEjbPersistent:forAllPersistentFields>
        TEST_<XDtMethod:methodNameWithoutPrefix/>,
    </XDtEjbPersistent:forAllPersistentFields>
);

This iterates through all persistent fields in the EJB, and for each one outputs a variable name beginning with "TEST_", and the whole thing is surrounded by "MyObject = new MyObject(.....);"  E.g. given the fields "UserId", "Colour" and "Age" - the desired output would be:

MyObject = new MyObject(TEST_UserId, TEST_Colour, TEST_Age);

So far so good.  The problem is that after each iteration the template puts a comma, including the *last* iteration - so what I actually get is the list with a comma at the end:

MyObject = new MyObject(TEST__UserId, TEST_Colour, TEST_Age , );

And this is very annoying!!  (at least the Java compiler seems to think so.. ;o)   What I'm thinking of is something like the following <XDtUtil:ifNotLast> tag to control when to include the comma in the output:

MyObject = new MyObject(
    <XDtEjbPersistent:forAllPersistentFields>
        TEST_<XDtMethod:methodNameWithoutPrefix/>
        <XDtUtil:ifNotLast>,</XDtUtil:ifNotLast>,
    </XDtEjbPersistent:forAllPersistentFields>
);

Any answers would be very much appreciated!                 

Michael O'Connor
Java Developer

Finalist IT Group
Building Your E-business Infrastructure!
-----------------------------------------
Amsterdam, The Netherlands                         
Office: +31 20 5962305 (Direct)
http://www.finalist.com/


-----------------------------

Reply via email to