0

基本上,我有一个 primefaces 数据网格组件,它渲染来自p:fileuploadwith的上传图像multiple="true"

问题是当我将update属性设置p:fileupload为数据网格(实际上是包含数据网格的表单)时,数据网格只显示一个图像,而不是所有图像。

这是我的代码:

<p:fileUpload
    fileUploadListener="#{galleriesManagedBean.handleFileUpload}"
    mode="advanced" multiple="true" sizeLimit="1000000"
    allowTypes="/(\.|\/)(gif|jpe?g|png)$/" showButtons="true"
    update=":formTabView" />

和 :

<p:dataGrid var="photo"
    value="#{galleriesManagedBean.photos}" columns="4" rows="8"
    paginator="true"
    paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink}
            {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
    rowsPerPageTemplate="8,16,24"
    styleClass="ui-datagrid-content"
    style="width:700px;table-layout: fixed;">
    <p:panel style="text-align:center;width:155px;height:170px;">
        <h:panelGrid columns="1" style="text-align:center;">
            <p:graphicImage value="#{photo.image_thumbnail_url}" />

            <p:commandLink update=":formPhotoDialog:photoDetail"
                oncomplete="photoDialog.show()" title="Show Photo">
                <h:outputText styleClass="ui-icon ui-icon-arrow-4-diag"
                    style="margin:0 auto;" />
                <f:setPropertyActionListener value="#{photo}"
                    target="#{galleriesManagedBean.selectedPhoto}" />
            </p:commandLink>
            <p:commandLink update=":formTabView" title="Delete Photo"
                action="#{galleriesManagedBean.deletePhoto}" >
                <h:outputText styleClass="ui-icon ui-icon-trash"
                    style="margin:0 auto;" />
                <f:setPropertyActionListener
                target="#{galleriesManagedBean.selectedPhoto}" value="#{photo}" />
            </p:commandLink>
        </h:panelGrid>
    </p:panel>
</p:dataGrid>

和附加的托管bean:

...

    public void handleFileUpload(FileUploadEvent event)
{

    BufferedImage resizedImage;
    BufferedImage resizedThumbnailImage;

    try
    {
        resizedImage = AlbumPhoto.resizeImage(640, 960, event.getFile().getInputstream());
        resizedThumbnailImage = AlbumPhoto.resizeImage(150, 150, event.getFile().getInputstream());
    }
    catch(IOException e1)
    {
        e1.printStackTrace();
        return;
    }

    String imageName = AlbumPhoto.createImageName(Integer.parseInt(selectOneAlbum));
    String imageNameThumbnail = imageName + "th";

    //save files images to server images directory
    try
    {
        ImageIO.write(resizedImage, "png", new File(Configuration.getImagesServer() + File.separator + imageName + ".png"));
        ImageIO.write(resizedThumbnailImage, "png", new File(Configuration.getImagesServer() + File.separator + imageNameThumbnail + ".png"));
    }
    catch(IOException e1)
    {
        e1.printStackTrace();
        return;
    }

    //save images into database
    AlbumPhoto photo = new AlbumPhoto("/usekImages/" + imageName + ".png", "/usekImages/" + imageNameThumbnail + ".png", Integer.parseInt(selectOneAlbum));
    photo.insertAlbumPhoto();

    //refresh data grid
    refrech();
}

...

    private void refrech()
{
    this.photos = galleryService.getAllAlbumPhotos(Integer.parseInt(selectOneAlbum));
}
4

0 回答 0