2013-01-19 25 views
1

我試圖重新渲染一個文件(照片)上傳後的幾個組件,但由於某種原因,上傳完成後,組件不會被重新渲染。任何人都可以請幫忙? 我在運行Tomcat 6應用程序的64位Windows 7機器上使用Java 1.6 JSF 1.2 Richfaces 3.3.3 Seam 2.2GA;RichFaces fileUpload notre rendering

<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事件調用它(見下面的代碼)

<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" /> 

回答

2

問題是,你試圖重新渲染一個組件,該組件在第一次加載頁面時沒有呈現,這將是photoGrid組件。

爲了使其工作,您應該將非rendererd組件包裝在一個UIContainer(如<a4j:outputPanel>)中,該組件將始終呈現並重新渲染較大的容器。

<!-- 
    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> 
+0

感謝Luiggi,我想你的建議都沒有用,我仍然有同樣的問題是什麼。 –

+0

@KennethNjendu答案更新。我注意到''也應該像這樣封閉。 –