pe:ckEditor not cleared after non ajax submit with push

UI Components for JSF
Post Reply
bittersour
Posts: 61
Joined: 26 Aug 2013, 03:39

12 Aug 2015, 11:00

I have a page with pe:ckEditor, p:fileUpload, p:commandButton, primefaces push. If there is no file attachment, the p:commandButton (ajax="true") will be executed. Otherwise, p:commandButton (ajax="false") will be executed.

If there is no attachment, when I click on send, the pe:ckEditor is cleared automatically after ajax submit. However, if there is attachment, when I click on send, the pe:ckEditor is not cleared automatically after non ajax submit.

xhtml

Code: Select all

           <h:head>
                <script type="text/javascript">
                    function update() {
                        if (document.getElementById('tr1004_fileupload_attachment1').value != ''
                                || document.getElementById('tr1004_fileupload_attachment2').value != ''
                                || document.getElementById('tr1004_fileupload_attachment3').value != '') {
                            document.getElementById('tr1004_command_send').ajax = 'false';
                            document.getElementById('hiddenLink_non_ajax').click();         
                        } else {
                            document.getElementById('tr1004_command_send').ajax = 'true';
                            document.getElementById('hiddenLink_ajax').click();
                            CKupdate();
                        }
                    }

                    function CKupdate() {
                        for (instance in CKEDITOR.instances) {
                            CKEDITOR.instances[instance].updateElement();
                        }
                        CKEDITOR.instances[instance].setData('');
                    }
                </script>
            </h:head>

            <h:body>
                <h:form id="form1" enctype="multipart/form-data" prependId="false">
                    <ui:include src="../../theme/menubar.xhtml" />

                    <p:commandButton type="submit" value="#{msg.tr1004_command_send}"
                        styleClass="commandButton" id="tr1004_command_send"
                        onclick="update()" rendered="#{pc_Tr1004.showSend}">
                    </p:commandButton> 
                    <p:commandButton id="hiddenLink_ajax" ajax="true"
                        actionListener="#{pc_Tr1004.doTr1004_command_ajaxSendAction}"
                        style="display:none"/> 
                    <p:commandButton id="hiddenLink_non_ajax" ajax="false"
                        actionListener="#{pc_Tr1004.doTr1004_command_nonAjaxSendAction}"
                        style="display:none"/>

                    <table border="0" cellpadding="0" cellspacing="0">
                        <tbody>
                            <tr>
                                <td align="left" valign="top">
                                    <h:outputText
                                        styleClass="outputText" id="tr1004_output_attachments"
                                        value="#{msg.tr1004_output_attachments}">
                                    </h:outputText>
                                </td>
                                <td>
                                    <p:fileUpload id="tr1004_fileupload_attachment1" mode="simple" 
                                        value="#{pc_Tr1004.w_teamroom.fileupload1}"/>
                                </td>
                                <td>
                                    <p:fileUpload id="tr1004_fileupload_attachment2" mode="simple" 
                                        value="#{pc_Tr1004.w_teamroom.fileupload2}"/>
                                </td> 
                                <td>
                                    <p:fileUpload id="tr1004_fileupload_attachment3" mode="simple" 
                                        value="#{pc_Tr1004.w_teamroom.fileupload3}"/>
                                </td>               
                            </tr>
                        </tbody>
                    </table> 

                    <table border="0" cellpadding="0" cellspacing="0">
                        <tbody>
                            <tr>
                                <td valign="top" width="650">
                                    <pe:ckEditor id="tr1004_editor_message" 
                                        value="#{pc_Tr1004.w_teamroom.message}" 
                                        interfaceColor="#F0F0F0" skin="kama" 
                                        height="150" width="800"
                                        customConfig="../../config.js"
                                        toolbar="[
                                                ['Bold', 'Italic', 'Underline', 'Strike', 'Subscript', 'Superscript', 'RemoveFormat'],
                                                ['TextColor', 'BGColor'],
                                                ['NumberedList', 'BulletedList', 'Outdent', 'Indent', 'Blockquote', 'JustifyLeft', 'JustifyCenter', 'JustifyRight', 'JustifyBlock', 'BidiLtr', 'BidiRtl'], 
                                                ['/']
                                                ['Styles'], ['Format'], ['Font'], ['FontSize'],
                                                ['Cut','Copy','Paste','PasteText','PasteFromWord', 'Undo', 'Redo'],
                                                ['Find', 'Replace', '-', 'SpellChecker', 'Scayt'],
                                                ['Link', 'Unlink'],
                                                ['Image', 'Table', 'HorizontalRule', '-', 'SpecialChar']
                                                ]">
                                    </pe:ckEditor>
                                </td>
                            </tr>   
                        </tbody>
                    </table>    

                    <table border="0" cellpadding="0" cellspacing="0">
                        <tbody>
                            <tr>
                                <td valign="top" width="800">
                                    <p:dataTable styleClass="dataTable" id="tr1004_datatable_teamroomhistorys" 
                                        value="#{pc_Tr1004.w_teamroom.listOfTeamroomHistorys}" 
                                        var="varlistOfTeamroomHistorys">


                                    </p:dataTable>
                                </td>
                            </tr>
                        </tbody>
                    </table>

                    <p:remoteCommand name="updateWidgets"
                        actionListener="#{pc_Tr1004.increment}"
                        update=":form1:tr1004_datatable_teamroomhistorys" />

                </h:form>

                <p:socket onMessage="handleMessage" channel="/counter" />
                <script type="text/javascript">
                    function handleMessage(data) {
                        updateWidgets();
                    }
                </script>
            </h:body>
Managed Bean

Code: Select all

public synchronized void increment() {

                W_teamroom _w = getW_teamroom();

                ServletContext servletContext = (ServletContext) FacesContext
                        .getCurrentInstance().getExternalContext().getContext();

                if (servletContext.getAttribute("GLOBAL_PUSH") != null){
                    if (((String)servletContext.getAttribute("GLOBAL_PUSH")).equals(_w.getTeamroomid())){
                      _w.retrieveTeamroomHistory();
                    }
                }
            }

            public String doTr1004_command_ajaxSendAction() {

                W_teamroom _w = getW_teamroom();

                UploadedFile _file1 = null;
                UploadedFile _file2 = null;
                UploadedFile _file3 = null;

                _w.saveTeamroomComment(_file1, _file2, _file3);

                ServletContext servletContext = (ServletContext) FacesContext
                        .getCurrentInstance().getExternalContext().getContext();

                servletContext.setAttribute("GLOBAL_PUSH", _w.getTeamroomid());

                 //Clear message
                _w.setMessage(null);

                PushContext pushContext = PushContextFactory.getDefault().getPushContext();
                pushContext.push("/counter", "");

                return ""; 
            }   

            public String doTr1004_command_nonAjaxSendAction() {

                W_teamroom _w = getW_teamroom();

                UploadedFile _file1 = _w.getFileupload1();
                UploadedFile _file2 = _w.getFileupload2();
                UploadedFile _file3 = _w.getFileupload3();

                _w.saveTeamroomComment(_file1, _file2, _file3);

                ServletContext servletContext = (ServletContext) FacesContext
                        .getCurrentInstance().getExternalContext().getContext();

                servletContext.setAttribute("GLOBAL_PUSH", _w.getTeamroomid());

                 //Clear message
                _w.setMessage(null);

                PushContext pushContext = PushContextFactory.getDefault().getPushContext();
                pushContext.push("/counter", "");

                return "";      
            } 
web.xml

Code: Select all

<servlet>
                <servlet-name>Push Servlet</servlet-name>
                <servlet-class>org.primefaces.push.PushServlet</servlet-class>
                <async-supported>true</async-supported> 
            </servlet>

            <servlet-mapping>
                <servlet-name>Push Servlet</servlet-name>
                <url-pattern>/primepush/*</url-pattern>
            </servlet-mapping>
WEB-INF\lib
I have the below jarfiles
- atmosphere-runtime-2.2.3.jar
- log4j-1.2.17.jar
- slf4j-api-1.6.1.jar
- slf4j-log4j12-1.7.7.jar
-----------------------------------------------------------------------------------------------------------
Primefaces 5.1
MyFaces 2.0
WebSphere 8.0

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 29 guests