gpt4 book ai didi

jsf - 从 Primeface 的 p :fileUpload in same form without refresh 显示 UploadedFile 内容

转载 作者:行者123 更新时间:2023-12-04 13:43:39 24 4
gpt4 key购买 nike

我正在尝试实现 ImageUpload 并使用 DynamicImage 在同一页面上立即显示上传的图片。我的问题是,我无法强制刷新 p:graphicImage 内容并在上传后显示上传的图片。

@ManagedBean(name = "myformbean")
@Controller
@ViewScoped
@Data
public class MyFormBean implements Serializable {

private StreamedContent listImage = null;

public StreamedContent getListImage() {
if (listImage == null) {
try {
listImage = new DefaultStreamedContent(new FileInputStream("E:/t.jpg"), "image/png"); // load a dummy image
}
catch (FileNotFoundException e) {
e.printStackTrace();
}
}

return listImage;
}

public void handleFileUpload(FileUploadEvent event) {
final UploadedFile uploadedFile = event.getFile();

listImage = new DefaultStreamedContent(new ByteArrayInputStream(uploadedFile.getContents()), "image/png");
}
}

在 .xhtml 文件中:

<p:graphicImage value="#{myformbean.listImage}" />

最佳答案

如果您的上传成功

您只需将 id 设置为 <p:graphicImage像这样

<p:graphicImage id="refreshMe" value="#{myformbean.listImage}" />

在你的<p:fileUpload设置更新属性指向图片

喜欢这个

<p:fileUpload  auto="true"  ... update="refreshMe" ....

关于jsf - 从 Primeface 的 p :fileUpload in same form without refresh 显示 UploadedFile 内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10464933/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com