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
swapna9swapna9 

Dynamically add and search in visualforce page

Hi,

I am doing dynamically adding rows and dynamically searching one field while adding the row in visualforce page.

Actually adding and searching working fine in different buttons.In my requirement under quote-->Quoteline item is custom object.

in quote line item i have a button New Quote.if i click on it will open one vf page with quote fileds.after entering quote fields if i click on add quotelineitems button it will add quoteline item dynamically.This ty\ime i need to check Nicomatic P/N is already there or not.

In seperate button i am using Jeff Douglas code for dynamic search.it is working fine.If add that code with my code

debug soql is showing null.it is not dispalying query.

Can any one help me...

Here is my code:

 <apex:page standardController="Quote" extensions="QuoteLineNew,TestSearch">

 <script type="text/javascript">
      function doSearch() {
        searchServer(
          document.getElementById("NicomaticPN").value         
          
                    );
      }
      </script>
        
<apex:pageMessages escape="false">
</apex:pageMessages>
<apex:pageMessages id="errors" />
<apex:form id="theForm">
<apex:pageBlock title="Quote Detail" mode="read">
<apex:pageBlockButtons >
<apex:commandButton value="Save" action="{!savequote}"/>
<apex:commandButton immediate="true" value="Cancel" action="{!cancel}"/>
<apex:commandButton value="Add/Edit QuoteLineItems"   action="{!Method1}" rerender="theForm" status="updateStatus"  id="theButton" />
<apex:actionStatus startText="Opening Quote Line Items section..."  id="updateStatus"></apex:actionStatus>
<!--<apex:commandButton value="Add/Edit QuoteLineItems"  reRender="p1"  action="{!Method1}" /> -->
<apex:actionStatus startText=" (Opening Quote Line Items Section...)" id="QuoteLineItemSection"/>                    
</apex:pageBlockButtons>

<apex:pageBlockSection title="Quote Information">      
<apex:inputField value="{!q.Name}"/>       
<apex:inputField value="{!q.Title__c}"/>                
<apex:inputField value="{!q.Subject__c}"/>  
<apex:outputText value="{!opp.Name}"/>  
                   
</apex:pageBlockSection>

<apex:pageBlockSection title="Prepared For">      
<apex:inputField value="{!q.ContactId}"/>         
<apex:inputField value="{!q.Contact.Email}"/>
    
</apex:pageBlockSection>

<apex:pageBlockSection title="Additional Information">
<apex:inputField value="{!q.Payment_Terms__c}"/>         

</apex:pageBlockSection>
</apex:pageBlock>      


<apex:outputPanel id="p1">
<apex:outputPanel rendered="{!a}">
<apex:pageblock id="pb" >
    <apex:pageBlockButtons >
        <apex:commandbutton value="Add" action="{!Add}" rerender="pb1"/>
        <!--<apex:commandButton immediate="true" value="Cancel" action="{!cancel1}"/>-->
                <!--<apex:commandbutton value="Save" action="{!Save}"/>-->
    </apex:pageBlockButtons>
    
        
        <apex:pageblock id="pb1">
          <apex:actionFunction name="searchServer" action="{!runSearch}" rerender="results,debug,errors">
          <apex:param name="Name" value="" />         
          
      </apex:actionFunction>  
        <apex:repeat value="{!lstInner}" var="e1" id="therepeat">
       
                <apex:panelGrid columns="5">
                <apex:panelGrid headerClass="Name">
                    <apex:facet name="header">Del</apex:facet>
                    <apex:commandButton value="Delete" action="{!Del}" rerender="pb1">
                        <apex:param name="rowToBeDeleted" value="{!e1.recCount}" assignTo="{!selectedRowIndex}"></apex:param>
                    </apex:commandButton>
                </apex:panelGrid>
                 
                
                <apex:panelGrid title="SPD" >
                    <apex:facet name="header">Nicomatic P/N</apex:facet>
                    <apex:inputField value="{!e1.acct.Name}" required="true" id="NicomaticPN" onkeyup="doSearch();"/>
                </apex:panelGrid>
               
                
                <apex:panelGrid >
                    <apex:facet name="header">Asked Qty</apex:facet>
                    <apex:inputfield value="{!e1.acct.Asked_Qty__c}"/>
                </apex:panelGrid>
                
               
            </apex:panelgrid>
        </apex:repeat>
    </apex:pageBlock>
        
</apex:pageblock>

</apex:outputPanel>
</apex:outputPanel>
<apex:pageblock title="Similar Quote Line Items">
<apex:pageBlock >
  <table width="100%" border="0">
  <tr>  
    <td width="200" valign="top">
 
   
    <apex:pageBlock mode="edit" id="results">
 
        <apex:pageBlockTable value="{!Qline}" var="Ql">
 
            <apex:column >
                <apex:facet name="header">
                    <apex:commandLink value="Nicomatic P/N" action="{!toggleSort}" rerender="results,debug">
                        <apex:param name="sortField" value="Nicomatic P/N" assignTo="{!sortField}"/>
                    </apex:commandLink>
                </apex:facet>
                <apex:outputField value="{!Ql.Name}"/>
            </apex:column>
              <apex:column >
                <apex:facet name="header">
                   <apex:commandLink value="Client P/N"  rerender="results,debug">
                        
                    </apex:commandLink>
                </apex:facet>
                <apex:outputField value="{!Ql.Client_P_N__c}"/>
            </apex:column>
             <apex:column >
                          
 
        </apex:pageBlockTable>
 
    </apex:pageBlock>
    
       </td>
  </tr>
  </table>
  <apex:pageBlock title="Debug - SOQL" id="debug">
      <apex:outputText value="{!debugSoql}" />           
  </apex:pageBlock>
    </apex:pageBlock>
</apex:pageblock>


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


apex class:
public class QuoteLineNew
{

   
public Opportunity opp {get; private set;}
public boolean a{get;set;}
public boolean b{get;set;}
public Quote q {get;set;}
public List<Quote_Line_Item__c>lstAcct  = new List<Quote_Line_Item__c>();
public List<innerClass> lstInner{get;set;}
public String selectedRowIndex{get;set;}
public Integer count = 1;
public Quote_Line_Item__c AppSearch {get;set;}
    public QuoteLineNew(ApexPages.StandardController ctlr)
    {       
        q =new Quote();
        q = (Quote)ctlr.getRecord();
         
        opp = [Select Id, Name From Opportunity Where Id =: q.OpportunityId];
        a=false;
        b=false;   
        lstInner = new List<innerClass>();
        addMore();
        selectedRowIndex = '0';
    }
    public void Method1()
    {
        a=true;    
    }
    public void Method2()
    {
        b=true;    
    }
    public PageReference savequote()
    {
        insert q;   
        for(Integer j = 0;j<lstInner.size();j++)
        {
            lstInner[j].acct.Quote__c = q.Id;
            lstAcct.add(lstInner[j].acct);
        }
        insert lstAcct;      
        PageReference pr1 = new PageReference('https://cs6.salesforce.com/'+ApexPages.CurrentPage().getParameters().get('oppid'));  
        pr1.setRedirect(True);
        return pr1;
    }
    public PageReference cancel()
    {
        PageReference pr2 = new PageReference('https://cs6.salesforce.com/'+ApexPages.CurrentPage().getParameters().get('oppid') );
        pr2.setRedirect(True);
        return pr2;
    }
    public PageReference cancel1()
    {
        PageReference pr3 = new PageReference('/apex/NewQuote');
        pr3.setRedirect(True);
        return pr3;
    }
    public void Add()
    {   
        count = count+1;
        addMore();      
    }
    public void addMore()
    {   
        innerClass objInnerClass = new innerClass(count);  
        lstInner.add(objInnerClass);    
    }
    public void Del()
    {
        system.debug('selected row index---->'+selectedRowIndex);
        lstInner.remove(Integer.valueOf(selectedRowIndex)-1);
        count = count - 1;        
    }
    public class innerClass
    {     
        public String recCount{get;set;}
        public Quote_Line_Item__c acct {get;set;}

        public innerClass(Integer intCount)
        {
            recCount = String.valueOf(intCount);
            acct = new Quote_Line_Item__c();    
        }

    }

public with sharing class TestSearch {

    public TestSearch(QuoteLineNew controller) {

    }


    public TestSearch(ApexPages.StandardController controller) {

    }

 
  private String soql {get;set;}
 
  public List<Quote_Line_Item__c> Qline{get;set;}
 
 
  public String sortDir {
    get  { if (sortDir == null) {  sortDir = 'asc'; } return sortDir;  }
    set;
  }
 
 
  public String sortField {
    get  { if (sortField == null) {sortField = 'Name'; } return sortField;  }
    set;
  }
 
 
  public String debugSoql {
    get { return soql + ' order by ' + sortField + ' ' + sortDir + ' limit 20'; }
    set;
  }
 
 
  public TestSearch () {
    soql = 'select name,  Quote__c,Client_P_N__c,Unit_Price__c,Asked_Qty__c  from Quote_Line_Item__c where Quote__c!= null';
    runQuery();
  }
 
 
  public void toggleSort() {
   
    sortDir = sortDir.equals('asc') ? 'desc' : 'asc';
   
    runQuery();
  }
 
 
  public void runQuery() {
 
    try {
      Qline= Database.query(soql + ' order by ' + sortField + ' ' + sortDir + ' limit 20');
    } catch (Exception e) {
      ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Ooops!'));
    }
 
  }
 
 
  public PageReference runSearch() {
 
    String Name= Apexpages.currentPage().getParameters().get('Name');    
    String lastName = Apexpages.currentPage().getParameters().get('Client_P_N__c');
     
    soql = 'select Name,  Quote__c,Client_P_N__c,Unit_Price__c,Asked_Qty__c from Quote_Line_Item__c where Quote__c != null';
    if (!Name.equals(''))
      soql += ' and Name LIKE \''+String.escapeSingleQuotes(Name)+'%\'';       
  
    runQuery();
 
    return null;
  }

   
}

 

 

Thanks in advance,