diff --git a/src/main/java/org/omnifaces/el/functions/Components.java b/src/main/java/org/omnifaces/el/functions/Components.java index 070be1304..25d747e4a 100644 --- a/src/main/java/org/omnifaces/el/functions/Components.java +++ b/src/main/java/org/omnifaces/el/functions/Components.java @@ -12,10 +12,16 @@ */ package org.omnifaces.el.functions; +import static org.omnifaces.util.Faces.getContext; import static org.omnifaces.util.Faces.getELContext; +import java.util.Date; + import javax.el.ValueExpression; import javax.faces.component.UIComponent; +import javax.faces.context.FacesContext; + +import org.omnifaces.resourcehandler.GraphicResource; /** * Collection of EL functions for working with components. @@ -56,4 +62,72 @@ public static Object evalAttribute(UIComponent component, String name) { return component.getAttributes().get(name); } } -} + + /** + *
+ * Returns <o:graphicImage>
URL based on given expression string.
+ *
+ * Usage example: + *
+ * <a href="#{of:graphicImageURL('bean.getFullImage(image.id)')}"> + * <o:graphicImage value="#{bean.getThumbnailImage(image.id)}" /> + * </a> + *+ * @param expression Expression string representing the same value as you would use in + *
<o:graphicImage>
. It must be a quoted string. Any nested quotes can be escaped with backslash.
+ * @return <o:graphicImage>
URL based on given expression string.
+ * @since 2.5
+ */
+ public static String graphicImageURL(String expression) {
+ return graphicImageURLWithTypeAndLastModified(expression, null, null);
+ }
+
+ /**
+ *
+ * Returns <o:graphicImage>
URL based on given expression string and image type.
+ *
+ * Usage example: + *
+ * <a href="#{of:graphicImageURL('bean.getFullImage(image.id)', 'png')}"> + * <o:graphicImage value="#{bean.getThumbnailImage(image.id)}" type="png" /> + * </a> + *+ * @param expression Expression string representing the same value as you would use in + *
<o:graphicImage>
. It must be a quoted string. Any nested quotes can be escaped with backslash.
+ * @param type The image type, represented as file extension.
+ * E.g. "jpg", "png", "gif", "ico", "svg", "bmp", "tiff", etc. This may be null
.
+ * @return <o:graphicImage>
URL based on given expression string and image type.
+ * @since 2.5
+ */
+ public static String graphicImageURLWithType(String expression, String type) {
+ return graphicImageURLWithTypeAndLastModified(expression, type, null);
+ }
+
+ /**
+ *
+ * Returns <o:graphicImage>
URL based on given expression string, image type and last modified.
+ *
+ * Usage example: + *
+ * <a href="#{of:graphicImageURL('bean.getFullImage(image.id)', 'png', image.lastModified)}"> + * <o:graphicImage value="#{bean.getThumbnailImage(image.id)}" type="png" lastModified="#{image.lastModified}" /> + * </a> + *+ * @param expression Expression string representing the same value as you would use in + *
<o:graphicImage>
. It must be a quoted string. Any nested quotes can be escaped with backslash.
+ * @param type The image type, represented as file extension.
+ * E.g. "jpg", "png", "gif", "ico", "svg", "bmp", "tiff", etc. This may be null
.
+ * @param lastModified The "last modified" timestamp, can be either a {@link Long}, {@link Date}, or {@link String}
+ * which is parseable as {@link Long}. This may be null
.
+ * @return <o:graphicImage>
URL based on given expression string, image type and last modified.
+ * @since 2.5
+ */
+ @SuppressWarnings("all") // Eclipse el-syntax.
+ public static String graphicImageURLWithTypeAndLastModified(String expression, String type, Object lastModified) {
+ FacesContext context = getContext();
+ ValueExpression value = org.omnifaces.util.Components.createValueExpression("#{" + expression + "}", Object.class);
+ GraphicResource resource = GraphicResource.create(context, value, type, lastModified);
+ return context.getExternalContext().encodeResourceURL(resource.getRequestPath());
+ }
+
+}
\ No newline at end of file
diff --git a/src/main/resources/META-INF/omnifaces-functions.taglib.xml b/src/main/resources/META-INF/omnifaces-functions.taglib.xml
index 1123840bf..29a0e3b82 100644
--- a/src/main/resources/META-INF/omnifaces-functions.taglib.xml
+++ b/src/main/resources/META-INF/omnifaces-functions.taglib.xml
@@ -823,10 +823,9 @@
+ Usage example: +
+<a href="#{of:graphicImageURL('bean.getFullImage(image.id)')}"> + <o:graphicImage value="#{bean.getThumbnailImage(image.id)}" /> +</a> ++ ]]> +
+ Usage example: +
+<a href="#{of:graphicImageURL('bean.getFullImage(image.id)', 'png')}"> + <o:graphicImage value="#{bean.getThumbnailImage(image.id)}" type="png" /> +</a> ++ ]]> +
java.lang.Long
, java.util.Date
,
+ or java.lang.String
which is parseable as java.lang.Long
.
+ + Usage example: +
+<a href="#{of:graphicImageURL('bean.getFullImage(image.id)', 'png', image.lastModified)}"> + <o:graphicImage value="#{bean.getThumbnailImage(image.id)}" type="png" lastModified="#{image.lastModified}" /> +</a> ++ ]]> +