0

参考: http: //www.primefaces.org/showcase/ui/galleria.jsf

我的页面:

<p:galleria id="merchant-gallery" value="#{testController.imageIds}" var="item" autoPlay="false" >  
    <p:graphicImage width="300" value="#{imageStreamer.image}" >
        <f:param name="id" value="#{item}" />
    </p:graphicImage>
</p:galleria>  

我尝试将其包含<p:galleria>在一个表格中并添加了一个<p:remoteCommand name="updateme" update="@form"/>,但在调用 updateme 之后,它只是让 Galleria 空白。

*更新

测试控制器 bean:

public List<Integer> getImageIds() {
    int aId = (Integer) FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get("user_id");
    EntityManagerFactory emf = Persistence.createEntityManagerFactory("TEST2PU");
    EntityManager em = emf.createEntityManager();
    TypedQuery<Merchant> tp = em.createQuery("SELECT a FROM Account a WHERE a.id = :id", Account.class);
    tp.setParameter("id", aId);
    current = tp.getSingleResult();

    Collection rawPhotoCollection = current.getPhotoCollection();

    imageIds = new ArrayList<Integer>(rawPhotoCollection);
    List<Photo> photoList = new ArrayList<Photo>(rawPhotoCollection);

    for (int i = 0; i < photoList.size(); i++) {
        int imageId = photoList.get(i).getId();
        imageIds.set(i, imageId);
    }

    return imageIds;
}

imageStreamer 豆:

@EJB
private test.controller.photo.PhotoFacade ejbFacade;

public StreamedContent getImage() throws IOException {
    FacesContext context = FacesContext.getCurrentInstance();

    if (context.getCurrentPhaseId() == PhaseId.RENDER_RESPONSE) {
        return new DefaultStreamedContent();
    } else {
        Map<String, String> param = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap();
        String id = param.get("id");

        Photo image = ejbFacade.find(Integer.valueOf(id));
        return new DefaultStreamedContent(new ByteArrayInputStream(image.getImage()));
    }
}
4

1 回答 1

1

我修改了您的示例并遇到了同样的问题。它与您的上传或远程命令无关。我认为这是primefaces中的一个错误。有关类似问题,请参阅http://code.google.com/p/primefaces/issues/detail?id=4840。当我执行命令时

PrimeFaces.cw('Galleria','widget_companydetail_merchant-gallery',{id:'companydetail:merchant-gallery',transitionInterval:0,panelWidth:640,panelHeight:480,custom:false},'galleria');

在萤火虫控制台中,画廊重新出现。因此,当更改远程命令并将 javascript 添加到 oncomplete 时,它​​可以工作。

<p:remoteCommand name="updateme" update="@form" oncomplete="PrimeFaces.cw('Galleria','widget_companydetail_merchant-gallery',{id:'companydetail:merchant-gallery',transitionInterval:0,panelWidth:640,panelHeight:480,custom:false},'galleria');"/>
于 2013-03-27T13:06:25.727 回答