How to pass the parameter or object value (could be custom object) to apex class
from visualforce?
I saw some where they're using ApexPages.currentPage()
etc, not sure how we can modify the below program.
The main issue which I am facing is I dont see any data coming on VF page, but query executes fine fetches the result. How to fixed this issue ?
public class ContactController {
public String accountName {get; set;}
public List<Contact> contacts {get; set;}
public ContactController(){
}
public void getContactUsingAccount(){
contacts = [SELECT ID, FirstName, LastName, Phone FROM Contact where account.Name = :accountName];
System.debug('Contacts : '+contacts);
}
}
and VF page
<apex:page controller="ContactController">
<apex:form>
<apex:pageBlock>
Account Name : <apex:inputText value="{!accountName}" />
<apex:commandButton value="Submit" reRender="outputContact" action="{!getContactUsingAccount}" />
</apex:pageBlock>
<apex:pageBlock>
<b>Output Contact Details </b>
<apex:outputText value="{!contacts}" id="outputContact" />
<apex:pageBlockTable value="{!contacts}" var="c">
<apex:column headerValue="FirstName" value="{!c.FirstName}" />
<apex:column headerValue="LastName" value="{!c.FirstName}" />
<apex:column headerValue="Phone" value="{!c.Phone}" />
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>