2017-11-22 26 views
2

PrimeFaces TextEditor에 문제가 있습니다.PrimeFaces의 내용을 인쇄 할 수 없습니다. TexEditor

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> 

관리 빈 (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; 
} 
} 

답변

2

안녕하세요 월 당신이 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}" /> 

그의 이드가 작동하지 않는다.

그것은이 remoteCommand 수행 할 수 있습니다 :

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

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

        </p:remoteCommand> 

양식과 버튼을 변경해야합니다 당신의 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> 

당신의 후 질문 다를 수 있습니다. 당신은 그들에게 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> 
+0

여전히 동일합니다. 나는 질문을 업데이트했다. –

+0

EditorBean도 표시 할 수 있습니까? EditorBean에서 속성 텍스트를 인쇄한다는 의미입니다. 당신이 그것을 EditorView – pwain

+0

에 다시 설정했기 때문에 그것은 단지 비어있는 것 같아요. 나는 그것을 다시 업데이트했습니다. :) –