function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
logontokartiklogontokartik 

Dynamic Bindings and Wrapper Class

Hi,

I am trying to dynamically display the fields of a custom object in a list. for that I am using the concept of VF Dynamic Bindings.

<apex:repeat value="{!columnFieldsList}" var="flds">                 
 <apex:column > 
  <apex:facet name="header">   
 <apex:outputField value="{!l.loc[flds]}" style="width:30%;"/>                	
 </apex:column> 
</apex:repeat>

 This works fine for me, 

But now I want to extend this functionality by adding a command link on the reference fields. for that I have created a Wrapper class with a boolean value isReference and checking in the controller if the field is a Reference and setting boolean to true.

 

But in VF, I am not sure how to use the wrapper in the apex repeat statement for a dyamic binding.. Below is what I did and I am getting error

 

 

<apex:repeat value="{!columnFields}" var="flds">                 
 <apex:column > 
  <apex:commandLink value="{!l.loc[flds.ColumnFieldName]}" id="fieldname" action="{!navigatefield}" target="_blank" rendered="{!flds.isReference}">
               <apex:param name="FieldId" value="{!!l.loc[flds.ColumnFieldName]}" assignTo="{!fieldName}"/>  
   </apex:commandLink> 
<apex:outputField value="{!l.loc[flds.ColumnFieldName]}" style="width:30%;" rendered="{!NOT(flds.isReference}/>                	
 </apex:column> 
</apex:repeat>

 

 

Can anyone tell me or confirm if VF Bindings can be done using wrapper classes? or if there is roundabout for this problem?

 

Thanks

Kartik

 

 

 

aballardaballard

Not sure what you are wrapping where.

 

What is l.loc returning?  Do you mean l.loc[flds].ColumnFieldName ? 

logontokartiklogontokartik

l.loc returns the custom object.  If I use l.loc[flds] - where flds is the dynamic binding. fields are dynamically displayed. So for example if the flds contain name, city, state  l.loc[flds] will display data for name, city and state from l.loc object

 

My objective is for example if flds has a reference field say Account Name, then I want to have a command link so that when user click on it he is redirected to that account. 

for that I have used a wrapper class

 

public class wColumnFields {
	
	public String columnFieldName{get;set;}
	public Boolean isReference{get;set;}

	public wColumnFields(String fieldname, boolean isRef){
		this.isReference = isRef;
		this.columnFieldName = fieldname;
	}

 Now I am stuck because if I use a dynamic binding notation for a wrapper class property, i am getting internal error.

 

 

 

 

 

aballardaballard

Where flds.ColumnFieldName certainly can't be right, because Flds is just an item from the fieldset.  Not your wrapper object. 

 

dipudipu

I have created similar VF pages earlier. You will have to add many dummy columns and set the rendered property based on the number of fields you have. Following is  from the SFDC documentation. Obviously you cannot have apex:column inside apex:repeat, since apex:column goes only inside of dataTable or pageBlockTable.

 

apex:repeat

This component cannot be used as a direct child of the following components:

  • apex:dataTable
  • apex:pageBlockTable
aballardaballard

That is not true.. Repeat can be used as a child of datatable to generate columns since dynamic reference support was implemented.

dipudipu

Thanks aballard

You are correct. Documentation need update. www.salesforce.com/us/developer/docs/pages/Content/pages_compref_repeat.htm

 

Kartik,

Repeat over a list of field names. Place the wrapper in a map with fieldname as the key. If you have no other property in the wrapper just keep the reference property in the map. I just tried it and works for me.

Shashikant SharmaShashikant Sharma

I differ from this I think what you want can achieve from wrapper. You just need to ensure that the columnFieldName in wrapper always have API Name of the field.

Shashikant SharmaShashikant Sharma

One more thing are you getting a compile time error and not able to save the page or a runtime error when you use wrapper for dynamic binding/