This content has been marked as final.
Show 2 replies
-
1. Re: fck-faces/FCKEditor: Executing javascript before the aja
juanignaciosl Jun 14, 2007 5:15 AM (in response to carlabramsson)I've solved connecting once form's onsubmit with a function that calls FCKeditorAPI.GetInstance('${id}').UpdateLinkedField(). I think this is a clean enough way, and you can encapsulate it into a facelets component.
<a4j:outputPanel ajaxRendered="true"> <f:verbatim> <script type="text/javascript"> function alertar() { if(dojo.byId('${id}') != null) { FCKeditorAPI.GetInstance('${id}').UpdateLinkedField(); return true; }; }; if(!dojo.byId('${id}___Frame')) { dojo.event.connectOnce(dojo.byId('${id}').form, 'onsubmit', 'alertar'); var oFCKeditor = new FCKeditor( '${id}' ) ; oFCKeditor.BasePath = '${contexto}/scripts/fckeditor/' ; oFCKeditor.ToolbarSet = 'Basic'; oFCKeditor.ReplaceTextarea() ; } </script> </f:verbatim> </a4j:outputPanel>
-
2. Re: fck-faces/FCKEditor: Executing javascript before the aja
carlabramsson Jun 15, 2007 4:38 AM (in response to carlabramsson)Thanks for the pointer! I was wrong at first, a a4j submit triggers the onsubmit event of the form after all. So then it was quite easy to build a component that takes care of this event wiring and syncing the formvalue with the fckeditor! This is what is looks like in my code now:
<hmjsf:a4jFckSupport> <fck:editor id="richeditor" value="#{example.myString}" /> </hmjsf:a4jFckSupport>
That's clean! ;-)
The magic is in the encodeEnd method in my components renderer:String fckEditorClientId = getFckEditorClientId(context,component); if(fckEditorClientId != null && !"".equals(fckEditorClientId)) { ResponseWriter writer = context.getResponseWriter(); writer.startElement("script", component); writer.writeAttribute("type", "text/javascript", "type"); writer.write("function wireA4jfckSupport(clientId) {\n" + " var prevHandler = document.getElementById(clientId).form.onsubmit;\n" + " document.getElementById(clientId).form.onsubmit = function() {\n" + " FCKeditorAPI.GetInstance(clientId).UpdateLinkedField();\n" + " if(prevHandler) { prevHandler(); }\n" + " }\n" + " }"); writer.write("wireA4jfckSupport('"+fckEditorClientId+"')"); writer.endElement("script"); }
Only problem now is to push a server generated value into the editor after a a4j-action...