我的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;
}
}
答案 0 :(得分:2)
Hello 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>