AuthorDocumentController.findNodesByXPath returning null after first use
Having trouble deploying Oxygen XML Web Author? Got a bug to report? Post it all here.
-
- Posts: 31
- Joined: Fri Jan 26, 2024 3:31 pm
AuthorDocumentController.findNodesByXPath returning null after first use
Post by vitorhugovm »
Hello!
I'm using a custom renderer called by webappRendererClassName property in CSS.
In two particular element renderers, I need to get attributes values from another element, which I find by using AuthorDocumentController.findNodesByXPath.
When it passes through the first element render, everything goes fine, the element is located and the rest of the function runs normally.
The second render occurs just after the first one, it's a sibling element and it's utilizes the same custom renderer as the first one. The problem is that when it gets to findNodesByXPath function, searching for the same node from before, it returns null.
For instance, there is a function inside this renderer that inserts text in the current element, in addition to rendering some content.
I get the AuthorDocumentController from AuthorInplaceContext.getAuthorAccess().getDocumentController() received by renderControl function in the custom WebappFormControlRenderer.
The context for findNodesByXPath is not specified, what I believe makes it use the root element as context.
What could be happening?
Thanks!
Vitor
I'm using a custom renderer called by webappRendererClassName property in CSS.
In two particular element renderers, I need to get attributes values from another element, which I find by using AuthorDocumentController.findNodesByXPath.
When it passes through the first element render, everything goes fine, the element is located and the rest of the function runs normally.
The second render occurs just after the first one, it's a sibling element and it's utilizes the same custom renderer as the first one. The problem is that when it gets to findNodesByXPath function, searching for the same node from before, it returns null.
For instance, there is a function inside this renderer that inserts text in the current element, in addition to rendering some content.
I get the AuthorDocumentController from AuthorInplaceContext.getAuthorAccess().getDocumentController() received by renderControl function in the custom WebappFormControlRenderer.
The context for findNodesByXPath is not specified, what I believe makes it use the root element as context.
What could be happening?
Thanks!
Vitor
-
- Posts: 513
- Joined: Thu Sep 04, 2014 4:22 pm
Re: AuthorDocumentController.findNodesByXPath returning null after first use
Post by cristi_talau »
Hello,
The findNodesByXPath function has a version [1] that receives a context node. If you do not specify the context, it uses the document element.
You mentioned that there is a function in the renderer that inserts text in the document. Does that mean that while rendering you also alter the document? If yes, you should try to find a different solution, because the changes you make during rendering are not reliably reflected in the browser.
Also, notice that if your rendering depends on a sibling element, when that element is modified, the element with the form control will not automatically re-render. You have to use AuthorEditorAccess.refresh(node) (from an AuthorDocumentListener for example) to make sure it re-renders.
If you think there is a bug in the application, please submit a minimal plugin that helps us reproduce your situation using our technical support form: https://www.oxygenxml.com/techSupport.html . Both source code and a compiled plugin will be useful.
Best,
Cristian
[1] https://www.oxygenxml.com/InstData/Edit ... n,boolean)
The findNodesByXPath function has a version [1] that receives a context node. If you do not specify the context, it uses the document element.
You mentioned that there is a function in the renderer that inserts text in the document. Does that mean that while rendering you also alter the document? If yes, you should try to find a different solution, because the changes you make during rendering are not reliably reflected in the browser.
Also, notice that if your rendering depends on a sibling element, when that element is modified, the element with the form control will not automatically re-render. You have to use AuthorEditorAccess.refresh(node) (from an AuthorDocumentListener for example) to make sure it re-renders.
If you think there is a bug in the application, please submit a minimal plugin that helps us reproduce your situation using our technical support form: https://www.oxygenxml.com/techSupport.html . Both source code and a compiled plugin will be useful.
Best,
Cristian
[1] https://www.oxygenxml.com/InstData/Edit ... n,boolean)
-
- Posts: 31
- Joined: Fri Jan 26, 2024 3:31 pm
Re: AuthorDocumentController.findNodesByXPath returning null after first use
Post by vitorhugovm »
Hello Cristian!
Actually, I've found a solution to the problem!
The rendering call for the second element was being executed, but had a null return when passing through findNodesByXPath function.
I assumed that the context for the function would be the root element when sending null as context, which is true at the beginning as the document was being opened while the rendering was occurring and this function uses the element at caret position when context equals null.
What I think was happening is that when I inserted some content inside the first element, the caret position probably changed too, so when it passed through the second element, the context for the XPath find changed, then it wouldn't find anything.
To solve the issue, I explicitly sent the root element as context to the function, getting it by the AuthorDocumentController. After this modification everything worked just fine.
Thanks for the response!
Vitor
Actually, I've found a solution to the problem!
The rendering call for the second element was being executed, but had a null return when passing through findNodesByXPath function.
I assumed that the context for the function would be the root element when sending null as context, which is true at the beginning as the document was being opened while the rendering was occurring and this function uses the element at caret position when context equals null.
What I think was happening is that when I inserted some content inside the first element, the caret position probably changed too, so when it passed through the second element, the context for the XPath find changed, then it wouldn't find anything.
To solve the issue, I explicitly sent the root element as context to the function, getting it by the AuthorDocumentController. After this modification everything worked just fine.
Thanks for the response!
Vitor
-
- Posts: 513
- Joined: Thu Sep 04, 2014 4:22 pm
Re: AuthorDocumentController.findNodesByXPath returning null after first use
Post by cristi_talau »
Hello,
I am glad you managed to find a solution.
Best,
Cristian
I am glad you managed to find a solution.
Best,
Cristian
Jump to
- Oxygen XML Editor/Author/Developer
- ↳ Feature Request
- ↳ Common Problems
- ↳ DITA (Editing and Publishing DITA Content)
- ↳ SDK-API, Frameworks - Document Types
- ↳ DocBook
- ↳ TEI
- ↳ XHTML
- ↳ Other Issues
- Oxygen XML Web Author
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Content Fusion
- ↳ Feature Request
- ↳ Common Problems
- Oxygen JSON Editor
- ↳ Feature Request
- ↳ Common Problems
- Oxygen PDF Chemistry
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Feedback
- ↳ Feature Request
- ↳ Common Problems
- Oxygen XML WebHelp
- ↳ Feature Request
- ↳ Common Problems
- XML
- ↳ General XML Questions
- ↳ XSLT and FOP
- ↳ XML Schemas
- ↳ XQuery
- NVDL
- ↳ General NVDL Issues
- ↳ oNVDL Related Issues
- XML Services Market
- ↳ Offer a Service