使用primefaces fileupload我试图在上传组件上方的img标签中显示最近上传的图像,但只有在我手动按F5或在浏览器上按Enter后才会显示我尝试过location.reload()和histry.go(0 )但图像未加载
<img height="100" src="relativepath/productId"/>
<p:fileUpload oncomplete="history.go(0)" fileUploadListener="#{productController.upload}" mode="advanced"
dragDropSupport="false" allowTypes="/(\.|\/)(gif|jpe?g|png)$/" />
答案 0 :(得分:1)
不要限制自己使用javascript。 ajax之后的更新,在url中使用timestamp参数将正常工作。
这应该是xhtml代码:
<h:panelGroup id="panelToUpdate">
<img height="100" src="relativepath/productId?t=#{myManagedBean.currentTimeInMillis}"/>
</h:panelGroup>
<p:fileUpload update="panelToUpdate" fileUploadListener="#{productController.upload}"
mode="advanced" dragDropSupport="false" allowTypes="/(\.|\/)(gif|jpe?g|png)$/" />
这应该是托管bean中的方法:
public long getCurrentTimeInMillis()
{
return System.currentTimeMillis();
}
答案 1 :(得分:-1)
以下代码每1秒加载一次图像...希望我帮助
<div id="wraper">
</div>
<style>
var t=setInterval(runFunction,1000);
function runFunction() {
document.getElementById("p1").innerHTML = '<img height="100" src="relativepath/productId"/>
<p:fileUpload oncomplete="history.go(0)" fileUploadListener="#{productController.upload}" mode="advanced"
dragDropSupport="false" allowTypes="/(\.|\/)(gif|jpe?g|png)$/" />'
}
</style>