You need to sign in to do that
Don't have an account?
Aneesh Allumalla
Showing list on Vf page
I am trying to show the list of account records on vf page:
there is no error. But it is not retrieving any list on vf page.
can someone tell me the reason.
Class:
public class Dev12 {
public String city{get;set;}
public list<account> acclist{get;set;}
public boolean showTable{get;set;}
Public Dev12(){
showTable=false;
}
Public void showT(){
List <account> acclist = new List<account>();
acclist = [Select name , phone, BillingCity from account where name =:city];
showTable=true;
}
}
Vf page:
<apex:page controller="Dev12">
<apex:form >
<apex:pageBlock >
<apex:pageblocksection >
<apex:inputtext value="{!city}" label="City"/>
</apex:pageblocksection>
<apex:pageBlockButtons >
<apex:commandButton value="show" action="{!showT}" reRender="table" />
</apex:pageBlockButtons>
<apex:outputPanel id="table">
<apex:pageBlockTable rendered="{!showTable==true}" value="{!acclist}" var="a">
<apex:column value="{!a.name}"/>
<apex:column value="{!a.phone}"/>
</apex:pageBlockTable>
</apex:outputPanel>
</apex:pageBlock>
</apex:form>
</apex:page>
there is no error. But it is not retrieving any list on vf page.
can someone tell me the reason.
Class:
public class Dev12 {
public String city{get;set;}
public list<account> acclist{get;set;}
public boolean showTable{get;set;}
Public Dev12(){
showTable=false;
}
Public void showT(){
List <account> acclist = new List<account>();
acclist = [Select name , phone, BillingCity from account where name =:city];
showTable=true;
}
}
Vf page:
<apex:page controller="Dev12">
<apex:form >
<apex:pageBlock >
<apex:pageblocksection >
<apex:inputtext value="{!city}" label="City"/>
</apex:pageblocksection>
<apex:pageBlockButtons >
<apex:commandButton value="show" action="{!showT}" reRender="table" />
</apex:pageBlockButtons>
<apex:outputPanel id="table">
<apex:pageBlockTable rendered="{!showTable==true}" value="{!acclist}" var="a">
<apex:column value="{!a.name}"/>
<apex:column value="{!a.phone}"/>
</apex:pageBlockTable>
</apex:outputPanel>
</apex:pageBlock>
</apex:form>
</apex:page>
The issue in the Class:
Don't create the one more List inside the showT Method just instantiate the already declared List:
And if you want to use the City as the Where condition then use the BillingCity in where query.
Please use the below udated code:
public class Dev12 {
public String city{get;set;}
public list<account> acclist{get;set;}
public boolean showTable{get;set;}
Public Dev12(){
showTable=false;
}
Public void showT(){
acclist = new List<account>(); ///// This Line is now changed
acclist = [Select name , phone, BillingCity from account where BillingCity =:city];
showTable=true;
}
}
Can you please Let me know if it helps or not!!!
If it helps don't forget to mark this as a best answer!!!
Thanks,
Maharajan.C
All Answers
The issue in the Class:
Don't create the one more List inside the showT Method just instantiate the already declared List:
And if you want to use the City as the Where condition then use the BillingCity in where query.
Please use the below udated code:
public class Dev12 {
public String city{get;set;}
public list<account> acclist{get;set;}
public boolean showTable{get;set;}
Public Dev12(){
showTable=false;
}
Public void showT(){
acclist = new List<account>(); ///// This Line is now changed
acclist = [Select name , phone, BillingCity from account where BillingCity =:city];
showTable=true;
}
}
Can you please Let me know if it helps or not!!!
If it helps don't forget to mark this as a best answer!!!
Thanks,
Maharajan.C
It was a silly mistake though.