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
MattLMattL 

Issues with rerender

I have a VisualForce page that contains an attachment upload (basically, overriding the attachments related list). However, upon upload, the page refreshes entirely. This normally wouldn't be a problem, except that it doesn't re-render the detail, and that section is rather important to the overall flow of the page. I was under the impression that rerender would rebuild the list with a partial page refresh... however, I attempted to use this functionality when adding documents from Salesforce, and while the document is added, you don't see it in the list until you do a manual refresh. What am I doing wrong?

VisualForce Page
Code:
<apex:page standardController="Agreement__c" extensions="documentExt,ec_mod_cntrl" >
    <apex:detail relatedList="false" />
    <apex:pageBlock >
        <apex:pageBlockSection title="Attachments">
            <apex:pageBlockTable border="0" cellpadding="6" value="{!attachments}" var="a" id="rows">
                <apex:column headerValue="Title"><apex:outputField value="{!a.Name}" /></apex:column>
                <apex:column headerValue="Last Modified"><apex:outputField value="{!a.LastModifiedDate}" /></apex:column>
                <apex:column headerValue="Created By"><apex:outputField value="{!a.LastModifiedById}" /></apex:column>
            </apex:pageBlockTable>
            <br />
            <apex:tabPanel switchType="client" selectedTab="File">
                <apex:tab label="From File" name="File" id="file">
                    <apex:form id="newfile">
                        <apex:inputFile value="{!attachment.body}" filename="{!attachment.name}" />
                        <apex:commandButton value="submit" action="{!save}" />
                    </apex:form>
                </apex:tab>
                <apex:tab label="From Salesforce" name="SFDC" id="sfdc">
                    <apex:form id="newsf">
                        <apex:selectList size="1" value="{!selectedProd}">
                            <apex:selectoptions value="{!items}" />
                        </apex:selectList>
                        <apex:commandButton value="Find Documents" rerender="doc" />
                        <br />
                        <apex:outputPanel id="doc">
                            <apex:actionStatus startText="Polling Folder {!selectedProd}">
                                <apex:facet name="stop">
                                    <apex:selectList size="1" value="{!selectedDoc}">
                                        <apex:selectoptions value="{!items2}" />
                                    </apex:selectList>
                                </apex:facet>
                            </apex:actionStatus>
                        </apex:outputPanel>
                        <apex:commandButton value="Add Document" action="{!svdoc}" rerender="rows" />
                    </apex:form>
                </apex:tab>
                <apex:tab label="From External Respository" name="ECRepo" id="ecrepo">
                    <apex:pageMessage detail="A link to the external Repository goes here." severity="warning" />
                </apex:tab>
            </apex:tabPanel>
        </apex:pageBlockSection>
    </apex:pageBlock>
</apex:page>

 Controller Extension documentExt
Code:
public class documentExt {
 private final String ecagree;
 public Attachment attachment {get;set;}
 
 public PageReference save() {
  attachment.parentid = ecagree;
  insert attachment;
  return null;
 }
 
 public documentExt(ApexPages.StandardController controller) {
  attachment = new Attachment();
  this.ecagree = ApexPages.currentPage().getParameters().get('id');
  this.stdController = stdController;
 }
 
 ApexPages.StandardController stdController;
}

Controller Extension ec_mod_cntrl
Code:
public class ec_mod_cntrl {
 public String selectedProd {get;set;}
 public String selectedDoc {get;set;}
 public List<Attachment> attachList;
 public List<SelectOption> docs = new List<SelectOption>();
 public PageReference reset() {
     attachList = [select id, Name, LastModifiedDate, LastModifiedById from Attachment where ParentId = :ApexPages.currentPage().getParameters().get('id')];
        return null;
    }
 public List<Attachment> getAttachments() {
     if(attachList == null) reset(); 
        return attachList;
    }
    public void setAttachments(List<Attachment> Attach) {
        attachList = Attach;
    }
 public ec_mod_cntrl(ApexPages.StandardController controller) {
  
 }
 public List<SelectOption> getItems() {
     List<SelectOption> dfolder = new List<SelectOption>();
        for(Folder fd : [Select Id, Name from Folder where Type='Document']) dfolder.add(new SelectOption(fd.Id, fd.Name));
        return dfolder;
    }
    public List<SelectOption> getItems2() {
     queryDocs();
     return docs;
    }
    public PageReference queryDocs() {
     docs.clear();
     for(Document d : [Select Id, Name from Document where FolderId=:selectedProd]) docs.add(new SelectOption(d.Id, d.Name));
     return null;
    }
    public void svdoc() {
     Document d1 = [Select Id, Body, Description, Name, Type from Document where Id=:selectedDoc];
     if(d1!=null)
     {
      Attachment a1 = new Attachment();
      a1.Body=d1.Body;
      a1.ContentType=d1.Type;
      a1.Name=d1.Name;
      a1.ParentId=ApexPages.currentPage().getParameters().get('id');
      insert a1;
     }
    }
}

 

 


Ron HessRon Hess
Hi Matt,
 There is a known limitation with input File, please review Jill's comment here
http://community.salesforce.com/sforce/board/message?board.id=Visualforce&message.id=6817

your entire page should refresh, not sure why the detail page is not shown after this refresh

I can suggest that you add subject={!xx} to your detail component.

so, something like
Code:
<apex:detail subject="{!Agreement__c.id}" relatedList="false" />

 


MattLMattL
Thanks Ron. Adding the subject parameter to my detail fixed that issue right up.

The other issue, however, is that it still requires another (manual) refresh for anything added to the list to show up. When the page refreshes after submitting a file from my computer, the file doesn't appear. Doing a ctrl-r on the page displays it.
Similar behavior occurs when I attempt to add a document from the Org.

Is there something I'm missing with my rerender="rows" statement?
Ron HessRon Hess
It looks like you have two different forms on one Visualforce page. 

I believe that one form is all that is needed, and it may fix the issue you describe.

I normally put one apex : form tag at the start of the page and close it at the end.


Message Edited by Ron Hess on 01-05-2009 02:51 PM