我有一个页面有pe:ckEditor,p:fileUpload,p:commandButton,primefaces push。 如果没有文件附件,将执行p:commandButton(ajax =“true”)。否则,将执行p:commandButton(ajax =“false”)。
如果没有附件,当我点击发送时,pe:ckEditor会在ajax提交后自动清除。 但是,如果有附件,当我点击发送时,pe:ckEditor在非ajax提交后不会自动清除。
在websphere应用服务器8上运行使用primefaces 3.5和atmosphere-runtime-2.2.3
XHTML
<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>
托管Bean
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
<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>