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

Need help on selectoptions and vf page blocks
Hi I want to display contact and accounts in the same page, Account first with editable fields and a checkbox. once I click the checkbox it should display the related contact below it and allow me to edit it. Also, at top there should be a industry listview to display accounts accordingly.. Below is the code and output screen which I am getting at the moment, please help
Apex
public class DiplayRelatedContacts {
public List<Account> accList{get;set;}
public list<Contact> conList{get;set;}
public String accId{get;set;}
public String str{get;set;}
public DiplayRelatedContacts (){
acclist=[SELECT Id,Name,AccountNumber, industry FROM Account Where industry=:str];
}
public List<SelectOption> Accountlist
{
get
{
Accountlist= new List<SelectOption>();
for(Account acc: acclist)
{
//string str = String.valueOf(acc.getRelationshipNaryme());
if(acc.industry!=null){
string str=acc.industry;
Accountlist.add(new SelectOption(str, str));
// Accountlist.add(new SelectOption(acc.industry, acc.industry));
}
}
return Accountlist;
}
set;
}
public PageReference dispalyContact() {
if(accId != null)
conList=[SELECT id,FirstName,LastName FROM Contact WHERE AccountId=:accId];
return null;
}
public PageReference SaveAccount(){
if(acclist.size()> 0){
Update acclist;
}
return null;
}
public PageReference SaveContact(){
if(conList.size()>0){
Update conlist;
}
return null;
}
}
________________________________________
VF page
<apex:page controller="DiplayRelatedContacts" id="pg">
<apex:form id="frm">
<apex:pageBlock>
<apex:pageblockButtons>
<apex:commandButton value="Save Account" action="{!SaveAccount}"/>
<apex:commandButton value="Save Contact" action="{!SaveContact}"/>
</apex:pageblockButtons>
</apex:pageBlock>
<apex:pageBlock id="pgblk" >
<apex:selectList size="3">
<apex:selectOptions value="{!Accountlist}"></apex:selectOptions>
</apex:selectlist>
<apex:pageBlockTable value="{!acclist}" var="ac">
<apex:column width="10px">
<input type="radio" name="group1" />
<apex:actionSupport event="onclick" action="{!dispalyContact}" ReRender="conpgblk" >
<apex:param assignTo="{!accId}" name="accname" value="{!ac.id}"/>
</apex:actionSupport>
</apex:column>
<apex:column headervalue="Account Name">
<apex:inputfield value="{!ac.Name}" />
</apex:column>
<apex:column headervalue="Account Number">
<apex:inputfield value="{!ac.AccountNumber}" />
</apex:column>
<apex:column headervalue="Account Industry">
<apex:inputfield value="{!ac.industry}" />
</apex:column>
</apex:pageBlockTable>
</apex:pageBlock>
<apex:pageBlock id="conpgblk" >
<apex:outputPanel rendered="{!conList.size == 0}">
<b> NO RELATED CONTACTS FOR THIS ACCOUNT .</b>
</apex:outputPanel>
<apex:outputPanel rendered="{!conList.size != 0}">
<apex:pageBlockTable value="{!conList}" var="con">
<apex:column headervalue="Firstname">
<apex:inputfield value="{!con.FirstName}"/>
</apex:column>
<apex:column headervalue="Last Name">
<apex:inputfield value="{!con.LastName}"/>
</apex:column>
</apex:pageBlockTable>
</apex:outputPanel>
</apex:pageBlock>
</apex:form>
</apex:page>
_______
the Output page

Apex
public class DiplayRelatedContacts {
public List<Account> accList{get;set;}
public list<Contact> conList{get;set;}
public String accId{get;set;}
public String str{get;set;}
public DiplayRelatedContacts (){
acclist=[SELECT Id,Name,AccountNumber, industry FROM Account Where industry=:str];
}
public List<SelectOption> Accountlist
{
get
{
Accountlist= new List<SelectOption>();
for(Account acc: acclist)
{
//string str = String.valueOf(acc.getRelationshipNaryme());
if(acc.industry!=null){
string str=acc.industry;
Accountlist.add(new SelectOption(str, str));
// Accountlist.add(new SelectOption(acc.industry, acc.industry));
}
}
return Accountlist;
}
set;
}
public PageReference dispalyContact() {
if(accId != null)
conList=[SELECT id,FirstName,LastName FROM Contact WHERE AccountId=:accId];
return null;
}
public PageReference SaveAccount(){
if(acclist.size()> 0){
Update acclist;
}
return null;
}
public PageReference SaveContact(){
if(conList.size()>0){
Update conlist;
}
return null;
}
}
________________________________________
VF page
<apex:page controller="DiplayRelatedContacts" id="pg">
<apex:form id="frm">
<apex:pageBlock>
<apex:pageblockButtons>
<apex:commandButton value="Save Account" action="{!SaveAccount}"/>
<apex:commandButton value="Save Contact" action="{!SaveContact}"/>
</apex:pageblockButtons>
</apex:pageBlock>
<apex:pageBlock id="pgblk" >
<apex:selectList size="3">
<apex:selectOptions value="{!Accountlist}"></apex:selectOptions>
</apex:selectlist>
<apex:pageBlockTable value="{!acclist}" var="ac">
<apex:column width="10px">
<input type="radio" name="group1" />
<apex:actionSupport event="onclick" action="{!dispalyContact}" ReRender="conpgblk" >
<apex:param assignTo="{!accId}" name="accname" value="{!ac.id}"/>
</apex:actionSupport>
</apex:column>
<apex:column headervalue="Account Name">
<apex:inputfield value="{!ac.Name}" />
</apex:column>
<apex:column headervalue="Account Number">
<apex:inputfield value="{!ac.AccountNumber}" />
</apex:column>
<apex:column headervalue="Account Industry">
<apex:inputfield value="{!ac.industry}" />
</apex:column>
</apex:pageBlockTable>
</apex:pageBlock>
<apex:pageBlock id="conpgblk" >
<apex:outputPanel rendered="{!conList.size == 0}">
<b> NO RELATED CONTACTS FOR THIS ACCOUNT .</b>
</apex:outputPanel>
<apex:outputPanel rendered="{!conList.size != 0}">
<apex:pageBlockTable value="{!conList}" var="con">
<apex:column headervalue="Firstname">
<apex:inputfield value="{!con.FirstName}"/>
</apex:column>
<apex:column headervalue="Last Name">
<apex:inputfield value="{!con.LastName}"/>
</apex:column>
</apex:pageBlockTable>
</apex:outputPanel>
</apex:pageBlock>
</apex:form>
</apex:page>
_______
the Output page