I can't find on the tutorial the difference between this two instructions.
th:field="${something}" and th:field="*{something}"
Can anyone show me some example?
${} used for variable expressions. Variable expressions are OGNL expressions –or Spring EL if you're integrating Thymeleaf with Spring. *{} is used for selection expressions. Selection expressions are just like variable expressions, except they will be executed on a previously selected object.
Thymeleaf provides a special attribute th:field responsible for binding input fields with a property in the bean class. This attribute behaves differently depending on whether it is attached to. Thymeleaf supports all-new input types introduced in HTML5 such as type="color" or type="datetime" .
You can also change the value in the controller, just make a Java object from $client.name and call setClientName. public class FormControllModel { ... private String clientName = "default"; public String getClientName () { return clientName; } public void setClientName (String value) { clientName = value; } ... }
th:name => This would be the name of the value that you will be either passing to another page (Exemplar scenario). th:value => This would be the actual value that you would be passing.
Reference site
Five types:
${...}
: Variable expressions. These are OGNL expressions (or Spring
EL if you have spring integrated)
*{...}
: Selection expressions. Same as above, excepted it will be executed on a previously selected object only
#{...}
: Message (i18n) expressions. Used to retrieve locale-specific messages from external sources
@{...}
: Link (URL) expressions. Used
to build URLs ~{...}
: Fragment expressions. Represent fragments of
markup and move them around templatesIf you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With