Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
tandraschko committed Mar 22, 2023
1 parent 0430fd7 commit 747828b
Show file tree
Hide file tree
Showing 4 changed files with 120 additions and 0 deletions.
Expand Up @@ -24,24 +24,36 @@
package org.primefaces.showcase.domain;

import java.io.Serializable;
import java.util.UUID;

public class Photo implements Serializable {

private String id;
private String itemImageSrc;
private String thumbnailImageSrc;
private String alt;
private String title;

public Photo() {
this.id = UUID.randomUUID().toString().substring(0, 8);
}

public Photo(String itemImageSrc, String thumbnailImageSrc, String alt, String title) {
this();
this.itemImageSrc = itemImageSrc;
this.thumbnailImageSrc = thumbnailImageSrc;
this.alt = alt;
this.title = title;
}

public String getId() {
return id;
}

public void setId(String id) {
this.id = id;
}

public String getItemImageSrc() {
return itemImageSrc;
}
Expand Down
Expand Up @@ -498,6 +498,7 @@ public void init() {
galleriaMenuItems.add(new MenuItem("FullScreen", "/ui/multimedia/galleria/fullscreen"));
galleriaMenuItems.add(new MenuItem("AutoPlay", "/ui/multimedia/galleria/autoplay"));
galleriaMenuItems.add(new MenuItem("Caption", "/ui/multimedia/galleria/caption"));
galleriaMenuItems.add(new MenuItem("Dynamic", "/ui/multimedia/galleria/dynamic"));
multimediaMenuItems.add(new MenuItem("Galleria", galleriaMenuItems));

multimediaMenuItems.add(new MenuItem("Media", "/ui/multimedia/media"));
Expand Down
@@ -0,0 +1,73 @@
/*
* The MIT License
*
* Copyright (c) 2009-2023 PrimeTek Informatics
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.primefaces.showcase.view.multimedia;

import java.io.Serializable;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.enterprise.context.RequestScoped;
import javax.faces.context.FacesContext;
import javax.inject.Inject;
import javax.inject.Named;
import org.primefaces.model.DefaultStreamedContent;
import org.primefaces.model.StreamedContent;
import org.primefaces.showcase.domain.Photo;
import org.primefaces.showcase.service.PhotoService;

@Named
@RequestScoped
public class DynamicGalleriaView implements Serializable {

private List<Photo> photos;

@Inject
private PhotoService service;

@PostConstruct
public void init() {
photos = service.getPhotos();
}

public StreamedContent getPhotoAsStreamedContent() {
FacesContext facesContext = FacesContext.getCurrentInstance();
String photoId = facesContext.getExternalContext().getRequestParameterMap().get("photoId");
Photo photo = photos.stream()
.filter(p -> p.getId().equals(photoId))
.findFirst().get();

return DefaultStreamedContent.builder()
.name(photo.getTitle() + ".jpg")
.contentType("image/jpg")
.stream(() -> facesContext.getExternalContext().getResourceAsStream("/resources/" + photo.getItemImageSrc()))
.build();
}

public List<Photo> getPhotos() {
return photos;
}

public void setService(PhotoService service) {
this.service = service;
}
}
@@ -0,0 +1,34 @@
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:p="http://primefaces.org/ui"
template="/WEB-INF/template.xhtml">

<ui:define name="title">
Galleria <span class="subitem">Dynamic</span>
</ui:define>

<ui:define name="description">
Galleria also supports dynamic content via StreamedContent.
</ui:define>

<ui:param name="documentationLink" value="/components/galleria"/>
<ui:param name="widgetLink" value="Galleria"/>

<ui:define name="implementation">
<div class="card">
<p:galleria value="#{dynamicGalleriaView.photos}" var="photo" numVisible="5" responsiveOptions="#{galleriaView.responsiveOptions1}" style="max-width: 640px">
<p:graphicImage value="#{dynamicGalleriaView.photoAsStreamedContent}" alt="#{photo.alt}" style="width: 100%">
<f:param name="photoId" value="#{photo.id}" />
</p:graphicImage>
<f:facet name="thumbnail">
<p:graphicImage value="#{dynamicGalleriaView.photoAsStreamedContent}" alt="#{photo.alt}" style="width: 100%">
<f:param name="photoId" value="#{photo.id}" />
</p:graphicImage>
</f:facet>
</p:galleria>
</div>
</ui:define>

</ui:composition>

0 comments on commit 747828b

Please sign in to comment.