Menu

if-elseif conditions

2019-09-19
2019-09-23
  • Miroslav Kosec

    Miroslav Kosec - 2019-09-19

    Hello,
    wanted to ask if there's any way to apply multiple jt:if tags for cell. What I am trying to do is that i have forEach loop to insert list of values into row. When inserting I need to check indexVar and based on it's value then set formatting. for example 1st cell will have color1, 2nd will have color2, 3rd color3 and so on.

     

    Last edit: Miroslav Kosec 2019-09-19
  • Etienne Canaud

    Etienne Canaud - 2019-09-20

    Hi Miroslav,

    This is likely the issue already described here:

    https://sourceforge.net/p/jett/tickets/10/

    I assume this issue is not fixed. Maybe you can write more details in the above issue to help Randy reproduce the problem.
    He also provided a workaround in the ticket, where you can write your code in a JEXL block in the style="${your code goes here}" . I this this should work for you, let me know if you meet any problem getting something that works.

     

    Last edit: Etienne Canaud 2019-09-20
  • Miroslav Kosec

    Miroslav Kosec - 2019-09-20

    Thanks for reply,
    first off, I am familiar with that post you linked above, this example seems not to be valid :
    < jt:style style="bottom-border-color:${(index == 0) ? color : color2}"/ >
    As I understand jt:style tags cant be bodyless. Based on that post, I have tried this:
    <jt:style style="border-left:${(index == 0) ? medium : thin}">${item}</jt:style>
    but nothing got formatted according that JEXL condition block. Could you provide some specific example that you are sure it works? For example what I have in my example: If index equals 0, then left border is formatted medium, else thin.

    Thanks

     

    Last edit: Miroslav Kosec 2019-09-20
  • Etienne Canaud

    Etienne Canaud - 2019-09-23

    This code works for me:

    <jt:forEach items="${items}" var="item" indexVar="index"> 
    <jt:style style="font-color: ${index % 2 == 0 ? 'red' : 'blue'}">
    ${item} / ${index}  
    </jt:style>
    </jt:forEach>
    

    You should ensure that your JEXL code should return a string; in your second piece of code, "medium" and "thin" don't have any quotes, so unless you've defined some variables with these names they will be undefined.

    So it should be <jt:style style="border-left:${(index == 0) ? 'medium' : 'thin'}">${item}</jt:style> (note the single quotes).

     

Log in to post a comment.