primefaces重新加载广场

时间:2013-03-26 06:02:36

标签: jsf primefaces

参考: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之后,它只是将广告空白。

*更新

testController 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 bean:

@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()));
    }
}

1 个答案:

答案 0 :(得分:1)

我重写了你的例子并遇到了同样的问题。它与您的上传或远程命令无关。我认为这是一个错误的表面。有关类似问题,请参阅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');
在firebug控制台中,Galleria重新出现。 因此,当更改remotecommand并将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');"/>