davisoski
davisoski

Reputation: 767

Nested loops using thymeleaf and comparative

I'm trying to convert an old code using facelets and JSF to thymeleaf and Spring, but I'm stucked in this point.

Consists in a nested List of objects. These object have lists too.

public class ContainerGrid {

    private Collection<MiGrid> gridList = new ArrayList<MiGrid>();

    //Getter/Setters
}

public class MiGrid {
    private Collection<CeldaGrid> celdaGridList;
    //Getter/Setters
}

public class CeldaGrid {
    private int valor;
    private int index;
    private String texto;
    private int fila;
    private int col;
    private String estilo;
    //Getter/Setters
}

This code create a grid correctly and give id and name the correct values.

One thing I can't be able to do with thymeleaf is two compartions like I have in id and name

USING FACELETS

<ui:repeat value="#{containergrid.gridList}" var="eachCelda">
    <tr>
        <ui:repeat value="#{eachCelda.celdaGridList}" var="celda">
            <td id="gridPrincipal-#{celda.fila}-#{celda.col}">
                    <input class="celdaGrid#{celda.estilo}" type="text" 
                            id="#{celda.texto}_#{celda.index gt 9 ? '':0}#{celda.index}#{(celda.fila+1) gt 9 ? '':0}#{celda.fila+1}"
                            name="C#{celda.texto}#{celda.index gt 9 ? '':0}#{celda.index}#{celda.fila+1 gt 9 ? '':0}#{celda.fila+1}"
                            title="#{celda.texto}#{celda.index gt 9 ? '':0}#{celda.index}#{celda.fila+1 gt 9 ? '':0}#{celda.fila+1}"
                            value="#{celda.valor}" />
            </td>
        </ui:repeat>
    </tr>
</ui:repeat>    

As a result the cells in the grid will have this values in the id:

ROW 1: C_0101 C_0201 P_0101 C_0301 C_0401 P_0201

ROW 2: C_0102 C_0202 P_0102 C_0302 C_0402 P_0202

USING thymeleaf I have created the grid correctly but I dont know how to do the second comparative in th:id

<table id="gridPrincipal">
    <tbody>
        <tr th:each="eachCelda,indexList : *{gridList}">
            <td th:each="celda,indexCelda: ${eachCelda.celdaGridList}">
                <input type="text"
                th:id="__${indexCelda.index}__ > 9 ? __${celda.texto}____${celda.index}__:__${celda.texto}__0__${celda.index}__"
                th:field="*{celdaGridList[__${indexCelda.index}__].valor}" />
            </td>
        </tr>
    </tbody>
</table>

I would like to add a second comparative like I did using facelets or doing in another way.

Any idea?

Thanks

Upvotes: 0

Views: 279

Answers (1)

Metroids
Metroids

Reputation: 20487

I think it should look like this:

th:id="${celda.texto + (indexCelda.index > 9 ? '' : '0') + indexCelda.index + (celda.fila+1 > 9 ? '' : '0') + (celda.fila+1)}"

Upvotes: 1

Related Questions