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
tonante27tonante27 

Calling <apex:repeat> from A Command Button

 

Is there any way that I can call  <apex:repeat>   from a command button (that sits within a <apex:pageBlockButtons> tag ) in order to store the output in an Excel spreadsheet? How do I associate the command button with this reapeat tag? Here is the code segment where I am having problems using the repeat tag. (variable lstwrapper is a List<Wrapper> amd wrapper is a class). Thanks much for your help and advice.:

 

 

 

<apex:pageBlock title="Subscription Issues">
    
    <apex:pageBlockButtons >
       <div style="display:inline; padding-left:10%; " id="SubscriptionSpacer1"></div>
            <apex:commandButton value="Get Subscriptions!" action="{!GetQuerySubscriptions}"  status="status"  />
           <apex:commandButton value="Decrement Subscriptions!" action="{!decrementAllIssues}" />
           <apex:commandButton value="Export to Excel" action="{!ExportToExcel}">            
               <apex:pageBlockTable>
                 <apex:repeat value="{!lstwrapper}" var="w">
                     <apex:outputText value="{!w.sid}" />
                     <apex:outputText value ="{!w.acctId}" />
                     <apex:outputText value="{!w.mAttention}"/>
                     <apex:outputText value="{!w.Street1}" />
                     <apex:outputText value="{!w.Street2}" />
                     <apex:outputText value="{!w.Street3}" />
                     <apex:outputText value="{!w.state}" />
                     <apex:outputText value="{!w.zip}" />
                     <apex:outputText value="{!w.name}" />
                     <apex:outputText value="{!w.productName}" />
                     <apex:outputText value="{!w.description}" />
                     <apex:outputText value="{!w.qty}" />
                     <apex:outputText value="{!wlrdate}" />
                     <apex:outputText value="{!w.numissues}" />
                     <apex:outputText value="{!w.lissuessent}" />
                  </apex:repeat>
               </apex:pageBlockTable>
         </apex:commandButton>
    </apex:pageBlockButtons>

 

 

 

Best Answer chosen by tonante27
Gunners_23Gunners_23

I assume on click Export to Excel button you want to populate the table, to achieve put the pageblockTable inside the

 

outputPanel and reRender it on click of that button. Please check the code below

 

 

<apex:pageBlockButtons >
       <div style="display:inline; padding-left:10%; " id="SubscriptionSpacer1"></div>
            <apex:commandButton value="Get Subscriptions!" action="{!GetQuerySubscriptions}"  status="status"  />
           <apex:commandButton value="Decrement Subscriptions!" action="{!decrementAllIssues}" />
           <apex:commandButton value="Export to Excel" action="{!ExportToExcel}" reRender="wrapper">         

            <apex:outputPanel id="wrapper">
               <apex:pageBlockTable>
                 <apex:repeat value="{!lstwrapper}" var="w">
                     <apex:outputText value="{!w.sid}" />
                     <apex:outputText value ="{!w.acctId}" />
                     <apex:outputText value="{!w.mAttention}"/>
                     <apex:outputText value="{!w.Street1}" />
                     <apex:outputText value="{!w.Street2}" />
                     <apex:outputText value="{!w.Street3}" />
                     <apex:outputText value="{!w.state}" />
                     <apex:outputText value="{!w.zip}" />
                     <apex:outputText value="{!w.name}" />
                     <apex:outputText value="{!w.productName}" />
                     <apex:outputText value="{!w.description}" />
                     <apex:outputText value="{!w.qty}" />
                     <apex:outputText value="{!wlrdate}" />
                     <apex:outputText value="{!w.numissues}" />
                     <apex:outputText value="{!w.lissuessent}" />
                  </apex:repeat>
               </apex:pageBlockTable>
            </apex:outputPanel >        

</apex:commandButton>
    </apex:pageBlockButtons>