【问题标题】:Cannot print content of PrimeFaces TexEditor无法打印 PrimeFaces TexEditor 的内容
【发布时间】:2017-11-22 14:47:31
【问题描述】:

PrimeFaces TextEditor 有问题。

我想打印 TextEditor 中的 content,但是当我单击“打印”按钮时,我只得到 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;
}
}

【问题讨论】:

    标签: jsf primefaces jsf-2 glassfish


    【解决方案1】:

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

    您在评论中的问题:

    可以通过remoteCommand来完成:

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

    【讨论】:

    • 你能不能也给我看看EditorBean。我的意思是你从 EditorBean 打印属性文本。我猜它只是空的,因为你只将它设置为 EditorView
    • 请搜索 editorBean 并将其替换为 editorView 行 我敢打赌它有效
    • 文件 editorBean 不存在。没有editorBean可以解决这个问题吗?我只想从编辑器中打印文本,仅此而已:)
    • 但是是的,我把代码改成了editorView,但是pdf还是空白。
    猜你喜欢
    • 2013-09-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-11-06
    • 1970-01-01
    • 2021-03-23
    • 2013-01-19
    相关资源
    最近更新 更多