[Building Sakai] Adding wyswig editor to JSP form

Noah Botimer botimer at umich.edu
Tue Sep 20 13:38:13 PDT 2011


This is all pretty much correct. Thanks, Matt and Charles.

The "old" (pre-2.8) method of loading the RTE varied based on what UI technology you were using. For example, the velocity and jsf modules have support to load/launch the editor. There is effectively no utility library for JSP apps, which is why you'll see some tools checking "wysiwyg.editor" and using editor-specific code in the tool. Other places like OSP and Samigo also have specific code.

The "new" (2.8+) support is incorporated into the portal so that all you typically need to do is call sakai.editor.launch(textarea, config) via JavaScript (however that should be done with your UI technology). The legacy macros (chef_setuptextarea), tags (sakai:inputRichText) have been changed over to emit the new JavaScript so existing tool code did not need to change (and velocity/jsf no longer use editor-specific code).

The reason this works is that anything that renders through /portal/tool/ automatically gets the right editor loaded in the frame head.

So, if your tool is running through the Tool Portal, you should not have to do anything but call sakai.editor.launch. If, for some reason, your tool content is not being inserted into the Tool Portal markup, you have a couple of options. (Paul, are you not running inside the Tool Portal for some reason?)

As Matthew notes, the Editor Registry and related stuff was added to portal. Not because it was the perfect place, but because it was a common place and portal needed to use it. The PortalService is available from tool code easily, and the way OSP uses it can be modeled in your code (as linked by Matthew).

The other option is to use the static URLs /sakai-editor/editor-bootstrap.js, /sakai-editor/editor.js, and /sakai-editor/editor.launch.js in the head of your pages. Each can use a placement ID parameter (editor.js?placement=123-456). These URLs will redirect to the right scripts for the system/site/user. Though they are convenient, they do result in extra HTTP requests, so the server-side method is preferred.

Charles is also right that this technique is only 2.8+. If you want to target 2.7 and 2.8+ with the same code, you will have to do some other tricks.

This discussion does remind me that the complete script tags (head matter) should be available to tools so we don't replicate the code (and OSP and portal should use it). It also reminds me that there should be more documentation than is in place:

https://confluence.sakaiproject.org/display/SAKDEV/CKEditor+Integration

Hope this helps. Don't hesitate to ask for more help.

Thanks,
-Noah

On Sep 20, 2011, at 3:22 PM, Matthew Jones wrote:

> Right, the "Editor Registry" was added as part of CKEditor and is only available in 2.8+ (SAK-17880). In versions prior to 2.8, you'll only *really* be supporting FCKEditor even though the property
> wysiwyg.editor was available since at least 2.2.
> 
> Using this function will also get you any registry overridden via a site property "wysiwyg.editor", saving some code. And you'll need to detect one or another. (http://goo.gl/50jKt)
> 
> Since 2.7 is basically near EOL I'm guessing that this won't be backported, but if you still need to support 2.7, you'll have to do something else, probably hardcoded as you have, as Charles mentioned.
> 
> Thanks!
> 
> On Tue, Sep 20, 2011 at 2:47 PM, Charles Hedrick <hedrick at rutgers.edu> wrote:
> I don't see this function in the 2.7.1 version of PortalService. If your code needs to work on 2.7 you need a different approach. 
> 
> On Sep 20, 2011, at 1:42 PM, Matthew Jones wrote:
> 
>> The only thing you might need to worry about with this is that the user change change their editor from fck to the now default for 2.9 (ckeditor). This would always launch the fckeditor.
>> 
>> There's a function in the portalService api to get the active Editor.  
>> 
>> http://source.sakaiproject.org/release/2.8.0/apidocs/org/sakaiproject/portal/api/PortalService.html#getActiveEditor()
>> 
>> You can then build up the appropriate scripts from editor to deal with this:
>> http://source.sakaiproject.org/release/2.8.0/apidocs/org/sakaiproject/portal/api/Editor.html
>> 
>> This *possibly* should be somewhere other than portal, but everyone has to have portal, right? ;)
>> 
>> It *looks* like the commit against osp uses this to build up the javascript needed to dump this into a jsp: http://goo.gl/8vVhc
>> 
>> Hope this is somewhat accurate!
>> 
>> On Tue, Sep 20, 2011 at 3:32 AM, Paul Mungai <paulwando at gmail.com> wrote:
>> Its worked.
>> 
>> One also needs to add these scripts on the header section;
>> 
>> <script type="text/javascript" language="JavaScript" src="/library/editor/FCKeditor/fckeditor.js"></script>
>> <script type="text/javascript" language="JavaScript" src="/library/editor/fckeditor.launch.js"></script>
>> 
>> Unfortunately, there is no documentation that the search engine could lead to, that explains this.
>> 
>> 
>> On Tue, Sep 20, 2011 at 9:28 AM, Paul Mungai <paulwando at gmail.com> wrote:
>> Kindly advise on what scripts I need to add to load the editor on a text area.
>> 
>> I have added this script on the body section after the textarea whose name & id is cdesc
>> 
>> <script type="text/javascript" defer="1">sakai.editor.launch('cdesc', { height: 650, width: 400 });</script>
>> 
>> -- 
>> Regards,
>> Paul Mungai
>> 
>> "Ability is what youre capable of doing. Motivation determines what you do. Attitude determines how well you do it" By Lou Holtz, Notre Dame Football Coach
>> 
>> 
>> 
>> -- 
>> Regards,
>> Paul Mungai

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://collab.sakaiproject.org/pipermail/sakai-dev/attachments/20110920/2fc557d2/attachment.html 


More information about the sakai-dev mailing list