You need to sign in to do that
Don't have an account?
problem in Dynamic search page
Hai..............
I created Dynamic search page with custom object (applicant) having fields firstname,skillset(text datatype), expected annual salary(currency data type) ,location(text data type) etc.......
i got the table with all the field values.But the thing is when i enter the values in the input field ,the query is not exectuing can any one help me .............
I think the values are not passing from javascript to controller...............
Here is my Controller code....
public with sharing class SearchapplicantsController {
private String soql {get;set;}
// the collection of contacts to display
Public List<Applicant__c> applicants {get;set;}
// the current sort direction. deaults to asc
public String sortDir{
get { if (sortDir == null) { sortDir = 'asc'; }
return sortDir;
}
set;
}
// the current field to sort by. defaults to last name
public String sortField {
get {
if ( sortField == null) {
sortField = 'First_Name__c'; } return sortField; }
set;
}
// format the soql for display on the visualforce page
public String debugSoql {
get { return soql + ' order by ' + sortField + ' ' + sortDir + 'limit 20 '; }
set;
}
// init the contrller and display some sample data when the page loads
public SearchapplicantsController() {
soql='select First_name__c,Skill_set__c,Experience__c,Qualification__c,Expected_Annual_Salary__c,Location__c from Applicant__c where Applicant__c.First_name__c != null ';
runQuery();
}
// toggles the sorting of query from asc<-->desc
public void toggleSort() {
//simply toggle the direction
sortDir = sortDir.equals('asc') ? 'desc' : 'asc' ;
// run the query again
runQuery();
}
//runs the actualquery
public void runQuery() {
try {
applicants = Database.query(soql + ' order by ' + sortField + ' ' + sortDir + ' limit 20 ');
}
catch (Exception e) {
ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, ' OOOps! ') );
}
}
// runs the search with parameters passed via JavaScript
public PageReference runSearch(){
String FirstName = Apexpages.currentPage().getParameters().get('First_Name__c');
String Skillset = Apexpages.currentPage().getParameters().get('Skill_set__c');
String Experience = Apexpages.currentPage().getParameters().get('Experience__c');
String ExpectedSalary = Apexpages.currentPage().getParameters().get('Expected_Annual_Salary__c');
String Location = Apexpages.currentPage().getParameters().get('Location__c');
String Qualification = Apexpages.currentPage().getParameters().get('Qualification__c');
soql='select First_name__c,Skill_set__c,Experience__c,Qualification__c,Expected_Annual_Salary__c,Location__c from Applicant__c where Applicant__c.First_name__c != null' ;
if (!FirstName.equals(''))
soql += ' and First_Name__c LIKE \''+String.escapeSingleQuotes(FirstName)+'%\'';
if (!Skillset.equals(''))
soql += ' and Skill_Set__c LIKE \''+String.escapeSingleQuotes(Skillset)+'%\'';
if (!Experience.equals(''))
soql += ' and Experience__c LIKE \''+String.escapeSingleQuotes(Experience)+'%\'';
if (!ExpectedSalary.equals(''))
soql += ' and Expected_Annual_Salary__c LIKE \''+String.escapeSingleQuotes(Expectedsalary)+'%\' ';
if (!Qualification.equals(''))
soql += ' and Qualification__c LIKE (\' '+Qualification+'\')';
// run the query again
runQuery();
return null;
}
// use apex describe to build the picklist values
public List<String> Qualification {
get {
if (Qualification == null) {
Qualification = new List<String>();
Schema.DescribeFieldResult field = Applicant__c.Qualification__c.getDescribe();
for (Schema.PicklistEntry f : field.getPicklistValues())
Qualification.add(f.getLabel());
}
return Qualification;
}
set;
}
}
Here is my visualforce code............
<apex:page controller="SearchapplicantsController" sidebar="false">
<script type="text/javascript">
function doSearch() {
searchServer(
document.getElementById("First_Name__c").value,
document.getElementById("Skill_set__c").value,
document.getElementById("Experience__c").value,
document.getElementById("Expected_Annual_Salary__c").value,
document.getElementById("Location__c").value,
document.getElementById("Qualification__c").options[document.getElementById("Qualification__c").selectedIndex].value
);
}
</script>
<apex:form >
<apex:pageMessages id="errors" />
<apex:pageBlock title="Find Me A Candidate!" mode="edit">
<table width="100%" border="0">
<tr>
<td width="200" valign="top">
<apex:pageBlock title="Parameters" mode="edit" id="criteria">
<apex:actionFunction name="searchServer" action="{!runSearch}" rerender="results,debug,errors">
<apex:param name="First_name__c" value="" />
<apex:param name="Skill_set__c" value="" />
<apex:param name="Experience__c" value="" />
<apex:param name="Expected_Annual_salary__c" value="" />
<apex:param name="Location__c" value="" />
<apex:param name="Qualification__c" value="" />
</apex:actionFunction>
<table cellpadding="2" cellspacing="2">
<tr>
<td style="font-weight:bold;">First Name<br/>
<input type="text" id="First_name__c" onkeyup="doSearch();"/>
</td>
</tr>
<tr>
<td style="font-weight:bold;">Skillset<br/>
<input type="text" id="Skill_set__c" onkeyup="doSearch();"/>
</td>
</tr>
<tr>
<td style="font-weight:bold;">Experience<br/>
<input type="text" id="Experience__c" onkeyup="doSearch();"/>
</td>
</tr>
<tr>
<td style="font-weight:bold;">Expected salary<br/>
<input type="text" id="Expected_Annual_salary__c" onkeyup="doSearch();"/>
</td>
</tr>
<tr>
<td style="font-weight:bold;">Location<br/>
<input type="text" id="Location__c" onkeyup="doSearch();"/>
</td>
</tr>
<tr>
<td style="font-weight:bold;">Qualification<br/>
<select id="Qualification__c" onchange="doSearch();">
<option value=""></option>
<apex:repeat value="{!Qualification}" var="qua">
<option value="{!qua}"> {!qua}</option>
</apex:repeat>
</select>
</td>
</tr>
</table>
</apex:pageBlock>
</td>
<td valign="top">
<apex:pageBlock mode="edit" id="results">
<apex:pageBlockTable value="{!applicants}" var="applicant">
<apex:column >
<apex:facet name="header">
<apex:commandLink value="First Name" action="{!toggleSort}" rerender="results,debug">
<apex:param name="sortField" value="first_name__c" assignTo="{!sortField}"/>
</apex:commandLink>
</apex:facet>
<apex:outputField value="{!applicant.First_Name__c}"/>
</apex:column>
<apex:column >
<apex:facet name="header">
<apex:commandLink value="Skill set" action="{!toggleSort}" rerender="results,debug">
<apex:param name="sortField" value="Skill_set__c" assignTo="{!sortField}"/>
</apex:commandLink>
</apex:facet>
<apex:outputField value="{!applicant.Skill_set__c}"/>
</apex:column>
<apex:column >
<apex:facet name="header">
<apex:commandLink value="Experience" action="{!toggleSort}" rerender="results,debug">
<apex:param name="sortField" value="Experience__c" assignTo="{!sortField}"/>
</apex:commandLink>
</apex:facet>
<apex:outputField value="{!applicant.Experience__c}"/>
</apex:column>
<apex:column >
<apex:facet name="header">
<apex:commandLink value="Expected salary" action="{!toggleSort}" rerender="results,debug">
<apex:param name="sortField" value="Expected_Annual_salary__c" assignTo="{!sortField}"/>
</apex:commandLink>
</apex:facet>
<apex:outputField value="{!applicant.Expected_Annual_Salary__c}"/>
</apex:column>
<apex:column >
<apex:facet name="header">
<apex:commandLink value="Location" action="{!toggleSort}" rerender="results,debug">
<apex:param name="sortField" value="Location__c" assignTo="{!sortField}"/>
</apex:commandLink>
</apex:facet>
<apex:outputField value="{!applicant.Location__c}"/>
</apex:column>
<apex:column >
<apex:facet name="header">
<apex:commandLink value="Education" action="{!toggleSort}" rerender="results,debug">
<apex:param name="sortField" value="Qualification__c" assignTo="{!sortField}"/>
</apex:commandLink>
</apex:facet>
<apex:outputField value="{!applicant.Qualification__c}"/>
</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:form>
</apex:page>