Solving problems with CKEditor in 9.0.1FP1 and/or FP2

// Java code to define a map containing some configuration strings for the Dojo stuff
package org.openntf.xsp.dojo;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
import com.ibm.xsp.context.DojoLibrary;
public class Config implements Serializable {
	private static final long serialVersionUID = -5429830701050906773L;
	private final Map<String, String> config;
	public Config() {
		this.config = new HashMap<String, String>();
		DojoLibrary dojolib = com.ibm.xsp.context.DojoLibraryFactory.getDefaultLibrary();
		
		// get the current version of Dojo
		config.put("version", dojolib.getVersion().toString());
		// get the keyword for setting toolbar options
		config.put("toolbartype", dojolib.getVersion().toString().indexOf("1.9") == -1 ? "toolbarType" : "toolbar");
		// to be extended...
	}
	public Map<String, String> getConfig() {
		return config;
	}
}
<!-- faces-config.xml -->
<managed-bean>
		<managed-bean-name>dojo</managed-bean-name>
		<managed-bean-class>org.openntf.xsp.dojo.Config
		</managed-bean-class>
		<managed-bean-scope>view</managed-bean-scope>
</managed-bean>
<!-- example using the Richtext control -->
<xp:inputRichText id="inputRichText1"
					value="#{sessionScope.editor}">
					<xp:this.dojoAttributes>
						<xp:dojoAttribute name="extraPlugins"
							value="autogrow">
						</xp:dojoAttribute>
						<xp:dojoAttribute value="Full">
							<xp:this.name><![CDATA[#{javascript:dojo.config.get("toolbartype")}]]></xp:this.name>
			</xp:dojoAttribute>
	</xp:this.dojoAttributes>
</xp:inputRichText>





How it works

The bean stores some values in a config map. The map value of "toolbartype" stores whether to use "toolbarType" or "toolbar" as attribute name for the control. So in this case it computes the attribute name and not it's value (in this case I use the "Full" toolbar with all options).

I tried to compute the attribute name directly with the above Java code but it failed. I think the rendering phase cannot compute the correct version until the control is rendered itself so the bean solution was the alternative as it is instanciated before any rendering takes place.

Java
Oliver Busse
August 31, 2014 3:19 PM
Rating
45

All code submitted to OpenNTF XSnippets, whether submitted as a "Snippet" or in the body of a Comment, is provided under the Apache License Version 2.0. See Terms of Use for full details.



No comments yetLogin first to comment...