Nwn
Nwn

Reputation: 571

Thymeleaf not recognized my field get method

I have a thymeleaf form and spring boot back-end. I have a model class which has defiened it's getters and setters little bit deferent name. so when Im going to take that model and get its fields as form input fields thymeleaf can not recognised them as fields.

here is my modal,

public class scDto {
    private Integer region;
    private boolean isAmt;

    public scDto() {
    }

    public Integer getRegion() {
        return this.region;
    }

    public void setRegion(Integer region) {
        this.region = region;
    }

    public boolean isAmt() {
        return this.isAmt;
    }

    public void setAmt(boolean amt) {
        this.isAmt = amt;
    }

here is my form input field,

 <input type="text" th:field="*{sc.isAmt}"/>

here is the error,

 Error during execution of processor 'org.thymeleaf.spring4.processor.attr.SpringInputGeneralFieldAttrProcessor' (price:331)

Form is working well for region field. but it does not work for Amt field. Maybe I can fix this if I changed isAmt() get method to getIsAmt(). But I cant change any method name of the modal class because that class already compiled and I used it via a jar file. Is there anyway to solve this problem.

Upvotes: 2

Views: 1166

Answers (2)

Ruslan K.
Ruslan K.

Reputation: 142

(Copied from the comments under the question)

I guess you can try to refer to this variable using the {sc.amt}. More information about the javabeans notation you can read here: stackoverflow.com/a/17066599/7629196

Upvotes: 1

MyTwoCents
MyTwoCents

Reputation: 7624

Seeing your DTO it has only 2 fields

public class scDto {
    private Integer region;
    private boolean isAmt;

    public boolean isAmt() {
        return this.isAmt;
    }

...

}

As per convention

For method name like this

boolean isXyz()

you will read it like xyz

So this line

 <input type="text" th:field="*{sc.isAmt}"/>

should be

  <input type="text" th:field="*{sc.amt}"/>

Credit also goes to Ruslan K for mentioning this in Comment. Just adding to add more clarity.

Upvotes: 0

Related Questions