Ajax Primefaces:动态内容刷新问题

Ajax Primefaces:动态内容刷新问题,ajax,jsf,primefaces,graphicimage,commandbutton,Ajax,Jsf,Primefaces,Graphicimage,Commandbutton,我有一个webapp,我在其中选择了一些要删除的内容。弹出一个模式,显示所选图像/闪光灯的预览。我按了一下按钮,一切正常。但是,当我选择另一个要删除的内容时,模式会弹出,并在一微秒的时间内显示先前删除的文件,然后被我要删除的新内容替换 显示动态内容的代码如下所示: 对于图像: <p:graphicImage value="#{controller.tempImage}" height="110" id="imageID" /> <p:media value="#{c

我有一个webapp,我在其中选择了一些要删除的内容。弹出一个模式,显示所选图像/闪光灯的预览。我按了一下按钮,一切正常。但是,当我选择另一个要删除的内容时,模式会弹出,并在一微秒的时间内显示先前删除的文件,然后被我要删除的新内容替换

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

对于图像:

<p:graphicImage value="#{controller.tempImage}" height="110" 
    id="imageID" />
<p:media value="#{controller.tempImage}" width="110" height="110" 
    id="imageID" player="flash" /> 
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;
}
<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>            
在加载之前,我尝试将
tempImage
设置为null,并在模式中设置
autoUpdate=true
,但没有成功

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


删除表单(xhtml):

<p:graphicImage value="#{controller.tempImage}" height="110" 
    id="imageID" />
<p:media value="#{controller.tempImage}" width="110" height="110" 
    id="imageID" player="flash" /> 
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;
}
<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();"
致:

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


在创建所谓的按钮时,应该使用
onclick
,即带有
type=“button”
的按钮,这些按钮只是执行一些JavaScript。Primefaces中的默认按钮类型是
submit

您可以显示该按钮的代码吗?查看更多代码会很有帮助。。。可能是显示对话框和对话框本身的按钮(xhtml)和删除内容的方法(bean)是的。就这样。再次感谢你的帮助:P。你帮了我很大的忙。顺便说一句(我不知道我是否可以在这里问一下)。。。我经常收到警告:JSF1091无法找到文件dynamiccontent的mime类型,我在这里和一些PF论坛上发布了一些教程,但没有任何更改。你对这个问题有什么想法吗?它看起来很普通,但我无法摆脱它。@partlov,你太快了!;)