Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Thymeleaf - The difference between th:field="${}" and th:field="*{}"

Tags:

thymeleaf

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?

like image 979
Dave Avatar asked Jun 09 '16 14:06

Dave


People also ask

What is ${} in Thymeleaf?

${} 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.

What is th field in Thymeleaf?

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" .

How do you set Thymeleaf th field value from another variable?

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; } ... }

What is Thymeleaf th 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.


Video Answer


1 Answers

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 templates
like image 198
Anand Rockzz Avatar answered Oct 07 '22 19:10

Anand Rockzz