Dynamic content rendering / streaming #3364
Unanswered
FloresGonzalezRodrigo
asked this question in
PrimeFaces
Replies: 1 comment 1 reply
-
In general it might get invoked multiple times, ready carefully here: https://primefaces.github.io/primefaces/15_0_0/#/core/dynamiccontentstreaming?id=during-rendering Even our example is broken a bit here: http://www.primefaces.org/showcase/ui/multimedia/galleria/dynamic.xhtml
|
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello! I'm trying to make a gallery of uploaded images. I got it to work, but I don't think it works the way it should.
The problem is that within the <p:graphicImage> tag I pass as parameter the id of the loaded image and I try to recover it in the method that returns the image stream, but the method is executed several times, the first times the id parameter arrives as null and at last it has the correct value.
I solved it by returning the last image of the list when the parameter arrives null and returning the image that has that id, otherwise.
View:
`<p:fileUpload mode="simple"
skinSimple="true"
multiple="false"
update="messages galleria"
listener="#{cropUploaderBean.handleFileUpload}"
auto="true">
<p:validateFile sizeLimit="10240000"
allowTypes="/(.|/)(gif|jpeg|jpg|png)$/"/>
</p:fileUpload>
<p:galleria id="galleria" value="#{cropUploaderBean.photos}" var="photo"
numVisible="5" style="width: 500px">
<p:graphicImage cache="false" value="#{cropUploaderBean.originalImageStream}" style="height: 100%; width: 100%; object-fit: contain">
<f:param name="photoId" value="#{photo.id}"/>
</p:graphicImage>
Controller:
`public StreamedContent getOriginalImageStream() {
FacesContext context = FacesContext.getCurrentInstance();
String id = context.getExternalContext().getRequestParameterMap().get("photoId");
System.err.println(id);
UploadedFile uploadedFile;
if(id==null)
uploadedFile=photos.getLast().getImage();
else
uploadedFile = photos.get(Integer.parseInt(id)).getImage();
return DefaultStreamedContent.builder()
.contentType(uploadedFile == null ? null : uploadedFile.getContentType())
.stream(() -> {
if (uploadedFile == null
|| uploadedFile.getContent() == null
|| uploadedFile.getContent().length == 0) {
return null;
}
Beta Was this translation helpful? Give feedback.
All reactions