首页 > 解决方案 > p:textEditor : 默认值


问题描述

我使用 PrimeFaces 的 textEditor 组件,字符串变量 (JEE) 包含输入的文本。当我在调用组件之前用“null”或“”初始化这个变量时,这个变量会包含:<p><br></p> 结果,占位符不显示,光标位于第二行。如何删除此值?

这是我的代码:

    <p:contextMenu>
                <p:menuitem value="Ajouter une note" actionListener="#{noteManagerBean.initialiserNote()}" 
                            oncomplete="PF('widgetNoteDialog').show()" 
                            update="idNoteDialog"/>
            </p:contextMenu>

            <p:dialog id="idNoteDialog" widgetVar="widgetNoteDialog" style="position: absolute; border: none; border-radius: 0; z-index: 2" class="effetZoom" showEffect="fade" hideEffect="fade" closable="false" resizable="false"> 
                <p:textEditor placeholder="Entrez votre texte ici" value="#{noteManagerBean.noteTexte}" height="129" style="width: 294px; position: absolute; top: 0px; left: 12px; margin-left: -1px; background-color: transparent">
                    <f:facet name="toolbar"> 
                        <span class="ql-formats">
                            <button class="ql-bold"></button>
                            <button class="ql-italic"></button>
                            <button class="ql-underline"></button>
                        </span>
                    </f:facet>
                </p:textEditor>
</p:dialog>

@SessionScoped
@Named
public class NoteManagerBean implements Serializable {

    private String noteTexte;

    public void initialiserNote() {

        setNoteTexte(null);

    }

标签: jsfprimefacestext-editor

解决方案


我相信您的问题与此问题的修复有关: https ://github.com/primefaces/primefaces/issues/3170

它试图确定编辑器是否已经显示 HTML。

getEditorValue: function() {
        var html = $(this.editorContainer[0]).find('p').text();
        var value = (html == '<p><br></p>') ? '' : html;

        return value;
    },

推荐阅读