0

In my code, I have 2 pageblockTable with 2 values(apex). They are displaying data in 2 different tables. First pageblockTable displays the data based on search button after giving input. Second pageBlockTable displays data when the page loads.

My requirement is to, When I click search button the second pageblockTable old data(default) should disappear and This search data should display in the second pageblockTable.

Visualforce page:

    <!--Searching and displaying the pageblockTable based on the Adharcard, Last name & surname-->

    <apex:pageBlock >
        <apex:pageBlockSection >

            <apex:outputLabel ><B>Search By</B></apex:outputLabel><BR/>
            <apex:selectList size="1" value="{!selectedPick}"> 
                <apex:selectOptions value="{!options}" ></apex:selectOptions>
            </apex:selectList><BR/>

            <apex:inputText label="Enter" value="{!inputValue}"/>

            <apex:commandButton value="Search" action="{!searchObjectRec}" reRender="SerachRcdId,recMatch, recNotMatch"/>
            <apex:pageBlockSection >                

                <apex:outputPanel id="SerachRcdId" >
                    <apex:pageblockSectionItem  rendered="{!searchMatch}">
                        <!--First  PageblockTable -->
                        <apex:pageblockTable value="{!searchObject}" var="ob">
                            <apex:column value="{!ob.name}"/>

                        </apex:pageblockTable>
                    </apex:pageblockSectionItem>

                </apex:outputPanel>

                <!--Fixed second PageblockTable -->

                <apex:outputPanel id="recMatch" >
                    <apex:pageblockSectionItem rendered="{!Match}" >

                        <apex:pageblockTable value="{!Objects}" var="obj">

                            <apex:column value="{!obj.name}"/>
                        </apex:pageblockTable>     
                    </apex:pageblockSectionItem>

                </apex:outputPanel>          
            </apex:pageBlockSection>

            <apex:pageBlockSection>
                <apex:outputPanel id="recNotMatch">
                    <apex:pageBlockSectionItem rendered="{!NoMatch}"> Record Not Found!</apex:pageBlockSectionItem>
                </apex:outputPanel>
            </apex:pageBlockSection>
        </apex:pageBlockSection>


        <!--Pagination-->

        <apex:panelGrid columns="7">
            <apex:commandButton status="fetchStatus" reRender="pb" value="|<" action="{!setCon.first}" disabled="{!!setCon.hasPrevious}" title="First Page"/>
            <apex:commandButton status="fetchStatus" reRender="pb" value="<" action="{!setCon.previous}" disabled="{!!setCon.hasPrevious}" title="Previous Page"/>
            <apex:commandButton status="fetchStatus" reRender="pb" value=">" action="{!setCon.next}" disabled="{!!setCon.hasNext}" title="Next Page"/>
            <apex:commandButton status="fetchStatus" reRender="pb" value=">|" action="{!setCon.last}" disabled="{!!setCon.hasNext}" title="Last Page"/>
            <apex:outputText >{!(setCon.pageNumber * size)+1-size}   -    {!IF((setCon.pageNumber * size)>noOfRecords, noOfRecords,(setCon.pageNumber * size))} of {!noOfRecords}</apex:outputText>
            <apex:commandButton status="fetchStatus" reRender="pb" value="Refresh" action="{!refresh}" title="Refresh Page"/>
            <apex:outputPanel style="color:#4AA02C;font-weight:bold">
                <apex:actionStatus id="fetchStatus" startText="Fetching..." stopText=""/>        
            </apex:outputPanel>
        </apex:panelGrid>

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

Apex

public class Controller {
    public List <Object__c> objectsToShow{get; set;}
    List<Object__c> ObjectList {get; set;}
    public Integer counter{get; set;}
    public List<Object__c> searchObject{get;set;} 
    public Boolean Match{get;set;}
    public Boolean NoMatch{get;set;}
    public Boolean searchMatch{get;set;}
    public String searchStrings{get;set;}
    public String adharcard{get;set;}
    public String lastname{get;set;}
    public String surname{get;set;}
    public Object__c object{set;get;}
    Integer limitSize = 10;
    Integer totalSize =0; 
    Public Integer noOfRecords{get; set;}
    Public Integer size{get;set;}
    public Object2__c object2{set;get;}
    public Object2__c Object2Query{set;get;}
    public list<selectOption> options{get;set;}
    public String selectedPick{get;set;}
    public String inputValue{get;set;}

    public ApexPages.StandardSetController setCon {

        get{
            Match=true;
            NoMatch=false;
            searchMatch=false;
            //object2 details to display in victim page
            object2=[SELECT id,name from object2__c ];
            //Picklists for searching the records
            options=new list<selectOption>();
            options.add(new selectOption('Aadhar card','Aadhar card'));
            options.add(new selectOption('Name','Name'));
            options.add(new selectOption('Surname','Surname'));
            if(setCon == null){
                size = 7;
                Object2Query= new Object2__c();
                //Query for getting the value from Object2__c
                Object2Query =[SELECT id, name From object2__c];
                string fieldString=Object2Query.name;
                //Query for displaying fixed Table Value 
                string queryString = 'SELECT id, name FROM Object1__c  WHERE name=:fieldString';
                setCon = new ApexPages.StandardSetController(Database.getQueryLocator(queryString));
                setCon.setPageSize(size);
                noOfRecords = setCon.getResultSize();
            }
            return setCon;
        }set;

    }
    Public List<object__c> getObjects(){
        objectList = new List<object__c>();
        for(object__c v : (List<object__c>)setCon.getRecords())
            objectList.add(v);
        return objectList;
    }
    public pageReference refresh() {
        setCon = null;
        getObjects();
        setCon.setPageNumber(1);
        return null;
    }

    //Redircet to create new object creation record page
    public pageReference NewObject()
    {
        pageReference pg=new pageReference('/apex/VfPage');
        return pg;

    }

    //Search Object based on Aadhar, lastname & surname
    public void searchObjectRec(){
        Match=false;
        NoMatch=false;
        //Trim the InputValue spaces
        inputValue = inputValue.trim();

        if( selectedPick=='Aadhar card')
        {
            searchObject=[select id,name, Aadhar_card__c from Object1__c where Aadhar_card__c LIKE :'%'+inputValue  +'%'];
        }
        else  if( selectedPick=='Name')
        {
            searchObject=[select id, name from Object1__c where Name LIKE :'%'+inputValue   +'%'];
        }
        else if( selectedPick=='Surname')
        {
            searchObject=[select name,first_name__c from Object1__c WHERE first_name__c LIKE :'%'+inputValue    +'%'];
        }

        if(searchObject.size()==0){
            NoMatch = True;
            SearchMatch = False; 
            Match = False;          
        }
        else if(searchObject.size()>0){
            NoMatch = False;
            SearchMatch = True;
            Match = False;
        }
    }
}
  • 1
    What do you mean by not working? – Martin Lezer Jun 14 '17 at 7:11
  • @Martin Lezer, Controller values are not displaying in page like Second pageBlockTable(fixed) and Picklist Values Line no. 5 in Vf page. Before I gave rendered values in vf page the Second pageBlockTable and Picklist Values displayed. – Ravindar Admin Jun 14 '17 at 7:21

Your Answer

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

Browse other questions tagged or ask your own question.