1
votes

I hope someone can help me with my problem with Thymeleaf.

The case is that I need to do preprocessing with thymeleaf, the first one does it correctly, but inside that first preprocessing I need to get another field from the model, but when I add the field preprocessinf inside another preprocessing it gives me a type error

Could not parse as expression: "$ {rules ["

If I do this, it works fine

rules[__${row.index}__].propertiesValues[]

Failure to insert the other preprocessing

rules[__${row.index}__].propertiesValues[__${rules[__${row.index}__].bookingRuleDescriptor.propertyDescriptors[__${iter.index}__].name}__]

I hope you can help me.

Thank you!!

1

1 Answers

0
votes

There is only one preprocessing pass. You get that error because of the mismatched __. For example, the first time it tries to preprocess:

propertiesValues[__${rules[__${row.index}__]

The expression it tries to evaluate is __${rules[__, which is not a valid thymeleaf expression.

The options you have are:

1) If this expression is not being used in a th:field, you shouldn't be doing preprocessing anyways. You can simply use:

${rules[row.index].propertiesValues[rules[row.index].bookingRuleDescriptor.propertyDescriptors[iter.index].name]}

2) If you are using this in a th:field, you'll have to use th:with to evaluate some of your expressions before hand. Something like:

<th:block th:with="i=${row.index}, j=${rules[row.index].bookingRuleDescriptor.propertyDescriptors[iter.index].name}">
  <input type="text" th:field="*{rules[__${i}__].propertiesValues['__${j}__']}" />
</th:block>