How to create a thumbnail link to OmniFaces graphicImage method

后端 未结 1 1013
一整个雨季
一整个雨季 2021-01-15 02:54

I was wondering if and how it is possible to display an as thumbnail inside a . To be more precise, I wan

相关标签:
1条回答
  • 2021-01-15 03:04

    For exactly this reason, OmniFaces 2.5 introduced the #{of:graphicImageURL()} EL function. This works only if your ImageBean is annotated with @GraphicImageBean.

    import org.omnifaces.cdi.GraphicImageBean;
    
    @GraphicImageBean
    public class ImageBean {
    
        // ...
    
    }
    

    <h:outputLink value="#{of:graphicImageURL('imageBean.getFirstImage(article, false)')}">  
        <o:graphicImage value="#{imageBean.getFirstImage(article, true)}" dataURI="true" height="80" />  
    </h:outputLink>
    

    See also the @GraphicImageBean showcase.


    Update: to be clear, you need a converter for non-standard types such as Article. Why such a converter is needed and how to create it is detailed in Conversion Error setting value for 'null Converter'. If you create a @FacesConverter(forClass=Article.class), then the OmniFaces GraphicImage will automatically pickup it.

    In your particular case it's however more efficient to just pass the identifier to the image streamer method right away, this saves an additional conversion step. Provided that your Article object has an id property, here's how:

    <h:outputLink value="#{of:graphicImageURL('imageBean.getFirstImage(article.id, false)')}">  
        <o:graphicImage value="#{imageBean.getFirstImage(article.id, true)}" dataURI="true" height="80" />  
    </h:outputLink>
    

    public byte[] getFirstImage(Long articleId, boolean thumbnail) {
        // ...
    }
    

    Namely, JSF already has builtin converters for standard types such as Long and boolean.

    0 讨论(0)
提交回复
热议问题