You need to sign in to do that
Don't have an account?
bela
Please help in this scenario .I am trying to display the seach with pagination by using standard set controller
I am trying to display the seach with pagination by using standard set controller but iam getting below error ,please help where i am going wrong and is the approch is correct?
System.NullPointerException: Attempt to de-reference a null object
Class.Pagnationwithsetcontroller.getOpportunities: line 50, column 1
VF Page
----------------
<apex:page controller="Pagnationwithsetcontroller">
<apex:form >
<apex:pageBlock id="a" >
<apex:pageBlockSection >
<apex:inputText value="{!InputString}" title="Search" label="search" >
<apex:actionSupport action="{!lstofopportunity}" event="onchange" reRender="a" status="status"/>
</apex:inputText>
</apex:pageBlockSection>
<apex:pageBlockSection columns="1">
<apex:actionStatus id="status" startText="requesting..."/>
<apex:pageBlockTable value="{!Opportunities}" var="a">
<apex:column value="{!a.name}"/>
</apex:pageBlockTable>
<apex:panelGrid columns="2">
<apex:commandLink value="first" action="{!first}"/>
<apex:commandLink value="first" action="{!last}"/>
</apex:panelGrid>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
Controller:
----------------
public with sharing class Pagnationwithsetcontroller {
Public string giveninputString;
public integer size=2;
//takes the letter which we type in the input text
public void setInputString(string s){
giveninputString=s;
system.debug('hiiii1 SET'+giveninputString);
}
//The "get" method is used to pass data from your Apex code to your Visualforce page
public string getInputString(){
system.debug('hiiii2 GET'+giveninputString);
return null;
}
public List<opportunity> oppresults{set;get;}
public List<opportunity> getoppresults() {
system.debug('hiiii oppresults in getoppresults '+oppresults);
return oppresults;
}
public pageReference lstofopportunity(){
oppresults=(list<opportunity>)[find :giveninputString in all Fields returning opportunity(name)][0] ;
system.debug('hiiii in lstofopportunity'+oppresults);
//con= new ApexPages.StandardSetController(oppresults);
//system.debug('aaaa11111111111'+con);
//con.setPageSize(size);
return null;
}
public ApexPages.StandardSetController con{get; set;}
Apexpages.standardSetController setcon{get
{
if(setcon==null){
system.debug('asassasaasaas'+oppresults);
setcon = new Apexpages.standardsetController(oppresults);
system.debug('aaaa11111111111'+setcon );
setcon.setPageSize(size);
}return setcon;
}
set;
}
public List<Opportunity> getOpportunities() {
return (list<opportunity>)Con.getRecords();
}
public void first(){
con.first();
}
public void last(){
con.last();
}
}
System.NullPointerException: Attempt to de-reference a null object
Class.Pagnationwithsetcontroller.getOpportunities: line 50, column 1
VF Page
----------------
<apex:page controller="Pagnationwithsetcontroller">
<apex:form >
<apex:pageBlock id="a" >
<apex:pageBlockSection >
<apex:inputText value="{!InputString}" title="Search" label="search" >
<apex:actionSupport action="{!lstofopportunity}" event="onchange" reRender="a" status="status"/>
</apex:inputText>
</apex:pageBlockSection>
<apex:pageBlockSection columns="1">
<apex:actionStatus id="status" startText="requesting..."/>
<apex:pageBlockTable value="{!Opportunities}" var="a">
<apex:column value="{!a.name}"/>
</apex:pageBlockTable>
<apex:panelGrid columns="2">
<apex:commandLink value="first" action="{!first}"/>
<apex:commandLink value="first" action="{!last}"/>
</apex:panelGrid>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
Controller:
----------------
public with sharing class Pagnationwithsetcontroller {
Public string giveninputString;
public integer size=2;
//takes the letter which we type in the input text
public void setInputString(string s){
giveninputString=s;
system.debug('hiiii1 SET'+giveninputString);
}
//The "get" method is used to pass data from your Apex code to your Visualforce page
public string getInputString(){
system.debug('hiiii2 GET'+giveninputString);
return null;
}
public List<opportunity> oppresults{set;get;}
public List<opportunity> getoppresults() {
system.debug('hiiii oppresults in getoppresults '+oppresults);
return oppresults;
}
public pageReference lstofopportunity(){
oppresults=(list<opportunity>)[find :giveninputString in all Fields returning opportunity(name)][0] ;
system.debug('hiiii in lstofopportunity'+oppresults);
//con= new ApexPages.StandardSetController(oppresults);
//system.debug('aaaa11111111111'+con);
//con.setPageSize(size);
return null;
}
public ApexPages.StandardSetController con{get; set;}
Apexpages.standardSetController setcon{get
{
if(setcon==null){
system.debug('asassasaasaas'+oppresults);
setcon = new Apexpages.standardsetController(oppresults);
system.debug('aaaa11111111111'+setcon );
setcon.setPageSize(size);
}return setcon;
}
set;
}
public List<Opportunity> getOpportunities() {
return (list<opportunity>)Con.getRecords();
}
public void first(){
con.first();
}
public void last(){
con.last();
}
}
public with sharing class Pagnationwithsetcontroller {
Public string giveninputString;
public integer size=2;
//takes the letter which we type in the input text
public void setInputString(string s){
giveninputString=s;
system.debug('hiiii1 SET'+giveninputString);
}
//The "get" method is used to pass data from your Apex code to your Visualforce page
public string getInputString(){
system.debug('hiiii2 GET'+giveninputString);
return null;
}
public List<opportunity> oppresults{set;get;}
public List<opportunity> getoppresults() {
system.debug('hiiii oppresults in getoppresults '+oppresults);
return oppresults;
}
public pageReference lstofopportunity(){
oppresults=(list<opportunity>)[find :giveninputString in all Fields returning opportunity(name)][0] ;
system.debug('hiiii in lstofopportunity'+oppresults);
//con= new ApexPages.StandardSetController(oppresults);
//system.debug('aaaa11111111111'+con);
//con.setPageSize(size);
return null;
}
public ApexPages.StandardSetController con{get; set;}
// ApexPages.StandardSetController must be instantiated
// for standard list controllers
public ApexPages.StandardSetController setCon {
get {
if(setCon == null) {
setCon = new ApexPages.StandardSetController(Database.getQueryLocator(
[SELECT Name, CloseDate FROM Opportunity]));
}
return setCon;
}
set;
}
// Initialize setCon and return a list of records
public List<Opportunity> getOpportunities() {
return (List<Opportunity>) setCon.getRecords();
}
public void first(){
con.first();
}
public void last(){
con.last();
}
}