2013-03-26 85 views
0

參考:http://www.primefaces.org/showcase/ui/galleria.jsfprimefaces重裝廣場

我的網頁:

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

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

你想達到什麼目的? – roel 2013-03-26 09:13:08

+0

我有一個''功能,上傳每張圖片後,我想重新加載環球免稅店而不刷新頁面。 – galao 2013-03-26 09:23:44

+0

你可以發佈一些bean代碼嗎?你確定圖像在那裏,並且.imageIds在你上傳之後不是空的嗎? – roel 2013-03-26 10:16:57

回答

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'); 
在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');"/> 
+0

嗨,即時通訊混淆什麼'widget_companydetail_merchant-gallery'和companydetail:merchant-gallery是,'companydetail'的形式的名稱? – galao 2013-04-01 04:04:31

+0

哦,我明白了!哇!謝謝! :d – galao 2013-04-01 08:05:24