无法在我的 XHTML 页面上显示 <pe:ckEditor/>

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

我想将 pe:ckeditor 集成到我的 XHTML 页面中。 谷歌搜索后,我发现这很有帮助 link www.primefaces.org/showcase-ext/sections/ckEditor/multipleEditors.jsf

Bean class 是:

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
}  

页面 XHTML 为:

<!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>

将此添加到文件 web.xml:

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

在 运行 我的项目之后:我得到了这个 screenshot。 如您所见,我没有教程显示的编辑器:我有一个没有 Header.

的编辑器

请问您对解决这个问题有什么想法吗?任何提议表示赞赏。非常感谢。

您必须添加 toolbar 属性

 <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>

并添加以下依赖项:

<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>

看到这个 helfull link Getting started with primefaces extensions

除了@ArgaPK 提到的 toolbar 属性之外,您还必须:

  • 验证是否存在所需的 jar:
    • 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
  • 通过添加 <h:head/>
  • 更新您的 XHTML

<!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