Primefaces fileUpload only works firts time

早过忘川 提交于 2019-12-25 03:05:07

问题


When I upload a file, I need to update some componentes. It only works first time I do it.

XHTML:

<p:fileUpload id="Uploader" fileUploadListener="#{cc.attrs.updateImageAction}"  
                    mode="advanced"
                    update="#{cc.id}:updatableElements #{cc.attrs.ajaxRender} #{cc.attrs.ajaxRenderCropDialog}"
                    auto="true" 
                    multiple="false" 
                    sizeLimit="#{cc.attrs.sizeLimit}"   
                    allowTypes="#{imageManagerServiceBean.imageFileAllowedTypesRegEx}"
                    label="#{messages['generic.images.select']}"
                    uploadLabel="#{messages['generic.images.upload']}"
                    cancelLabel="#{messages['generic.images.cancel']}"
                    invalidSizeMessage="#{cc.attrs.invalidFileSizeMessage}"
                    invalidFileMessage="#{messages['generic.images.invalidtype']}"
                    >
            </p:fileUpload>

Any idea?


回答1:


I have solved the problem. I don't know why but changing the value of #{cc.attrs.ajaxRenderCropDialog}, the update works.

Before: :artistImageCropperDialog:imageCropperDialog

After: :artistImageCropperDialog:imageCropperForm

ImageCropperDialog xhtml code:

        <h:panelGroup layout="block" styleClass="links">
            <h:panelGroup id="imageCropperDialog" layout="block" styleClass="hidden">
                <h:form id="imageCropperForm">
                        <h:panelGrid>
                            <p:imageCropper id="cropperImage" value="#{cc.attrs.croppedImage}"
                                image="/upload/#{cc.attrs.imageTmp}"
                                initialCoords="#{cc.attrs.initialCoords}"
                                aspectRatio="1"
                                minSize="#{cc.attrs.minSize}"
                                required="true"
                                requiredMessage="Hay que seleccionar parte de la imagen"
                                />
                        </h:panelGrid>
                    <h:commandButton id="acceptButton" action="#{cc.attrs.acceptCropAction}" styleClass="hidden">
                        <f:ajax execute="@form" render="@form :messages :form:pictureHandler:updatableElements" onevent="onAcceptCropEvent"/>
                    </h:commandButton>

                    <h:commandButton id="cancelButton" action="#{cc.attrs.cancelCropAction}" styleClass="hidden">
                         <f:ajax execute="@this" render="@form :messages"/>
                    </h:commandButton>

                </h:form>
            </h:panelGroup>
        </h:panelGroup>
    </composite:implementation>

Declaration of dialog in other xhtml:

<ui:define name="dialogs">
        <app:imageCropperDialog id="artistImageCropperDialog"
                        croppedImage="#{festivalArtistEditPageBean.croppedImage}"
                        imageTmp="#{festivalArtistEditPageBean.imageTemp}"
                        acceptCropAction="#{festivalArtistEditPageBean.cropImage()}"
                        cancelCropAction="#{festivalArtistEditPageBean.cancelCropImage()}"
                        minSize="#{festivalArtistEditPageBean.cropMinSize}"
                        initialCoords="#{festivalArtistEditPageBean.cropInitialCoords}"
                        >
        </app:imageCropperDialog>
    </ui:define>


来源:https://stackoverflow.com/questions/22414069/primefaces-fileupload-only-works-firts-time

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!