Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0430fd7
commit 747828b
Showing
4 changed files
with
120 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
...s-showcase/src/main/java/org/primefaces/showcase/view/multimedia/DynamicGalleriaView.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
primefaces-showcase/src/main/webapp/ui/multimedia/galleria/dynamic.xhtml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |