图像错误地重复在p:galeria中

问题描述 投票:0回答:1

我在使用primefaces image galleria时遇到了麻烦。 有时,幻灯片会多次显示,有时则不会。 Galleria printscreen

图像是由Servlet类动态获得的。 我已经调试了代码,图像列表是正确的,没有重复项目。

如何防止图像重复?

galleria.xhtml

<p:galleria id="myGalleria" 
        value="#{myBean.imageList}"
        var="item" 
        effect="fade" 
        autoPlay="false" 
        panelWidth="540"        
        showCaption="true" 
        widgetVar="myGalleria">     

    <p:graphicImage width="520" 
                    id="img"
                    title="#{item.description}"
                    value="/imageServlet/show?id=#{item.id}" 
                    cache="false" />
</p:galleria>

ImageServlet

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    String id = request.getParameter("id"); 

    if(StringUtils.isNotBlank(id)) {

        try {

            byte[] dados = myService.getImageData(id);
            if(dados != null) {

                String fileName = id.concat(EXTENSAO_ARQUIVO);

                response.setHeader("Content-Type", getServletContext().getMimeType(fileName));
                response.setHeader("Content-Length", String.valueOf(dados.length));
                response.setHeader("Content-Disposition", "inline; filename=\"" + fileName + "\"");

                // configuracoes de cache
                response.setHeader("Cache-control", "no-cache, no-store");
                response.setHeader("Pragma", "no-cache");
                response.setHeader("Expires", "-1");

                InputStream in = new ByteArrayInputStream(dados);
                OutputStream out = response.getOutputStream();

                IOUtils.copy(in, out);

                if(in != null) {
                    in.close();
                }
                if(out != null) {
                    out.close();
                }
            }           
        } catch (Exception e) {
            // TODO: log
            e.printStackTrace();
        }
    }
}

MyImage类

public class MyImage {
   private String id;
   private String description;
}

MyBean类

public class MyBean {
   List<MyImage> imageList = myService.getImageList();
}
jsf primefaces image-gallery
1个回答
1
投票

这可能是Primefaces UI issue with Gallery Film strip的副本,请参阅我的解决方法:

<p:commandLink onclick="PF('popup').show();" update="galleria"/>
<p:dialog id="popup">
    <p:galleria id="galleria"/>
</p:dialog>
© www.soinside.com 2019 - 2024. All rights reserved.