Created
November 3, 2014 09:35
-
-
Save Sunil02kumar/1a094fd1d6a56a592840 to your computer and use it in GitHub Desktop.
Dynamic Pageblocktable to display header in column in apex:repeat tag
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class competitorEntryController { | |
private String Oppid; | |
public oppwrapper parentrec{get;set;} | |
public List<oppwrapper> opplist{get;set;} | |
public competitorEntryController(Apexpages.standardcontroller controller){ | |
Oppid=(string)controller.getrecord().get('Id'); | |
parentrec=new oppwrapper(); | |
for(Opportunity opp:[select id,name,(select id,name,name__c,Stage__c,NextStep__c from Competitors__r order by name),Stagename, | |
nextstep from Opportunity where id=:Oppid]){ | |
parentrec.opp=opp; | |
if(opp.Competitors__r.size()>0){ | |
List<CompetitorWrapper> temp=new List<CompetitorWrapper> (); | |
for(Competitor__c cm:opp.Competitors__r){ | |
competitorWrapper cw=new competitorWrapper(); | |
cw.comp=cm; | |
temp.add(cw); | |
} | |
parentrec.complist=temp; | |
} | |
} | |
opplist=new List<oppwrapper> (); | |
system.debug('*******parentrec.complist:'+parentrec.complist); | |
opplist.add(parentrec); | |
} | |
public PageReference Submit(){ | |
//update operation on opportunity and competitor records | |
Pagereference pag=new PageReference('/'+Oppid); | |
return pag; | |
} | |
public Component.Apex.PageBlockTable getMyPageBlockTable(){ | |
Component.Apex.PageBlockTable table=new Component.Apex.PageBlockTable(var='op'); | |
table.expressions.value='{!opplist}'; | |
if(opplist.size()>0){ | |
Component.Apex.pageblocksection pgblksec1 = new Component.Apex.pageblocksection (); | |
pgblksec1.columns=1; | |
Component.Apex.inputField inputField1 = new Component.Apex.inputField (); | |
inputField1 .expressions.value = '{!op.opp.stagename}'; | |
pgblksec1.childComponents.add(inputField1); | |
Component.Apex.inputField inputField2 = new Component.Apex.inputField (); | |
inputField2.expressions.value = '{!op.opp.nextstep}'; | |
pgblksec1.childComponents.add(inputField2); | |
Component.Apex.Column column = new Component.Apex.Column(headerValue=opplist[0].opp.name); | |
column.childComponents.add(pgblksec1); | |
table.childComponents.add(column); | |
if(opplist[0].complist.size()>0){ | |
integer count=0; | |
for(competitorWrapper comp:opplist[0].complist){ | |
Component.Apex.pageblocksection pgblksec2 = new Component.Apex.pageblocksection (); | |
pgblksec2.columns=1; | |
Component.Apex.inputField inputField3 = new Component.Apex.inputField (); | |
inputField3.expressions.value = '{!op.complist['+count+'].comp.Stage__c}'; | |
pgblksec2.childComponents.add(inputField3 ); | |
Component.Apex.inputField inputField4 = new Component.Apex.inputField (); | |
inputField4.expressions.value = '{!op.complist['+count+'].comp.nextStep__c}'; | |
pgblksec2.childComponents.add(inputField4 ); | |
Component.Apex.Column column1 = new Component.Apex.Column(headerValue='Competitor:'+opplist[0].complist[count].comp.name); | |
column1.childComponents.add(pgblksec2); | |
table.childComponents.add(column1); | |
count++; | |
} | |
} | |
} | |
return table; | |
} | |
public class oppwrapper{ | |
public opportunity opp{get;set;} | |
public List<CompetitorWrapper> complist{get;set;} | |
public oppwrapper(){ | |
complist=new List<CompetitorWrapper>(); | |
} | |
} | |
public class competitorWrapper{ | |
public Competitor__c comp{get;set;} | |
} | |
} | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<apex:page standardController="Opportunity" extensions="competitorEntryController"> | |
<apex:form > | |
<apex:pageblock title="Competitor section"> | |
<apex:pageblockButtons > | |
<apex:commandButton value="Save" Action="{!Submit}"/> | |
</apex:pageblockButtons> | |
<apex:pageblockSection columns="1" title="Pageblocktable using dynamic visualforce components from Apex"> | |
<apex:dynamicComponent componentValue="{!MyPageBlockTable}" invokeAfterAction="true"/> | |
</apex:pageblockSection> | |
</apex:pageblock> | |
</apex:form> | |
</apex:page> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Error: Compile Error: Didn't understand relationship 'Competitors__r' in FROM part of query call. If you are attempting to use a custom relationship, be sure to append the '__r' after the custom relationship name. Please reference your WSDL or the describe call for the appropriate names. at line 8 column 33