Remove your existing code and paste following codes, it will definitely work: Apex
public class ContactgivenId {
public List<Account> acct{get; set;}
public List<Contact> cont{get; set;}
public String acctid{get; set;}
public ContactgivenId(){
acct=new List<Account>();
cont= new List<Contact>();
acct=[select id,name from account LIMIT 10];
}
public void getContact(){
cont=[select id, firstname, lastname, phone from contact where account.id= :acctid];
}
}
VF
Mark it as Solved, if it works.<apex:page id="pgId" controller="ContactgivenId">
<Apex:form >
<apex:pageBlock >
<Apex:pageblockSection title="Accounts">
<apex:pageBlockTable value="{!acct}" var="account">
<Apex:column headervalue="Account id">
<Apex:outputPanel >
<Apex:outputText value="Click" />
<apex:actionSupport event="onclick" action="{!getContact}" rerender="contactBlock" >
<Apex:param name="accountId" assignTo="{!acctId}" value="{!account.Id}"/>
</apex:actionSupport>
</apex:outputPanel>
</apex:column>
<Apex:column headervalue="Account name">
<Apex:outputField value="{!account.Name}" />
</apex:column>
</apex:pageBlockTable>
</Apex:pageblockSection>
</apex:pageBlock>
<apex:pageBlock id="contactBlock">
<Apex:pageblockSection title="Contacts">
<apex:pageBlockTable value="{!cont}" var="c">
<Apex:column headervalue="Contact id">
<Apex:outputField value="{!c.Id}"/>
</apex:column>
<Apex:column headervalue="Contact name">
<Apex:outputField value="{!c.firstName}" />
</apex:column>
</apex:pageBlockTable>
</Apex:pageblockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
13 réponses