question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Custom dialect missing attributes

See original GitHub issue

Hi, I am creating a custom tags using thymeleaf 3. Initially it is created in thymeleaf 2, but since we are upgrading to versioin 3 we need to rewrite our current custom tags.

We had some issue related to th:field attributes (and other th:* commands). Upon accessing the custom element itself the supposed generated name and value field from th:field is not there or even a th:field itself. Our custom tag has higher precedence than the th:* tags as we would like to retrieve the generated value. Below is from our logs:

HTML <extra:file th:document="${document}" th:field="*{regFile}" class="form-control" th:text="${docId}"></extra:file>

LOGS

_This part is retrieved from the ITemplateContext.getElementStack -_
FileTagProcessor.doProcess:101 - getElementCompleteName---------------------------->extra:file
FileTagProcessor.doProcess:106 - getAttributeMap: {th:document=${document}, th:field=*{regFile}, class=form-control, th:text=${docId}} 

_This is retrieved from IProcessableElementTag_
FileTagProcessor.doProcess:109 - getAttributeMap: {document={&quot;docTypeId&quot;:180,&quot;docDesc&quot;:{&quot;en&quot;:&quot;Upload File&quot;},&quot;order&quot;:1,&quot;type&quot;:&quot;image/gif, image/jpeg, image/png, application/pdf&quot;,&quot;size&quot;:1000000,&quot;compulsary&quot;:true,&quot;dimensionCompulsary&quot;:false}, class=form-control} - {} 
FileTagProcessor.doProcess:112 - IAttribute---------------------------->document="{&quot;docTypeId&quot;:180,&quot;docDesc&quot;:{&quot;en&quot;:&quot;Upload File&quot;},&quot;order&quot;:1,&quot;type&quot;:&quot;image/gif, image/jpeg, image/png, application/pdf&quot;,&quot;size&quot;:1000000,&quot;compulsary&quot;:true,&quot;dimensionCompulsary&quot;:false}"
FileTagProcessor.doProcess:112 - IAttribute---------------------------->class="form-control"
FileTagProcessor.doProcess:116 - label: {"docTypeId":180,"docDesc":{"en":"Upload File"},"order":1,"type":"image/gif, image/jpeg, image/png, application/pdf","size":1000000,"compulsary":true,"dimensionCompulsary":false}
FileTagProcessor.doProcess:120 - label: 180

Extra Dialect precedence is 100000 File Tag precedence is 2147483647

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
ultraqcommented, Aug 29, 2021

Ah, yes having a higher precedence than the standard dialect will mean you miss out on seeing things like th:field in its raw state 🤔

Some workarounds that I can think of:

  • create a separate dialect with a lower value than the standard dialect, which then that contains the processor you want to see the th:field value
  • create another processor that can be included on a parent HTML element, like the <form>, and then search through all of its input elements to find the th:field attributes you want to work with
1reaction
ultraqcommented, Nov 3, 2020

my expectation is it will generate the corresponding attribute id and name generated by th:field

So th:field will do that, but it’ll have to be on an HTML input element that it knows about, not a custom one like <extra:file>.

Given this, one option to try is to change from using a custom element to a custom attribute, use an HTML input element so that th:field can add the id and name as it normally would, then your attribute processor can read those values from the element after, eg:

<input type="file" th:field="*{regFile}" ... extra:file>

(I can’t remember if you can have custom attributes without values. If not, then making it extra:file="" should fix that up.)

th:field will recognize <input type="file"> and add the appropriate id and name attributes, then your extra:file attribute processor can read them from the input element.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Thymeleaf custom dialect with fragments: how to keep th
I'm creating a custom dialect that replaces <myprefix:mytag> with a <div th:replace="myTagFragment::myfrag"> and it works with no attributes or ...
Read more >
Creating Custom Hibernate Dialect - DEV Community ‍ ‍
So let's see, how to create our own Hibernate dialect to be able to use similarity function in HQL or Criteria Queries.
Read more >
How to Extend Thymeleaf with dialects - Educative.io
The process is simple: create a dialect; add it to the template engine; we'll be able to make use of it. ... true,...
Read more >
Tutorial: Extending Thymeleaf
Solution: create a Thymeleaf dialect with the tags or attributes you ... of the th:object attribute, but custom processors can do it too....
Read more >
[RFC] mlir::FloatAttr and legal types - LLVM Discourse
These MLIR types are closed and incapable of representing dialect Foo's constants, attributes, or types. Since the goal is to lower the Foo...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found