I ran into the same problem using the textEditor PrimeFaces element.
I am using the following HTML.
<div contenteditable="true" class="div-focus"> <h:outputText styleClass="OutputField" value="#{oController.panelTpl.getComment()}" escape="false" /> </div> <div class="text-editor"> <p:textEditor value="#{oController.panelTpl.txtComment.text}" /> </div>
TextArea is defined twice, so when the form is displayed, the user sees only the first <div> widget, without seeing a specific toolbar.
When the user clicks on the displayed text, the focusin () event hides the <div class = "div-focus"> and display the <p: textEditor> widget contained in the <div class = "text-editor"> parent element.
For this, I defined the following javascript code
function onLoadDialog() { jQuery(".text-editor").hide(); jQuery(".div-focus").focusin(function() { $(this).hide(); $(this).next(".text-editor").show(); $(this).next(".text-editor").focus(); }); jQuery(".text-editor").focusout(function(e) { if ($(e.relatedTarget).closest(".text-editor").size() == 0) { $(this).hide(); $(this).prev(".div-focus").show(); $(this).prev(".div-focus").text($(this).text()); } }); }
The onLoadDialog () function is called when the page loads and is used to hide the <div class = "text-editor> element and certain focusin () and focusout () events.
Event focusin () hide the <div class = "div-focus"> element and display the <div class = "text-editor"> element. When the user clicks on the text in the <div class = "div-focus"> element, this element is hidden and the next hidden element is displayed. Text editor <div class => focus elements.
Event focusout () hide <div class = "text-editor"> element and display <div class = "div-focus"> element ... only when the element that receives focus is not defined in <div class = " text-editor "> element.
The problem with element.focusout () is that it runs every time an element is included in the main element, even if the element receiving focus is defined in one element.
When you enter the house, you can enter the garage or living room or kitchen. When you enter the living room (through the external door), you enter the building. But when you leave the living room to the kitchen, you stay at home! If you leave the living room to go to the garden, you will leave the house (building).
The focusin () function implements the same principle, but not focusout ()!
if ($ (e.relatedTarget) .closest (". text-editor"). size () == 0) the line used in the focusout () event fixes this small difference!
CAUTION: The solution is not perfect, because I have some small problems that need to be solved when copying text from the textEditor widget to the outputText widget without formatting!