I've added TinyMCE on a website (JSF-2, Tomcat 7, Mojarra 2.1.6). When a user clicks on a 'refresh' button the html text inside the editor is parsed and printed somewhere else on the page.
I have to turn off TinyMCE before the Ajax request (otherwise I will end up with two editors). This is also recommended in the TinyMCE documentation.
So I added an f:ajax event to the button:
the javascript functions are called properly:
function cleanupRte() {
tinyMCE.triggerSave();
return true;
}
and the onevent method:
function disposeTinyMce(e) {
if(e.status == 'begin') {
tinyMCE.triggerSave();
var elem = document.getElementById("mainForm:rteExtAdr:input");
alert(elem.value);
tinyMCE.execCommand('mceRemoveControl', false, 'mainForm:rteExtAdr:input');
}
if(e.status == 'complete') {
}
if(e.status == 'success') {
tinyMCE.execCommand('mceAddControl', false, 'mainForm:rteExtAdr:input');
}
return true;
}
which disables the editor and adds it back to the page. This is working fine.
The problem is the model is not updated with the value from the textfield although the alert shows the correct value. The request also contains the 'old' value from the textfield.
Is there something that would prevent the ajax call to see the current form values?
or does it read the values before it executes the onevent function?
If I remove the f:ajax tag completely the model is updated but then I have the issues with the TinyMce editor getting duplicated after the response.
the init call:
tinyMCE.init({
mode : "textareas",
theme : "advanced",
editor_selector : "sesamWysiwyg",
language : "de",
force_br_newlines : true,
force_p_newlines : false,
inline_styles : false,
forced_root_block : '', // Needed for 3.x
plugins : "autolink,lists,style,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,searchreplace,print,paste,directionality,noneditable,visualchars,nonbreaking,xhtmlxtras,wordcount,advlist",
formats : {
underline : {inline : 'u', exact : true},
strikethrough : {inline : 'del', exact : true}
},
theme_advanced_buttons1 : "bold,underline,strikethrough,|,cut,copy,paste,pastetext,pasteword,search,replace,|,undo,redo,|,code,removeformat,|,charmap",
theme_advanced_buttons2 : "",
theme_advanced_buttons3 : "",
theme_advanced_buttons4 : "",
theme_advanced_toolbar_location : "top",
theme_advanced_toolbar_align : "left",
content_css : "css/content.css",
});
Any ideas or suggestions would be great!
thanks :)