1

I am sticking a value into a hidden input with Thymeleaf and keep getting an error that says Caused by: org.attoparser.ParseException: Exception evaluating SpringEL expression: "receiptInquirySearchForm.cardNumber?:''" (template: "results.html" - line 14, col 44)
I have tried putting the ? after receiptInquirySearchForm, after cardNumber, and after both. I keep getting that same error on that line.

Here is line 14:

<input type="hidden" name="cardNumber" data-th-value="${receiptInquirySearchForm.cardNumber?}" />

Now I know receiptInquirySearchForm is a valid non-null object because I have several other hidden inputs that do not throw errors.

<input type="hidden" name="tokenId" data-th-value="${receiptInquirySearchForm.tokenId}" />
<input type="hidden" name="accountNumber" data-th-value="${receiptInquirySearchForm.accountNumber}" />
<input type="hidden" name="sku" data-th-value="${receiptInquirySearchForm.sku}" />

When I change the data-th-value from cardNumber to tokenId, it gets past that block of hidden inputs so every other line works fine.

UPDATE
I found another more descriptive error message down below.
Caused by: org.springframework.expression.spel.SpelEvaluationException: EL1008E: Property or field 'cardNumber' cannot be found on object of type '...web.form.ReceiptInquirySearchForm' - maybe not public or not valid?

How can I check for that in the code? I know sometimes it will be there, but apparently in this instance it is not.

They were doing this in Velocity like this:

<input type="hidden" name="cardNumber" value="$!receiptInquirySearchForm.cardNumber" />

The exclamation correctly handled the possible missing or null cardNumber.

3
  • You're probably missing public getters/setters for the field cardNumber. Unless you really are passing different classes for receiptInquirySearchForm (which sometimes have getters and setters for cardNumber and sometimes don't -- which would be pretty weird.)
    – Metroids
    Aug 24, 2018 at 14:51
  • On a previous page, the user can select "credit card" or "check" and then it takes them to the appropriate page to fill in the details. When they submit, both pages bring them to the same results page. Obviously the credit card page will bring the card number and the checking page will bring routing and account number. I'm guessing I need to send blank numbers in for cardNumber when checking and vice versa?
    – dmikester1
    Aug 24, 2018 at 14:56
  • So turns out that was an old field we are no longer using so it was never being set in the controller. So I will just remove it and proceed. Still would be nice to know if there is a way that Thymeleaf could account for this possibility.
    – dmikester1
    Aug 24, 2018 at 15:28

1 Answer 1

2

Just as @Metroids pointed out, you are probably missing getters/setters for the field cardNumber especially a getter for it. If you have a getter for it, check that the getter follows the POJO convention and is public like so;

public int getCardNumber() { return cardNumber; }

If the spelling is not like so getCardNumber(), even though you can call the method in the controller to get the value, thymeleaf cannot do so because it relies on POJO convention to be able to call variable properties. I hope this helps.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.