How to get the value of <p:editor> after update

女生的网名这么多〃 提交于 2019-12-13 06:04:22

问题


As a feature in my JSF Web application, i need online editing for word documents. In order to update a word document that i have in my database table i do the following :

1/create the datatable and the column which contains the Commandlinks that shows the dialogue that has the <p:editor>.(used datatable binding in a sessionscoped Managedbean)

//the creation of the column that has Commandlinks.
CommandLink rapstatelink = (CommandLink) application.createComponent(CommandLink.COMPONENT_TYPE);
rapstatelink.setId("MRepShowButton");
rapstatelink.setUpdate(":form1:formero");
rapstatelink.setOnclick("EditorDialog.show();");

ValueExpression value = ef.createValueExpression(elc, "#{exam}", Cotation.class);
ValueExpression target = ef.createValueExpression(elc, "#{dyna.selectedExamen}", Cotation.class);

//this two lines should update the editor with the loaded doc from datatabase.
rapstatelink.addActionListener(new SetPropertyActionListenerImpl(target, value));
ValueExpression value1 = ef.createValueExpression(elc, "#{dyna.selectedExamen.examen.rapport.rapportWrittenFile}", byte[].class);
ValueExpression target1 = ef.createValueExpression(elc, "#{dyna.raptext}", byte[].class);
rapstatelink.addActionListener(new SetPropertyActionListenerImpl(target1, value1)); 
column.getChildren().add(rapstatelink);
table.getChildren().add(column);

2/create the dialogue that contains the on my jsf page :

<!-this is wrapped in a global form id="form1"->
<p:dialog header="Compte rendu"
          widgetVar="EditorDialog"
          resizable="true"
          id="patDlg"
          showEffect="fade"
          hideEffect="drop"
          modal="true"
          position ="center middle"
          maximizable="true"
          dynamic="true"
          width="1200"
          height="850">  
          <h:panelGrid id="display" ellpadding="4" style="margin:0 auto;">  
            <h:form id="formero">
              <p:messages id="msg2" showDetail="true" closable="true" />
              <p:editor id="editoreo"
                        value="#{dyna.raptext}"
                        converter="#{HTMLConverter}"
                        width="1100"
                        height="700" /> 
              <h:panelGrid columns="3" style="margin-top:10px">  
                <p:commandButton id="submitButton"
                                 value="Enregistrer"
                                 actionListener="#{dyna.saveDoc(dyna.selectedExamen.examen.rapport.rapportId)}" 
                                 process="@this" update="msg2"
                                 icon="ui-icon-disk" />
                <p:commandButton id="clearButton"
                                 type="button"
                                 value="Vider"
                                 onclick="editoreo.clear();"  
                                 icon="ui-icon-refresh" />
                <p:commandButton id="hideButton"
                                 type="button" 
                                 value="Annuler"
                                 onclick="EditorDialog.hide();"  
                                 icon="ui-icon-close" />  
              </h:panelGrid>   
            </h:form>   
           </h:panelGrid> 
</p:dialog>

3/this is the saveDoc() method that updates the table :

public void saveDoc(String idr) {

    try {
        //raptext is a field in the same managed bean.(session scoped)
        DAO_Examen.UpdateRapporttext(raptext, idr);
        FacesMessage msg = new FacesMessage("Terminé avec succes", "operation bien effectué " + idr + "|||||");
        FacesContext.getCurrentInstance().addMessage(null, msg);

    } catch (Exception c) {

        c.printStackTrace();

    }
}

--Just in case here is my HTMLConverter :

@Override
public String getAsString(FacesContext context, UIComponent component, Object value) {
    try {
        if (value != null) {
            ByteArrayInputStream bin = new ByteArrayInputStream((byte[]) value);
            HWPFDocumentCore wordDocument = WordToHtmlUtils.loadDoc(bin);
            WordToHtmlConverter wordToHtmlConverter = new WordToHtmlConverter(DocumentBuilderFactory.newInstance()
                    .newDocumentBuilder().newDocument());
            wordToHtmlConverter.processDocument(wordDocument);
            Document htmlDocument = wordToHtmlConverter.getDocument();
            ByteArrayOutputStream out = new ByteArrayOutputStream();
            DOMSource domSource = new DOMSource(htmlDocument);
            StreamResult streamResult = new StreamResult(out);
            TransformerFactory tf = TransformerFactory.newInstance();
            Transformer serializer = tf.newTransformer();
            serializer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
            serializer.setOutputProperty(OutputKeys.INDENT, "yes");
            serializer.setOutputProperty(OutputKeys.METHOD, "html");
            serializer.transform(domSource, streamResult);
            out.close();
            value = new String(out.toByteArray());
            return (String) value;

        } else {
            return "";
        }

    } catch (Exception ex) {
        ex.printStackTrace();
        return "";
    }

}

The Question :

Evreything works fine, but when i fire the action from the command button i don't get the edited text, i get the same very text that i loaded in the first time with no modification. I want to know how may i get the value of the new edited text, so i can save it to the datatabse.

来源:https://stackoverflow.com/questions/20375234/how-to-get-the-value-of-peditor-after-update

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!