You need to sign in to do that
Don't have an account?
Dynamic "headerValue" binding in VF page
Probably its just me, because I do not see anybody complaining about this. I have a simple VF page with pageblock referencing to a wrapper object. I need to display text from that wrapper object in headerValue for a column, but cannot do that, After trying for almost half a day, I have given up.
Please look at column 2, dynamic referencing cannot be simple that this. It is just calling a string field, objType from the wrapper class. If one argues, that it has to be sObject field, please look at column 3. I am typecasting it with hardcoded 'ListPrice' field, but it still won't work.
What is most frustrating, inputText values within those 2 columns which is replica of 'headerValue' works just fine, I can see ObjectType and field Lable in 2nd and 3rd column respt.
Please help me , am I missing something here? are 'headerValues' exception to dynamic binding. I am sure someone might have come across this in the past.
VF page:
<apex:pageBlock > <apex:pageBlockTable id="tbl1" value="{!wObjs}" var="wObj"> <apex:column headerValue="Select"> <apex:inputCheckbox value="{!wObj.selected}" required="true" /> </apex:column> <apex:column headerValue="{!wObj.objType}"> <apex:inputText value="{!wObj.objType}" required="true" /> </apex:column> <apex:column headerValue="{!$ObjectType[wObj.objType].Fields.ListPrice.Label}"> <apex:inputText value="{!$ObjectType[wObj.objType].Fields['ListPrice'].Label}" required="true" /> </apex:column> </apex:pageBlockTable> </apex:pageBlock>
Apex class (wrapper object):
public class wObj{ public sObject sObj {get; set;} public string objType {get; set;} public Boolean selected {get; set;} public wObj(sObject childObjRecord, boolean selected){ this.sObj = childObjRecord; this.objType = childObjRecord.getSObjectType().getDescribe().getName(); this.selected = selected; } }
I asume you also have something like:
public list<wObj> wObjs = new list<wObj>();
public list<wObj> getwObjs() {
return wObjs;
}
in your controller?
This is what I have
If you look at input variables in VF page, they are being populated, but not the headerValue.
Thanks Patrik for your time.
Intead of <apex:column headerValue="foo"> which I think can only take string literals?
try
basically make the header a facet vs a headerValue. I use facet to make something a command link for example, or a checkbox....so maybe it will work better for this to?
Let me know, I'll be curious if that solves it.
I tried that as well, nothing seems to be working. This is so straight fwd, I think it is a bug or a missing feature.
Are you in touch with salesforce team who manages vf bugs?
Thanks for your time.
Maybe the issue is that you are using a loop variable to set the header rather than a value fixed for the whole table?
So perhaps you could try setting an <apex:variable> outside the table which takes its value from the first element of your list, and then use that for the header text.
eg:
<apex:variable value="{!$ObjectType[wObjs[0].objType].Fields.ListPrice.Label}" var="colName">
<apex:pageBlock >
<apex:pageBlockTable id="tbl1" value="{!wObjs}" var="wObj">
...
<apex:column headerValue="{!colName}">
You can't use the repeat variable in headerValue, as it's not part of the repeat (it only appears once on the page). Instead, you'll have to use some non-repeating variable to show the headerValue dynamically, such as:
If you're trying to create the table with a variable number of columns and rows, you can use apex:repeat tags to dynamically create columns. In this case, use a List<String> to find your column names ( $ObjectType[objName].fields[fieldName].Label ) and field bindings ( inputField value="{!wrapper.record[fieldName]}" ).
Also, there's the new Dynamic Visualforce feature that lets you create VF elements from Apex Code; you might also look into this route.
I'd recommend you take a step back, and state your goals for the project instead of starting from this half-way point. While I can speculate on what you might be trying to do, without knowing exactly whats going on, I don't know exactly how to assist you.
Patrick,
I cannot have apex:variable outside the pageBlockTable, because I need to display dynamic related objects with dynamic fields for an Id.
I tried to set <apex:variable> inside the look, and assign it to column, but still blank.
Thanks.
sfdcfox,
You guessed it right, I need to show dynamic related objects, along with dynamic related fields. Wish I could use FieldSets, they are so easy to configure.
I started with dynamic VF feature, but for some reason inputCheckBox won't set from Apex. Please see below:
col = new Component.Apex.Column();
chkBox = new Component.Apex.inputCheckbox();
col.headerValue= String.Valueof(w.selected); // Does show true
chkBox.selected = true; // Does not work
chkBox.value = true; // Does not work
col.childComponents.add(chkBox);
Below is my best shot, can you please help with column headers, I did not quite understand your suggestion.
Except for first column (select checkbox), other columns have blank header.
Thank you for your time.
Actually, I think I said the same as sfdcfox ...