0

I want to clear the inputtext used to search, and clear all search results using a commandbutton. I tried the following on the 'Reset' button I added but it only clears the inputtext and the search results are not clearing.

<apex:pageBlockSectionItem >
                    <apex:outputPanel layout="block" Rendered="true">
                    <apex:inputText value="{!ReportSearchString}" />
                    <apex:commandButton value="Search" action="{!searchReports}" reRender="ReportSearchResults, "/> &nbsp;&nbsp; 
                    <apex:commandButton value="Back" action="{!BackToCreateFeedPage}"/>&nbsp;
                    <apex:commandButton value="Reset" onclick="this.form.reset();return false;"/>
                    </apex:outputPanel>
                </apex:pageBlockSectionItem>
                            </apex:pageBlockSection>
                        <apex:pageBlockSection id="ReportSearchResults">
                <apex:outputText value="{!warningMessage}" rendered="{!!showTable}" />
                <apex:pageBlockTable value="{!reportList}" var="item" rendered="{!showTable}">
                    <apex:column headerValue="Report Name" >
                        <apex:commandLink value="{!item.Name}" action="{!BackToCreateFeedPage}">
                            <apex:param value="{!item.Id}" name="SelectedReport" assignTo="{!selectedReportId}" />
                        </apex:commandLink>

This is my search function, it works fine. I need to clear the results of this search on clicking 'Reset' button.

 public void searchReports()
    {
        showTable = false;      
        reportList = new List<Report>(); 
        reportSearchResult = new Map<Id, Report>(); 
        selectedReport = new Report();
        if((ReportSearchString != null && ReportSearchString != '') && ReportSearchString.length() >= 3)
        {
            reportSearchResult = new Map<Id, Report>([Select Id, Name From Report Where Name Like :'%'+ReportSearchString+'%' limit 2000]);

            warningMessage = 'No Result Found';
        }
        else
        {
            warningMessage = 'Search text should have atleast 3 characters';
        }
    }
1

Page: have a id on first outputpanel and pageblocktable and rerender them after resetting the search string and search results.

<apex:commandButton value="Reset" action="{!reset}" rerender="OutPutPanelId PageBlockTableId"/>

Controller:

public void reset(){
   ReportSearchString = '';
   if(reportList != null){
       reportList.clear();
   }
}
| improve this answer | |
  • 1
    Thanks for the help. For some reason it did not work as expected. I tried using an actionsupport and it worked! – Tinkerbell Oct 10 '14 at 11:08
  • 1
    Glad you managed to make it work. Sorry for the untested code, just wanted to give you the idea. – highfive Oct 10 '14 at 11:11
  • 1
    No worries! Thanks so much for the support, your answer lead me to the correct path! Regards :) – Tinkerbell Oct 10 '14 at 11:12
1

Following technique with an actionsupport worked. I rerender the Pageblock.

<apex:pageBlock title="Please Search and Select a Source Report" id="pbBlock" >
            <apex:pageBlockSection columns="1">
                <apex:pageBlockSectionItem >
                    <apex:outputPanel layout="block" Rendered="true" id="panelId">
                        <apex:inputText value="{!ReportSearchString}" />
                        <apex:commandButton value="Search" action="{!searchReports}" reRender="ReportSearchResults, "/> &nbsp;&nbsp; 
                        <apex:commandButton value="Back" action="{!BackToCreateFeedPage}"/>&nbsp;
                        <apex:outputPanel style="padding:4.5px;" styleClass="btn" >
                            Reset
                            <apex:actionSupport event="onclick" action="{!reset}" rerender="pbBlock" />
                        </apex:outputPanel>
                    </apex:outputPanel>
                </apex:pageBlockSectionItem>
                <!-- <apex:commandButton value="Back" action="{!BackToCreateFeedPage}"/> -->
            </apex:pageBlockSection>

Method,

public pageReference reset()    {
      showTable = false;
      this.ReportSearchString = '';
      return null;    }
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.