I have encounter the same problem using textEditor PrimeFaces element.
I use the following html code.
<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>
The TextArea is defined twice so that when form is displayed, the user see only the first <div> widget without seeing a specific toolbar.
When user click on text displayed, the focusin() event hide the <div class="div-focus"> element and display the <p:textEditor> widget contained in <div class="text-editor"> parent element.
To do that, I have 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 page is loaded and is used to hide <div class="text-editor> element and to defined focusin() and focusout() events.
The focusin() event hide <div class="div-focus"> element and display <div class="text-editor"> element. When the user clicks on text in <div class="div-focus"> element, this element is hidden and the following hidden element is display. The <div class="text-editor"> element gains focus.
The focusout() event hide <div class="text-editor"> element and display <div class="div-focus"> element ... only when element that gains focus is not defines in <div class="text-editor"> element.
The problem with element.focusout() is that it is triggered each time an element included in main element even if element that gains focus is defined in same element.
When you enter in a house, you can enter passing by garage or living room or kitchen.
When you enter in living room (by external door), you enter in the building.
But when you quit living room to kitchen, you stay in house !!!
If you quit living room to go in garden, you quit the house (building).
focusin() function implement the same principe, but not focusout() !
if ($(e.relatedTarget).closest(".text-editor").size() == 0) line used in focusout() event correct this little difference !
CAUTION: the solution is not perfect because I have some little problems to solve when copying text from textEditor widget to outputText widget without formatting !