Tag attributes not being refreshed after AuthorDocumentController.setAttribute

Having trouble deploying Oxygen XML Web Author? Got a bug to report? Post it all here.
vitorhugovm
Posts: 36
Joined: Fri Jan 26, 2024 3:31 pm

Tag attributes not being refreshed after AuthorDocumentController.setAttribute

Post by vitorhugovm »

Hello!

I have an element that carries attributes representing a day of the calendar (day, month, year). They must be updated every time the user saves the document.
So I tried to intercept it using editorAboutToBeSavedVeto inside an extension of WSEditorListener class of the Java API.
When I update the element using AuthorDocumentController.setAttribute or AuthorDocumentController.setMultipleAttributes, the attributes are updated successfully, but only in the background. At the element tag, that shows the attributes, I still see the old values.
I tried to use AuthorEditorAccess.refresh(AuthorNode) after the update and it didn't work.
How could I solve this?

Thanks!
Vitor
mihaela
Posts: 519
Joined: Wed May 20, 2009 2:40 pm

Re: Tag attributes not being refreshed after AuthorDocumentController.setAttribute

Post by mihaela »

Hello,

Can you update the attributes every time the user makes changes in the document or it is necesssary to only change them on save?
If the answer is yes, you can create a plugin that uses an AuthorDocumentFilter[1] to update the the attributes on each change made in the document.
See the javadoc of the filter class about implementation details.

We have a sample plugin that uses an AuthorDocumentFilter, maybe you can use it as a starting point:
https://github.com/oxygenxml/web-author ... g-comments

[1] https://www.oxygenxml.com/InstData/Edit ... ilter.html

Best Regards,
Mihaela
Mihaela Calotescu
http://www.oxygenxml.com
vitorhugovm
Posts: 36
Joined: Fri Jan 26, 2024 3:31 pm

Re: Tag attributes not being refreshed after AuthorDocumentController.setAttribute

Post by vitorhugovm »

Hello Mihaela!

I tried your solution and the changes were applied also to the view, so it worked well!

Although, when I overwrote the setAttribute function of AuthorDocumentFilter, I saw and confirmed the risk of falling into a loop if you edit the attributes of the element that is going to be updated in the new function.
In this case it happens if I manually select a number for the day attribute, for example.
This forced me to include a validation before calling the update function. I think this could be problematic some day in the future for code maintenance.

I still think that doing the update when saving the document would be a better and cleaner solution.
Why exactly is the AuthorDocumentController.setAttribute action reflected in the screen when executed inside AuthorDocumentFilter, but not when it's inside WSEditorListener?

Thank you!
Vitor
mihaela
Posts: 519
Joined: Wed May 20, 2009 2:40 pm

Re: Tag attributes not being refreshed after AuthorDocumentController.setAttribute

Post by mihaela »

Hello,

How do you set the attribute value? if you are using the AuthorDocumentController to set the attributes, you should change to calling the super methods. See the AuthorDocumentFilter documentation [1]:
Warning: Subclasses should NOT call back into the AuthorDocumentController for modifications in the document instead call into the superclass or the AuthorDocumentFilterBypass!
https://www.oxygenxml.com/InstData/Edit ... ilter.html

Best Regards,
Mihaela
Mihaela Calotescu
http://www.oxygenxml.com
Post Reply