0

I am searching my for the records which satisfy the query in the controller. My page gets rendered correctly the first time I click the search button. But when I change the value for the query on my page it seems to render the old values only, but I can see the updated values in the controller after the query in executed in my query.

I am not able to figure out why this may be happening. Can someone help me?

Below is my code for VF page:-

<apex:page standardController="Opportunity__c" extensions="SearchController">
<script type="text/javascript">
  function callFunction(id)
   {
   var type = document.getElementById(id).value;

   }


   </script>

<apex:outputPanel id="all">
 <apex:form id="searchForm">
    <apex:PageBlock id="searchRender" mode="edit">        

    <apex:pageblockSection id="searchBlockSection">

        <apex:pageBlockSectionItem id="searchBlockSectionItem">

            <apex:panelGroup >
            <strong> <apex:outputText >Enter Keywords to search for Pricebook Items</apex:outputText></strong>
            <br></br>
            <br></br>
           <strong> <apex:outputLabel >PriceBook Name</apex:outputLabel></strong>
           <br></br>
            <apex:inputField id="searchTextBox1"  required="true" value="{!oppty.Price_Book__c}" >
            <apex:actionFunction name="searchTextBox1" action="{!search}">
                    <apex:param name="pricelineItem" assignTo="{!searchProduct}" value="{!searchProduct}"/>
                </apex:actionFunction>

            </apex:inputField>   
                <br></br>
                <br></br>  

            <strong><apex:outputLabel >ProductName or Part#</apex:outputLabel></strong>
            <br></br>
            <apex:inputtext id="searchTextBox" value="{!searchText}"> 
            </apex:inputtext>
                <br></br>
                <br></br>
             <br></br>
             <strong><apex:outputLabel >Product Line</apex:outputLabel></strong>
             <br></br>

            <apex:selectList id="searchTextBox2"  value="{!productLine}" size="1" multiselect="false" >
                    <apex:selectOptions value="{!productLineItems}"></apex:selectOptions> 
              </apex:selectList><p/>


            <strong>
            <br></br>
            <br></br>

           <apex:commandButton Id="btnSearch" action="{!search}" rerender="renderBlock" status="status" title="Search" value="Search"/>               
            </strong>

            </apex:panelGroup>

        </apex:pageBlockSectionItem>

    </apex:pageblockSection>
    </apex:PageBlock>

    <apex:actionStatus id="status" startText="Searching... please wait..."/>   
    <apex:actionStatus id="status1" startText="Saving record to Opportunity Item.. please wait..."/>  


    <apex:PageBlock id="renderBlock">


        <apex:pageblocktable value="{!pricebookitems}"  id="table" var="o" rendered="{!IF(renderfinish,true,false)}">

          <apex:column >
                    <apex:inputCheckbox value="{!o.selected}"/>
          </apex:column>  

          <apex:column value="{!o.con.Name}"/>
            <apex:column value="{!o.con.Part__c}"/>
            <apex:column value="{!o.con.Product__c}"/>
            <apex:column value="{!o.con.Product_Line__c}"/>
            <apex:column value="{!o.con.List_Price__c}"/>
            <apex:column value="{!o.con.DOD_Price__c}"/>
            <apex:column value="{!o.con.GSA_Price__c}"/>
            <apex:column value="{!o.con.Price_Book__c}"/>
            <apex:column headerValue="Min_Qty__c" >
            <apex:inputText label="" size="3"/>
            </apex:column>
          </apex:pageblocktable>


        <apex:pageblockButtons >
              <apex:commandButton action="{!save2}"  value="Save" status="status1" rerender="{!$CurrentPage.Parameters.retURL}"  />
              <apex:commandButton action="{!savenew}" status="status1" value="Save and New" rerender="renderBlock" />
        </apex:pageblockButtons>
    </apex:PageBlock>


    </apex:form>
    </apex:outputPanel>
</apex:page>

this is my controller:-

public class SearchController
{
        public Opportunity__c oppty {get;set;}
        public apexpages.standardController controller {get; set; }
        public List<Price_Book_Item__c> searchResults {get; set; }

        public List<priceBookItemWrapper> wrapperList {get;set;}
        public string productLine;
        public Boolean selected {get; set;}
        //public Boolean renderFinish  {get;set;}
        public integer OffsetSize = 0;
        public integer LimitSize= 10;
        public integer totalRecs = 0;

        Id opptyId;
        Id selectedOption;

        public string searchProduct
        {
            get
            {
                if (searchProduct==null) searchProduct = '';
                return searchProduct;
            }
            set;
        }

        public Boolean renderFinish  
        {
            get
            {

                renderFinish=false;
                return renderFinish;
            }
            set;
        }
        public string searchText
        {
            get
            {
                if (searchText==null) searchText = '';
                return searchText;
            }
            set;
        }
        public Price_Book__c getItems()
        {
           return [select Name from Price_Book__c limit 1];
        }
        public SearchController(ApexPages.StandardController controller)
        {
        renderFinish=false;
         oppty=  new Opportunity__c();
        this.controller = controller;
        opptyId=System.currentPagereference().getParameters().get('id');
        System.debug(System.currentPagereference().getParameters());

        }

        public PageReference search()
        {
            renderFinish=false;
            if(SearchResults!=null)
            {
                SearchResults.Clear();
            }
            SearchResults = new List<Price_Book_Item__c>();
            System.debug(System.currentPagereference());
            //System.debug('pricelineItem'+System.currentPagereference().getParameters().get('pricelineItem'));
            //System.debug(System.currentPagereference().getParameters().get('conid'));
            /*if(SearchResults == null)
            {
                SearchResults = new List<Price_Book_Item__c>();
            }
            else
            {
                SearchResults.Clear();
             }*/
            searchProduct=oppty.Price_Book__c;
           System.debug('searchproduct'+oppty.Price_Book__c);
           System.debug('product line name before quering'+ productLine);
        String qry = 'Select Name,Min_Qty__c,DOD_Price__c,GSA_Price__c,List_Price__c,Price_Book__c,Product_Name__c ,Product__c,Product_Line__c,Part__c,PriceBook_Name__c from Price_Book_Item__c  where ((Product_Line__c =:productLine)AND(Price_Book__c = :searchProduct)  AND ((Product_Name__c like \'%'+searchText+'%\')  OR ( Part__c like \'%'+searchText+'%\'))) ORDER BY Part__c ASC ';
        //String qry1 = 'Select count() from Price_Book_Item__c where (Price_Book__c = :searchProduct)  AND ((Product_Name__c like \'%'+searchText+'%\')  OR ( Part__c like \'%'+searchText+'%\'))';
        SearchResults = Database.query(qry);

        Integer count=0;

        for(Price_Book_Item__c  p:SearchResults)
          System.debug('Price book items'+  p);

        //totalRecs=count;
        renderFinish=true;
        return null;
        }

        public List<priceBookItemWrapper> getpricebookitems()
        {
            if(wrapperList==null)
            {
                wrapperList= new List<priceBookItemWrapper>();
                for(Price_Book_Item__c  p: SearchResults )
                {
                //System.debug('price  book item'+p);
                    wrapperList.add(new priceBookItemWrapper(p));
                 }  
            } 
            return wrapperList;
        }

        public void FirstPage()
        {
            OffsetSize = 0;
        }
        public void LastPage()
        {
            OffsetSize = totalrecs - math.mod(totalRecs,LimitSize);
        }
        public void previous()
        {
            OffsetSize = OffsetSize - LimitSize;
        }

        public void next()
        {
            OffsetSize = OffsetSize + LimitSize;
        }
        public boolean getprev()
        {
            if(OffsetSize == 0)
                    return true;
            else
                    return false;
        }

        public boolean getnxt()
        {
            if((OffsetSize + LimitSize) > totalRecs)
                    return true;
            else
                    return false;
        }


        public void temp()
        {
            renderFinish=false;
        }

        public PageReference save2()
        {

            List <Price_Book_Item__c > selectedpricebookitem = new List <Price_Book_Item__c >();
            List <Id> idList = new List <Id>();
            System.debug('these are the selected price book items');
            for(priceBookItemWrapper p: getpricebookitems())
            {
                if(p.selected==true)
                {
                    selectedpricebookitem.add(p.con);
                    idList.add(p.con.Id);
                    System.debug('price book items'+p.con.Name);
                 }
            }


             List<Price_Book_Item__c > priceItemsList=
            [
                SELECT 
                    Id, 
                    Name,
                    Part__c,
                    Price_Book__c,
                    Product__c,
                    List_Price__c
                FROM 
                    Price_Book_Item__c 
                WHERE 
                    Id IN :idList
            ];


            List <Opportunity_Item__c> opptyItemList= new List<Opportunity_Item__c>();
            for(Price_Book_Item__c p: priceItemsList)
            {   
                  opptyItemList.add(new Opportunity_Item__c (Name=p.Name, Opportunity__c= opptyId,Price_Book__c=p.Price_Book__c,Product__c=p.Product__c,List_Price__c=p.List_Price__c));
            }                 
            insert opptyItemList;
            //returnPage.setRedirect
           searchResults=null;

           return null;
        }
        public void savenew()
        {
            save2();
        }

        public List<selectOption> getproductLineItems()
        {

               List<SelectOption> options = new List<SelectOption>();
               List<SelectOption> temp= new List<SelectOption>();
                for(Price_Book_Item__c p:[select Name,Product_Line__c FROM Price_Book_Item__c ])
                         temp.add(new selectOption(p.Product_Line__c ,p.Product_Line__c ));

                Set<SelectOption> myset = new Set<SelectOption>();
                List<SelectOption> result = new List<SelectOption>();
                myset.addAll(temp);
                options.addAll(myset);
             return options;
        }

        public String  getproductLine()
        {
            System.debug('get Product line value'+productLine);
            return productLine;
        }

        public void setproductLine(String productLine )
        {
            System.debug('set Product line value'+productLine);
            this.productLine=productLine;
        }
}

2 Answers 2

0

try wrapping the pageblock in an outputPanel and rerender that id/component..

0

Thanks Benjamin!! Actually I just figured out the answer. I was not clearing the List and we checking the list if null. So whenever my list was null it wasnt populating the list (which happened everytime after the first time)

so I changed in getpricebookitems() method to this:-

public List getpricebookitems() { if(wrapperList!=null) wrapperList.clear();

            wrapperList= new List<priceBookItemWrapper>();
            for(Price_Book_Item__c  p: SearchResults )
            {
            //System.debug('price  book item'+p);
                wrapperList.add(new priceBookItemWrapper(p));
             }  

        return wrapperList;
    }

and it worked!!

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .