ajax - Primefaces:动态内容刷新问题

标签 ajax jsf primefaces graphicimage commandbutton

我有一个网络应用程序,我在其中选择了一些要删除的内容。模式弹出窗口显示所选图像/Flash 的预览。我按下一个按钮,一切正常。但是,当我选择另一个要删除的内容时,模式会弹出,并在一微秒内显示先前删除的文件,然后由我要删除的新内容替换。

显示动态内容的代码如下:

对于图片:

<p:graphicImage value="#{controller.tempImage}" height="110" 
    id="imageID" />

对于闪存:

<p:media value="#{controller.tempImage}" width="110" height="110" 
    id="imageID" player="flash" /> 

Controller :

public StreamedContent getTempImage() {
    try {
        FacesContext context = FacesContext.getCurrentInstance();

        if (context.getRenderResponse() ) {
            return new DefaultStreamedContent();
        }
        else {              
                tempImage = new DefaultStreamedContent(new FileInputStream("pathToFile"), "image/jpeg");                
        }
    } catch (FileNotFoundException e) {
        tempImage = new DefaultStreamedContent();
    }

    return tempImage;
}

我尝试在加载前将 tempImage 设置为 null,并在模态中将 autoUpdate=true 设置为 null,但没有成功。

删除按钮(显示删除模式的按钮):

<p:commandButton id="btnDelete" value="Delete" onclick="deleteModal.show();"  actionListener="#{controller.initDelete}" update=":deleteForm">                                       

删除表单(xhtml):

<h:form  id="deleteForm" enctype="multipart/form-data" >
<p:dialog id="deleteDialog" widgetVar="deleteModal" modal="true" resizable="false" draggable="false" autoUpdate="true">
        <p:outputPanel autoUpdate="false" >
            <p:panelGrid id="panelId">
                <p:row>                 
                    <p:column>
                        <p:panelGrid id="bannerPanel">

                            <p:row>
                                <p:column>
                                 <p:graphicImage value="#{controller.tempImage}" height="110" id="imageID" />
                                </p:column>
                            </p:row>    

                        </p:panelGrid>
                    </p:column>
                </p:row>

                <f:facet name="footer">
                    <p:row>
                        <p:column>  
                                <p:commandButton id="doDeleteBtn" value="Delete"
                                     actionListener="#{controller.delete}" >                                                        
                                </p:commandButton>
                        </p:column>
                    </p:row>
                </f:facet>
            </p:panelGrid>
        </p:outputPanel>
</p:dialog>            

最佳答案

更改自:

onclick="deleteModal.show();"

到:

oncomplete="deleteModal.show();"

这将确保您的对话框在 AJAX 请求完成后被查看,而不是在它开始之前。

你应该使用onclick,当你创建所谓的push buttons时,带有type="button"的按钮,它们只是执行一些 JavaScript。 Primefaces 中默认的按钮类型是 submit

关于ajax - Primefaces:动态内容刷新问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14570546/

相关文章:

javascript - Firefox 49.0.2 附加组件的 XMLHttpRequest Status 0

jquery - 创建带有下一个和上一个按钮的图像查看器弹出窗口

jquery - AJAX 发布后的 Pyramid HTTP 重定向

Javascript调用php函数并接收返回结果

java - 如何在数据表中引用数据表父级?

css - 如何在 primefaces 中创建自定义图标

java - 我们如何调整 p :commandbutton size or width

css - 将 styleClass 应用于父 panelGrid 元素而不是子元素

JSF2 i18n bean 验证消息

java - j_security_check 与 Primefaces