function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Madhura BMadhura B 

Problem Rerendering an element

Hi

 

I have a pageblocktable which has to be rerendered in order to dispaly the updated field values but it fails to do so.

Following is my code.

 

Please help me resolve the issue.

 

<apex:page sidebar="false" Controller="MyLibrary">

 <apex:form >
   <apex:pageBlock >
    <apex:pageBlockSection columns="1">
    
     <apex:PanelGrid width="30%">
       <apex:pageBlockSection >
           <apex:outputLabel value="Parent Folder" styleClass="labelCol first last" for="parent"/>
               <apex:selectList value="{!SelectedParentFolder}" size="1" id="parent" >
                      <apex:selectOptions value="{!ParentFolderList}" />
                       <apex:actionSupport event="onchange" reRender="folder"/>
               </apex:selectList>
         </apex:pageBlockSection>   
      </apex:PanelGrid>
     
 
        <apex:PanelGrid id="folder" width="30%">
             <apex:pageBlockSection >
             <apex:outputLabel value="Sub Folder" styleClass="labelCol first last" for="sfolder"/>
                   <apex:selectList value="{!SelectFolder}" size="1" id="sfolder" >
                          <apex:selectOptions value="{!FolderList}" />
                           <apex:actionSupport event="onchange" reRender="docs" action="{!Go}"/>
                   </apex:selectList>
             </apex:pageBlockSection>
       </apex:PanelGrid>  
   
  </apex:pageBlockSection>

 

<apex:pageBlockSection columns="1" id="docs">
    <apex:pageMessage severity="info" summary="Sorry the Folder has no Content to display." rendered="{!if(UserLib.size!=0,if(Docs.size==0,true,false),false)}"/>

   <apex:pageBlockTable value="{!Docs}" var="d" rendered="{!if(Docs.size>0,true,false)}" id="mytable">
    
       <apex:column >
             
               <apex:outputLink value="/servlet/servlet.FileDownload?file={!d.Document_Id__c}" >
                 <apex:image url="{!URLFOR($Resource.LibraryImages)}" title="Click to Download" />  
               
                 <apex:actionSupport event="onclick" rerender="mytable" action="{!incrementCounter}">
                       <apex:param assignTo="{!SelectedId}" name="selId" value="{!d.Id}"/>
                 </apex:actionSupport>
                 
               </apex:outputLink>   
           </apex:column>


<apex:column headerValue="Downloaded" >
            <apex:outputText value="{!d.Counter__c}" />   
     </apex:column>
     
   
   </apex:pageBlockTable>
</apex:pageBlockSection>
 </apex:pageBlock>

--------------------------------------

 

 public void go()
 {
     
       Docs=new List<Document_Details__c>();
       Docs.clear(); 
       
     try{
 
       MyLib=[select id from My_Library__c where Folder__c=:SelectFolder];
       UserLib =[select Accessed_by_User__c from User_Library__c where My_Library__c=: MyLib.id ];
       
      if(UserLib.size()!=0)
      {
          
           for (Integer j = 0; j< UserLib.size(); j++)
            {
               if(u.id==UserLib[j].Accessed_by_User__c)
               {   
                    Docs=[Select id, Name__c, Document_Id__c, counter__c,Uploaded_by__c,Type__c,Description__c,Document_Created_On__c,My_Library__c From Document_Details__c where My_Library__c=: MyLib.id order by Name__c ];
                    system.debug('***'+docs);
                                   
               }
               
            }   
      }
      
      
    
   }catch(Exception e){}
 }
 
    public pagereference incrementCounter()
    {
       
        UpdateCount = [select id, counter__c from Document_Details__c where id =:SelectedId];  
        
        Decimal num= updatecount.counter__c;
        updatecount.counter__c=num+1;

        update updatecount;
        
        go();
               
      return null;
       
        
    }
             
The pageBlockTable doesn't seem to rerender. however the counter is working fine.

 

Best Answer chosen by Madhura B
Madhura BMadhura B

I used command link, and added the whole pageblocksection i wanted to reRender in a pageblock rendered in an outputpanel and gave it a differnt id. To download the docuemnt I gave window.open in onClick... And it worked!!

 

 

<apex:page sidebar="false" Controller="MyLibrary">
 <apex:form >
   <apex:pageBlock >
    <apex:pageBlockSection columns="1">
    
     <apex:PanelGrid width="50%">
       <apex:pageBlockSection >
           <apex:outputLabel value="Parent Folder" styleClass="labelCol first last" for="parent"/> 
               <apex:selectList value="{!SelectedParentFolder}" size="1" id="parent" >
                      <apex:selectOptions value="{!ParentFolderList}" />
                       <apex:actionSupport event="onchange" reRender="folder"/>
               </apex:selectList> 
         </apex:pageBlockSection>   
      </apex:PanelGrid> 
     
  
        <apex:PanelGrid id="folder" width="50%">
             <apex:pageBlockSection >
             <apex:outputLabel value="Sub Folder" styleClass="labelCol first last" for="sfolder"/> 
                   <apex:selectList value="{!SelectFolder}" size="1" id="sfolder" >
                          <apex:selectOptions value="{!FolderList}" /> 
                           <apex:actionSupport event="onchange" reRender="docs" action="{!Go}"/>
                   </apex:selectList> 
             </apex:pageBlockSection>
       </apex:PanelGrid>  
   
   </apex:pageBlockSection>
 
</apex:pageBlock>

<apex:outputPanel id="docs">
<apex:pageBlock id="docs1">   
<apex:pageBlockSection columns="1" > 
     
    <apex:pageMessage severity="info" summary="Sorry the Folder has no Content to display." rendered="{!if(Docs.size==0,if(accessed==true,true,false),false)}"/>
    <apex:pageMessage severity="info" summary="Sorry you are not a member of this Library." rendered="{!if(accessed==false,true,false)}" />
 

   <apex:pageBlockTable value="{!Docs}" var="d" rendered="{!if(Docs.size>0,true,false)}" > 
    
     <apex:column headerValue="Name" >
       <apex:outputField value="{!d.Name__c}" />
     </apex:column> 
     
     <apex:column headerValue="Description">
       <apex:outputField value="{!d.Description__c}" />
     </apex:column>
     
     <apex:column headerValue="Type">
       <apex:outputField value="{!d.Type__c}" /> 
     </apex:column>
     
    <apex:column headerValue="Uploaded By">
       <apex:outputField value="{!d.Uploaded_By__c}" /> 
     </apex:column>
     
     <apex:column headerValue="Created Date">
       <apex:outputField value="{!d.Document_Created_On__c}" /> 
     </apex:column>
  
    <apex:column >
                         
               <apex:commandLink action="{!incrementCounter}" reRender="docs1" onClick="window.open('/servlet/servlet.FileDownload?file={!d.Document_Id__c}','_blank')" >
                 <apex:param assignTo="{!SelectedId}" name="selId" value="{!d.Id}"/>     
                    <apex:image url="{!URLFOR($Resource.LibraryImages)}" title="Click to Download" />
               </apex:commandLink>  
             
     </apex:column>
     
    
     <apex:column headerValue="Downloaded" >
            <apex:outputText value="{!d.Counter__c}" />   
     </apex:column>
     
  
   </apex:pageBlockTable> 
 
    
</apex:pageBlockSection>


 </apex:pageBlock>
</apex:outputPanel>   
 </apex:form>

</apex:page>

jd123 wrote:

Hi Madura,

 

Ones remove Action support and write the Command button or link I think it will work. Even I have faced the same problem in the past.

 

Thanks 


 

 

All Answers

bob_buzzardbob_buzzard

Given that you are conditionally rendering the table, I'd say you are trying to rerender an element that doesn't exist (i.e. wasn't rendered in the first place).

 

I've written a blog post about this at:

 

http://bobbuzzard.blogspot.co.uk/2011/02/visualforce-re-rendering-woes.html

Madhura BMadhura B

Even if I reRender the pageBlockSection where my table is placed or I add the whole pageBlockSection in an outpanel to reRender it isn't working!!

 

bob_buzzardbob_buzzard

It may be that you have an exception that is being swallowed.  Try adding a pagemessages and appending the id of that to the rerender attribute.

jd123jd123

Hi Madura,

 

Ones remove Action support and write the Command button or link I think it will work. Even I have faced the same problem in the past.

 

Thanks 

Madhura BMadhura B

I used command link, and added the whole pageblocksection i wanted to reRender in a pageblock rendered in an outputpanel and gave it a differnt id. To download the docuemnt I gave window.open in onClick... And it worked!!

 

 

<apex:page sidebar="false" Controller="MyLibrary">
 <apex:form >
   <apex:pageBlock >
    <apex:pageBlockSection columns="1">
    
     <apex:PanelGrid width="50%">
       <apex:pageBlockSection >
           <apex:outputLabel value="Parent Folder" styleClass="labelCol first last" for="parent"/> 
               <apex:selectList value="{!SelectedParentFolder}" size="1" id="parent" >
                      <apex:selectOptions value="{!ParentFolderList}" />
                       <apex:actionSupport event="onchange" reRender="folder"/>
               </apex:selectList> 
         </apex:pageBlockSection>   
      </apex:PanelGrid> 
     
  
        <apex:PanelGrid id="folder" width="50%">
             <apex:pageBlockSection >
             <apex:outputLabel value="Sub Folder" styleClass="labelCol first last" for="sfolder"/> 
                   <apex:selectList value="{!SelectFolder}" size="1" id="sfolder" >
                          <apex:selectOptions value="{!FolderList}" /> 
                           <apex:actionSupport event="onchange" reRender="docs" action="{!Go}"/>
                   </apex:selectList> 
             </apex:pageBlockSection>
       </apex:PanelGrid>  
   
   </apex:pageBlockSection>
 
</apex:pageBlock>

<apex:outputPanel id="docs">
<apex:pageBlock id="docs1">   
<apex:pageBlockSection columns="1" > 
     
    <apex:pageMessage severity="info" summary="Sorry the Folder has no Content to display." rendered="{!if(Docs.size==0,if(accessed==true,true,false),false)}"/>
    <apex:pageMessage severity="info" summary="Sorry you are not a member of this Library." rendered="{!if(accessed==false,true,false)}" />
 

   <apex:pageBlockTable value="{!Docs}" var="d" rendered="{!if(Docs.size>0,true,false)}" > 
    
     <apex:column headerValue="Name" >
       <apex:outputField value="{!d.Name__c}" />
     </apex:column> 
     
     <apex:column headerValue="Description">
       <apex:outputField value="{!d.Description__c}" />
     </apex:column>
     
     <apex:column headerValue="Type">
       <apex:outputField value="{!d.Type__c}" /> 
     </apex:column>
     
    <apex:column headerValue="Uploaded By">
       <apex:outputField value="{!d.Uploaded_By__c}" /> 
     </apex:column>
     
     <apex:column headerValue="Created Date">
       <apex:outputField value="{!d.Document_Created_On__c}" /> 
     </apex:column>
  
    <apex:column >
                         
               <apex:commandLink action="{!incrementCounter}" reRender="docs1" onClick="window.open('/servlet/servlet.FileDownload?file={!d.Document_Id__c}','_blank')" >
                 <apex:param assignTo="{!SelectedId}" name="selId" value="{!d.Id}"/>     
                    <apex:image url="{!URLFOR($Resource.LibraryImages)}" title="Click to Download" />
               </apex:commandLink>  
             
     </apex:column>
     
    
     <apex:column headerValue="Downloaded" >
            <apex:outputText value="{!d.Counter__c}" />   
     </apex:column>
     
  
   </apex:pageBlockTable> 
 
    
</apex:pageBlockSection>


 </apex:pageBlock>
</apex:outputPanel>   
 </apex:form>

</apex:page>

jd123 wrote:

Hi Madura,

 

Ones remove Action support and write the Command button or link I think it will work. Even I have faced the same problem in the past.

 

Thanks 


 

 

This was selected as the best answer