Elisabeth
Elisabeth

Reputation: 35

Can't show <pe:ckEditor/> on my XHTML page

I'd like to integrate pe:ckeditor to my XHTML page. After googling, I found this helpful link www.primefaces.org/showcase-ext/sections/ckEditor/multipleEditors.jsf

The Bean class is:

package com.esprit.util;

import java.io.Serializable;

import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;

@ManagedBean  
@ViewScoped  
public class EditorController implements Serializable {  
  
    private static final long serialVersionUID = 20111020L;  
  
    private String content;  
    private String secondContent;  
    private String color = "#33fc14";  
  
    public EditorController() {  
        content = "Hi Showcase User";  
        secondContent = "This is a second editor";  
    }  
  
    public void saveListener() {  
        content = content.replaceAll("\\r|\\n", "");  
  
        final FacesMessage msg = new FacesMessage(FacesMessage.SEVERITY_INFO, "Content",  
                    content.length() > 150 ? content.substring(0, 100) : content);  
  
        FacesContext.getCurrentInstance().addMessage(null, msg);  
    }  
  
    public void secondSaveListener() {  
        secondContent = secondContent.replaceAll("\\r|\\n", "");  
  
        final FacesMessage msg = new FacesMessage(FacesMessage.SEVERITY_INFO, "Second Content",  
                secondContent.length() > 150 ? secondContent.substring(0, 100) : secondContent);  
  
        FacesContext.getCurrentInstance().addMessage(null, msg);  
    }  
  
    public void changeColor() {  
        if (color.equals("#1433FC")) {  
            color = "#33fc14";  
        } else {  
            color = "#1433FC";  
        }  
    }  
  
    // Getters & Setters
}  

The page XHTML is:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:p="http://primefaces.org/ui"
      xmlns:pe="http://primefaces.org/ui/extensions">
    <body>
	<h:form>
	    <p:growl id="growl" showDetail="true" />  
            <pe:ckEditor id="editor" 
			 value="#{editorController.content}" 
		         toolbar="[['Cut','Copy','Paste','PasteText','PasteFromWord','-', 'SpellChecker', 'Scayt']]">  
                <p:ajax event="save" listener="#{editorController.saveListener()}" update="growl"/>  
            </pe:ckEditor> 
	    <br/>  
            <br/>  
            <pe:ckEditor id="secondEditor" 
            		 value="#{editorController.secondContent}" 
            	         toolbar="[['Cut','Copy','Paste','PasteText','PasteFromWord','-', 'SpellChecker', 'Scayt']]">  
                <p:ajax event="save" listener="#{editorController.secondSaveListener()}" update="growl"/>  
            </pe:ckEditor>
	</h:form>
    </body>
</html>

The added this to file web.xml:

 <context-param>
    <param-name>
        org.primefaces.extensions.DELIVER_UNCOMPRESSED_RESOURCES
    </param-name>
    <param-value>false</param-value>
</context-param>

After running my project: I got this screenshot. As you see, I didn't have the same editor as displayed by the tutorial: I have an Editor without Header.

Have you please any idea about solving this. Any proposition is appreciated. Thanks a lot.

Upvotes: 1

Views: 2460

Answers (2)

Saria Essid
Saria Essid

Reputation: 1248

Additional to the attribute toolbar that @ArgaPK mentioned, you have to:

  • Verify that those required jars exist:
    • commons-io-2.4.jar
    • commons-lang3-3.5.jar
    • gson-2.2.4.jar
    • primefaces-6.0.jar
    • primefaces-extensions-6.0.0.jar
    • resources-ckeditor-6.0.0.jar
  • Update your XHTML by adding <h:head/>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:p="http://primefaces.org/ui"
      xmlns:pe="http://primefaces.org/ui/extensions">
    <h:head/>
    <h:body>
  	<h:form style="width: 800px; margin: 0 auto;">
    	    <p:growl id="growl" showDetail="true" />  
    	    <pe:ckEditor id="editor" value="#{editorController.content}" toolbar="[['Cut','Copy','Paste','PasteText','PasteFromWord','-', 'SpellChecker', 'Scayt']]">  
 	        <p:ajax event="save" listener="#{editorController.saveListener}" update="growl"/>  
    	    </pe:ckEditor>
    	    <br/>  
   	    <br/>  
    	    <pe:ckEditor id="secondEditor" value="#{editorController.secondContent}" toolbar="[['Cut','Copy','Paste','PasteText','PasteFromWord','-', 'SpellChecker', 'Scayt']]">  
   	        <p:ajax event="save" listener="#{editorController.secondSaveListener}" update="growl"/>  
  	    </pe:ckEditor>
        </h:form>
    </h:body>
</html>

HTH

Upvotes: 3

ArgaPK
ArgaPK

Reputation: 455

You have to add the toolbar attribute

 <p:growl id="growl" showDetail="true" />  
    <pe:ckEditor id="editor" value="#{editorController.content}" toolbar="[['Cut','Copy','Paste','PasteText','PasteFromWord','-', 'SpellChecker', 'Scayt']]">  
  <p:ajax event="save" listener="#{editorController.saveListener}" update="growl"/>  
    </pe:ckEditor 
    <br/>  
   <br/>  
    <pe:ckEditor id="secondEditor" value="#{editorController.secondContent}" toolbar="[['Cut','Copy','Paste','PasteText','PasteFromWord','-', 'SpellChecker', 'Scayt']]">  
   <p:ajax event="save" listener="#{editorController.secondSaveListener}" update="growl"/>  
  </pe:ckEditor>

and add the following dependency also:

<dependency>
    <groupId>org.primefaces.extensions</groupId>
    <artifactId>primefaces-extensions</artifactId>
    <version>6.0.0</version>
</dependency>
<dependency>
    <groupId>org.primefaces.extensions</groupId>
    <artifactId>resources-ckeditor</artifactId>
    <version>6.0.0</version>
</dependency>

see this helfull link Getting started with primefaces extensions

Upvotes: 2

Related Questions