Use single quote or double quote for strings in EL
Asked Answered
H

1

13
<ui:repeat value="#{coreGridBean.heroBeanList}" var="hero"
    offset="0" step="1" size="#{hero.size}" varStatus="status">
    <tr class="#{status.even ? 'evenColumn' : 'oddColumn'}">
        <td>#{status.index}</td>
        <td>#{hero.id}</td>
        <td>#{hero.race}</td>
        <td>#{hero.name}</td>
    </tr>
</ui:repeat>

I wonder whether the usage of class="#{status.even ? 'evenColumn' : 'oddColumn'}" is correct.

I feel a bit guilty of using single quotes instead of double quotes. But in this case, double quote fails, single quote wins.

Hirz answered 7/1, 2011 at 17:6 Comment(1)
You could also use outer single quotes and then use double quotes for the Strings. class='#{status.even ? "evenColumn" : "oddColumn"}'Safford
G
16

It's perfectly fine. It's also the convention I use: single quotes for strings in EL. It's not only better readable, but it's also friendly for syntax highlighting.

Using double quotes is valid, but harder to interpret when nested in a HTML attribute which is by itself also double quoted.

Glycogenesis answered 7/1, 2011 at 19:0 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.