You need to sign in to do that
Don't have an account?

Display SOME data when page loads...Please help
Hi .
I would like to display some conditional data when my VF page loads.I had written my soql query in constructor.But i am not sure how to dispaly in VF page.
My Vf page is a search page.So when page loads i want that data to show up .When search is done,that data has to disappear and my search results has to be showed up.
Please help.
Here is my VF page and apex class
<apex:page standardController="customobject__c" extensions="searchpageController">
<apex:form >
<apex:outputPanel id="errorPanel">
<apex:pageMessages />
</apex:outputPanel>
<apex:pageblock title="Searach Records" >
<apex:outputText value="Name"/>
<apex:inputtext value="{!inputNametext}"/>
<apex:outputText value="Account Name"/>
<apex:inputtext value="{!inputAccounttext}"/>
<apex:outputtext value="Contact Name"/>
<apex:inputtext value="{!inputContacttext}"/>
<apex:commandbutton value=" Search " action="{!searchRecords}"/>
</apex:pageblock>
<apex:pageBlock >
<apex:pageblocktable value="{!accList}" var="acc">
<apex:column >
<apex:outputLink value="/{!acc.id}"><apex:outputText value="{!acc.Name}" />
</apex:outputLink>
</apex:column>
<apex:column value="{!acc.Account__c}"/>
<apex:column value="{!acc.Contact__c}"/>
</apex:pageblocktable>
</apex:pageBlock>
</apex:form>
</apex:page>
Apex class:
Public class FARsearchpageController {
Public string inputNametext{get;set;}
Public string inputAccounttext{get;set;}
Public string inputContacttext{get;set;}
Public string inputstatustext{get;set;}
Public String soql{get;set;}
Public List<Fuel_Analysis_Report__c> accList{get;set;}
Public String usernames=UserInfo.getName();
public FARsearchpageController (ApexPages.StandardController controller) {
String soql = 'select Name,Account__c,ContactStatus__c,Closed_Date__c from customobject__c where name != null and Name =:Usernames';
}
Public void searchRecords(){
soql = 'select Name,Account,Contact,Status__c,Closed_Date__c from customobject__c where Name =:Usernames';
if (string.isnotBlank(inputAccounttext)){
soql += ' and Account.Name like '+'\''+'%'+inputaccounttext+'%'+'\'';
}
if (string.isnotBlank(inputnametext)){
soql += ' and Name like '+'\''+'%'+inputnametext+'%'+'\'';
}
if (string.isnotBlank(inputContacttext)){
soql += ' and Contact.Name like '+'\''+'%'+inputcontacttext+'%'+'\'';
}
accList= Database.query(soql);
}
}
}
}
I would like to display some conditional data when my VF page loads.I had written my soql query in constructor.But i am not sure how to dispaly in VF page.
My Vf page is a search page.So when page loads i want that data to show up .When search is done,that data has to disappear and my search results has to be showed up.
Please help.
Here is my VF page and apex class
<apex:page standardController="customobject__c" extensions="searchpageController">
<apex:form >
<apex:outputPanel id="errorPanel">
<apex:pageMessages />
</apex:outputPanel>
<apex:pageblock title="Searach Records" >
<apex:outputText value="Name"/>
<apex:inputtext value="{!inputNametext}"/>
<apex:outputText value="Account Name"/>
<apex:inputtext value="{!inputAccounttext}"/>
<apex:outputtext value="Contact Name"/>
<apex:inputtext value="{!inputContacttext}"/>
<apex:commandbutton value=" Search " action="{!searchRecords}"/>
</apex:pageblock>
<apex:pageBlock >
<apex:pageblocktable value="{!accList}" var="acc">
<apex:column >
<apex:outputLink value="/{!acc.id}"><apex:outputText value="{!acc.Name}" />
</apex:outputLink>
</apex:column>
<apex:column value="{!acc.Account__c}"/>
<apex:column value="{!acc.Contact__c}"/>
</apex:pageblocktable>
</apex:pageBlock>
</apex:form>
</apex:page>
Apex class:
Public class FARsearchpageController {
Public string inputNametext{get;set;}
Public string inputAccounttext{get;set;}
Public string inputContacttext{get;set;}
Public string inputstatustext{get;set;}
Public String soql{get;set;}
Public List<Fuel_Analysis_Report__c> accList{get;set;}
Public String usernames=UserInfo.getName();
public FARsearchpageController (ApexPages.StandardController controller) {
String soql = 'select Name,Account__c,ContactStatus__c,Closed_Date__c from customobject__c where name != null and Name =:Usernames';
}
Public void searchRecords(){
soql = 'select Name,Account,Contact,Status__c,Closed_Date__c from customobject__c where Name =:Usernames';
if (string.isnotBlank(inputAccounttext)){
soql += ' and Account.Name like '+'\''+'%'+inputaccounttext+'%'+'\'';
}
if (string.isnotBlank(inputnametext)){
soql += ' and Name like '+'\''+'%'+inputnametext+'%'+'\'';
}
if (string.isnotBlank(inputContacttext)){
soql += ' and Contact.Name like '+'\''+'%'+inputcontacttext+'%'+'\'';
}
accList= Database.query(soql);
}
}
}
}
<apex:page standardController="customobject__c" extensions="FARsearchpageController">
<apex:form >
<apex:outputPanel id="errorPanel">
<apex:pageMessages />
</apex:outputPanel>
<apex:pageblock title="Searach Records" >
<apex:outputText value="Name"/>
<apex:inputtext value="{!inputNametext}"/>
<apex:outputText value="Account Name"/>
<apex:inputtext value="{!inputAccounttext}"/>
<apex:outputtext value="Contact Name"/>
<apex:inputtext value="{!inputContacttext}"/>
<apex:commandbutton value=" Search " action="{!searchRecords}" reRender="accListBlock" />
</apex:pageblock>
<apex:pageBlock id="accListBlock">
<apex:pageblocktable value="{!accList}" var="acc">
<apex:column >
<apex:outputLink value="/{!acc.id}"><apex:outputText value="{!acc.Name}" />
</apex:outputLink>
</apex:column>
<apex:column value="{!acc.Account__c}"/>
<apex:column value="{!acc.Contact__c}"/>
</apex:pageblocktable>
</apex:pageBlock>
</apex:form>
</apex:page>
Apex class:
Public class FARsearchpageController {
Public string inputNametext{get;set;}
Public string inputAccounttext{get;set;}
Public string inputContacttext{get;set;}
Public string inputstatustext{get;set;}
Public String soql{get;set;}
Public List<Fuel_Analysis_Report__c> accList{get;set;}
Public String usernames=UserInfo.getName();
public FARsearchpageController (ApexPages.StandardController controller) {
String soql = 'select Name,Account__c,ContactStatus__c,Closed_Date__c from Fuel_Analysis_Report__c where name != null and Name=\''+Usernames+'\'';
accList = Database.query(soql);
}
Public void searchRecords(){
soql = 'select Name,Account,Contact,Status__c,Closed_Date__c from Fuel_Analysis_Report__c where Name =\''+Usernames+'\'';
if (string.isnotBlank(inputAccounttext)){
soql += ' and Account.Name like '+'\''+'%'+inputaccounttext+'%'+'\'';
}
if (string.isnotBlank(inputnametext)){
soql += ' and Name like '+'\''+'%'+inputnametext+'%'+'\'';
}
if (string.isnotBlank(inputContacttext)){
soql += ' and Contact.Name like '+'\''+'%'+inputcontacttext+'%'+'\'';
}
accList= Database.query(soql);
}
}
}
}
Also i would like to display an message when acclist is empty just to say no matching records are found on pageblock table.
My test class also doesnt seem to have code coverage.Plase help.
Thanks in advance!!!
<apex:pageBlock id="accListBlock">
<apex:outputPanel rendered="{!accList.size == 0}">
No matching records were found.
</apex:outputPanel>
<apex:pageblocktable value="{!accList}" var="acc" rendered="{!accList.size > 0}">
<apex:column >
<apex:outputLink value="/{!acc.id}"><apex:outputText value="{!acc.Name}" />
</apex:outputLink>
</apex:column>
<apex:column value="{!acc.Account__c}"/>
<apex:column value="{!acc.Contact__c}"/>
</apex:pageblocktable>
</apex:pageBlock>