Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG: problem with passing Number and String data type to javascript function in thymeleaf looping th:each #989

Closed
coldyoyo100 opened this issue Jan 15, 2024 · 3 comments

Comments

@coldyoyo100
Copy link

BUGS:

hi, i'm struggle with passing parameter from th:each to javascript function with combination number and string. i think this is bug, because when i'm passing with same number param, the framework could read it properly but not otherwise with string.
here's the case, let say i got 3 variable :

  1. requestId => Number
  2. requestName => String
  3. clientId => String

test 1) when insert with both same number type of data, it's work
case 1
result 1

test 2) but when combine with Number and String param, it's not working and i got error
case 2

test 3) insert same variable, but i turn 1 variable to string with single quote ( ' ' )
case 3
result 3

test4) try different approach, with combination number and string, the framework could read the string data, but not for number type data
case 4
result 4

if anyone had any solution, please help me. thx

@jmiguelsamper
Copy link
Member

Hello Coldyoyo100,

Please bear in mind that Thymeleaf, via th:onclick, only produces text, it does not process Javascript code.

I recommend two things here:

I guess the error you are seeing is a Javascript error, so it is probably related to Javascript infered types, not related to Thymeleaf.

@coldyoyo100
Copy link
Author

coldyoyo100 commented Jan 16, 2024

Dear jmiguelsamper,

yes, i know Thymeleaf only produce text, that's why in "test 1" it's work. tried already with || syntax and it got error like this,
net::ERR_INCOMPLETE_CHUNKED_ENCODING 200 (OK)
its like HTML couldn't render what thymeleaf print for onclick function, because String datatype with "& quot;"

please look at "test 4 result" , we could see the value of clientId (String)

and this is the test with || syntax
its working when both are number type data
image
image

**when change to number and string data type, it got error **

image
image

@jmiguelsamper
Copy link
Member

Hello,

When you say that IJKL is the value of clientId, it does not seem to be the case because if clientId were not null, the output would contain a dash (-). I simply think that clientId is null in your example.

Anyway, as I understand where you are coming from, the described problem is not a Thymeleaf issue. It is quite difficult to give you an actionable tip without seeing the full source code and data, I suggest to post it in a more general web development forum like Stack Overflow.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants