无法打印 PrimeFaces TexEditor 的内容

Cannot print content of PrimeFaces TexEditor

我对 PrimeFaces TextEditor 有疑问。

我要打印 content that is inside TextEditor, but when I click "Print" button I only get blank PDF。代码中可能有错误还是我遗漏了什么?

textEditor.xhtml:

<ui:define name="content">
    <div class="ui-g">
        <div class="ui-g-12">
            <div class="card">
                <h:form>    
                    <h3 style="margin-top:0">Text editor</h3>
                    <p:textEditor widgetVar="editor1" value="#{editorView.text}"  height="400" style="margin-bottom:10px"/>

                    <h:outputText id="text_to_print" escape="false" value="#{editorView.text}" />

                    <p:commandButton value="Preview" update="display" oncomplete="PF('dlg').show()" icon="ui-icon-circle-zoomin" />
                    <p:commandButton value="Print" type="button" icon="ui-icon-print">
                        <p:printer target="text_to_print" />
                    </p:commandButton>
                    <p:commandButton value="Clear" type="button" onclick="PF('editor1').clear();" icon="ui-icon-close" />

                    <p:dialog header="Preview" widgetVar="dlg" showEffect="fade" hideEffect="fade">
                        <p:outputPanel id="display">
                            <h:outputText value="#{editorView.text}" escape="false" />
                        </p:outputPanel>
                    </p:dialog>     
                </h:form>
            </div>
        </div>
    </div>
</ui:define>

托管 bean (EditorView.java)

package org.primefaces.ultima.view.input;

import javax.faces.bean.ManagedBean;

@ManagedBean

public class EditorView {

private String text;

private String text2;

public String getText() {
    return text;
}

public void setText(String text) {
    this.text = text;
}

public String getText2() {
    return text2;
}

public void setText2(String text2) {
    this.text2 = text2;
}
}

你好Jan很简单你不更新text_to_print

 <h:form>    
                    <h3 style="margin-top:0">Text editor</h3>
                    <p:textEditor widgetVar="editor1" value="#{editorView.text}"  height="400" style="margin-bottom:10px"/>

                    <h:outputText id="text_to_print" escape="false" value="#{editorView.text}" />

如果这不起作用,请检查您的按钮 ID。取决于您的 DOM 树,它可能会有所不同

                    <p:commandButton value="Preview" update="display,text_to_print" oncomplete="PF('dlg').show()" icon="ui-icon-circle-zoomin" />
                    <p:commandButton value="Print" type="button" icon="ui-icon-print">
                        <p:printer target="text_to_print" />
                    </p:commandButton>
                    <p:commandButton value="Clear" type="button" update="text_to_print" onclick="PF('editor1').clear();" icon="ui-icon-close" />

                    <p:dialog header="Preview" widgetVar="dlg" showEffect="fade" hideEffect="fade">
                        <p:outputPanel id="display">
                            <h:outputText value="#{editorView.text}" escape="false" />
                        </p:outputPanel>
                    </p:dialog>     
                </h:form>

你的问题来自评论:

可以通过远程命令完成:

<p:commandButton  value="Go" 
     update="display,text_to_print"
    onsuccess="doAfter()"/>

<p:remoteCommand name="doAfter" oncomplete="document.getElementById('printForm:print').click()"   >

                  </p:remoteCommand>

记得更改表单和按钮。你必须给他们一个 Id

 <h:form id="printForm">    
...
  <p:commandButton value="Print" type="button" icon="ui-icon-print" id="print">
                        <p:printer target="text_to_print" />
                    </p:commandButton>