RichFaces fileUpload无法重新呈现 [英] RichFaces fileUpload not reRendering

查看:79
本文介绍了RichFaces fileUpload无法重新呈现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在上传文件(照片)后重新渲染几个组件,但是由于某种原因,在完成上传后,这些组件不会被重新渲染.谁能帮忙吗? 我正在64位Windows 7计算机上使用Java 1.6 JSF 1.2 Richfaces 3.3.3 Seam 2.2GA在Tomcat 6中运行该应用程序;

I'm trying to rerender a couple of components following the upload of a file (a photo) but for some reason, upon completion of the upload, the components are not being rerendered. Could anyone please help? I'm using Java 1.6 JSF 1.2 Richfaces 3.3.3 Seam 2.2GA on a 64 bit Windows 7 machine running the app in Tomcat 6;

<h:panelGrid columns="2" id="photoGrid"
    rendered="#{not signUpAction.fileUpRendered}"     styleClass="standard">
    <h:graphicImage value="#{signUpAction.imageUrl}" width="150" height="171" />
    <a4j:region>
        <a4j:commandLink id="remove" action="#{signUpAction.removePhoto}"
            reRender="a4jphotoUpload" value="Remove Photo" />
    </a4j:region>                               
</h:panelGrid>
<h:panelGroup id="photoGroup" rendered="#{signUpAction.fileUpRendered}">
    <rich:fileUpload maxFilesQuantity="1"
        fileUploadListener="#{signUpAction.listener}"
        addControlLabel="Add a photo..." allowFlash="true"
        id="photoUploadWidget" autoclear="true"
        listHeight="1" immediateUpload="true" acceptedTypes="jpg,jpeg,png,gif">
        <f:facet name="label">
            <h:outputText value="{_KB}KB from {KB}KB uploaded --- {mm}:{ss}" />
        </f:facet>
        <a4j:support event="onuploadcomplete" reRender="photoGrid,photoGroup"/>
    </rich:fileUpload>
</h:panelGroup>

我终于找到了解决方案,我调用了a4j:jsFunction来重新渲染组件并从onuploadcomplete事件中调用它(请参见下面的代码)

I finally figured out a solution, I call a a4j:jsFunction that rerenders the components and call it from the onuploadcomplete event (see the code below)

<h:panelGroup id="photoGroup" rendered="#{signUpAction.fileUpRendered}">
    <rich:fileUpload maxFilesQuantity="1" fileUploadListener="#{signUpAction.listener}"
    addControlLabel="Add a photo..."
    id="photoUploadWidget" autoclear="true" onuploadcomplete="reloadPhotoPanel()" onfileuploadcomplete="reloadPhotoPanel()"
    listHeight="1" immediateUpload="true" acceptedTypes="jpg,jpeg,png,gif">
    </rich:fileUpload>
</h:panelGroup>     
</a4j:outputPanel>  

<a4j:jsFunction id="reloadPhotoPanel" name="reloadPhotoPanel" reRender="photoPanel,photoGrid,photoGroup" />

推荐答案

问题是您正在尝试重新呈现第一次加载页面时未呈现的组件,该组件将是photoGrid组件.

The problem is that you're trying to rerender a component that isn't rendered the first time the page loaded, this would be the photoGrid component.

为了使其正常工作,应将非渲染器组件包装在始终会渲染的UIContainer(如<a4j:outputPanel>)中,然后重新渲染更大的容器.

In order to make it work, you should wrap the non-rendererd component inside a UIContainer (like <a4j:outputPanel>) that will be always rendered and rerender the bigger container.

<!--
     now you will rerender the a4j:outputPanel 
     and the inner h:panelGrid will appear/dissapear
-->
<a4j:outputPanel id="photoGrid">
    <h:panelGrid columns="2"
        rendered="#{not signUpAction.fileUpRendered}"     styleClass="standard">
        <h:graphicImage value="#{signUpAction.imageUrl}" width="150" height="171" />
        <a4j:region>
            <a4j:commandLink id="remove" action="#{signUpAction.removePhoto}"
                reRender="a4jphotoUpload" value="Remove Photo" />
        </a4j:region>                               
    </h:panelGrid>
</a4j:outputPanel>
<!--
     following the same logic in the h:panelGroup that renders
     the rich:fileUpload component
-->
<a4j:outputPanel id="photoGroup">
    <h:panelGroup rendered="#{signUpAction.fileUpRendered}">
        <rich:fileUpload maxFilesQuantity="1"
            fileUploadListener="#{signUpAction.listener}"
            addControlLabel="Add a photo..." allowFlash="true"
            id="photoUploadWidget" autoclear="true"
            listHeight="1" immediateUpload="true" acceptedTypes="jpg,jpeg,png,gif">
            <f:facet name="label">
                <h:outputText value="{_KB}KB from {KB}KB uploaded --- {mm}:{ss}" />
            </f:facet>
            <a4j:support event="onuploadcomplete" reRender="photoGrid,photoGroup"/>
        </rich:fileUpload>
    </h:panelGroup>
</a4j:outputPanel>

这篇关于RichFaces fileUpload无法重新呈现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆