You need to sign in to do that
Don't have an account?
DannyK89
Converting apex:columns to apex:outputFields
I want to make my visual force page have outputFields so that it is easier to read. Here is what I have so far. insurance_insured has a look up relationship with Account.
<apex:page standardController="Account"> <apex:form > <apex:pageBlock title="General Liability"> <apex:pageBlockTable value="{!account.insurance_insured__r}" var="item"> <apex:detail relatedList="false"/> <apex:column title="Insurance" value="{!item.name}" rendered="{!item.Insurance_Type__c == 'General Liability'}"/> <apex:column title="Action" rendered="{!item.Insurance_Type__c == 'General Liability'}"> <apex:commandButton value="About" onclick="window.location='/{!item.id}'; return false;"/> </apex:column> <apex:column title="Insurance Carrier" value="{! item.Insurance_Carrier__c}" rendered="{!item.Insurance_Type__c == 'General Liability'}"/> <apex:column title="Effective Date" value="{! item.Effective_Date__c}" rendered="{!item.Insurance_Type__c == 'General Liability'}"/> <apex:column title="Expiration Date" value="{! item.Expiration_Date__c}" rendered="{!item.Insurance_Type__c == 'General Liability'}"/> </apex:pageBlockTable> </apex:pageBlock> <apex:pageBlock title="Professional Liability"> <apex:pageBlockTable value="{! account.insurance_insured__r}" var="item"> <apex:column title="Insurance" value="{! item.name}" rendered="{!item.Insurance_Type__c == 'Professional Liability'}"/> <apex:column title="Action" rendered="{!item.Insurance_Type__c == 'Professional Liability'}"> <apex:commandButton value="About" onclick="window.location='/{!item.id}'; return false;"/> </apex:column> <apex:column title="Insurance Carrier" value="{! item.Insurance_Carrier__c}" rendered="{!item.Insurance_Type__c == 'Professional Liability'}"/> <apex:column title="Effective Date" value="{! item.Effective_Date__c}" rendered="{!item.Insurance_Type__c == 'Professional Liability'}"/> <apex:column title="Expiration Date" value="{! item.Expiration_Date__c}" rendered="{!item.Insurance_Type__c == 'Professional Liability'}"/> </apex:pageBlockTable> </apex:pageBlock> <apex:pageBlock title="Work Comp Liability"> <apex:pageBlockTable value="{! account.insurance_insured__r}" var="item"> <apex:column title="Insurance" value="{! item.name}" rendered="{!item.Insurance_Type__c == 'Work Comp Liability'}"/> <apex:column title="Action" rendered="{!item.Insurance_Type__c == 'Work Comp Liability'}"> <apex:commandButton value="About" onclick="window.location='/{!item.id}'; return false;"/> </apex:column> <apex:column title="Insurance Carrier" value="{! item.Insurance_Carrier__c}" rendered="{!item.Insurance_Type__c == 'Work Comp Liability'}"/> <apex:column title="Effective Date" value="{! item.Effective_Date__c}" rendered="{!item.Insurance_Type__c == 'Work Comp Liability'}"/> <apex:column title="Expiration Date" value="{! item.Expiration_Date__c}" rendered="{!item.Insurance_Type__c == 'Work Comp Liability'}"/> </apex:pageBlockTable> </apex:pageBlock> <apex:pageBlock title="Other Liability"> <apex:pageBlockTable value="{! account.insurance_insured__r}" var="item"> <apex:column title="Insurance" value="{! item.name}" rendered="{!item.Insurance_Type__c == 'Other Liability'}"/> <apex:column title="Action" rendered="{!item.Insurance_Type__c == 'Other Liability'}"> <apex:commandButton value="About" onclick="window.location='/{!item.id}'; return false;"/> </apex:column> <apex:column title="Insurance Carrier" value="{! item.Insurance_Carrier__c}" rendered="{!item.Insurance_Type__c == 'Other Liability'}"/> <apex:column title="Effective Date" value="{! item.Effective_Date__c}" rendered="{!item.Insurance_Type__c == 'Other Liability'}"/> <apex:column title="Expiration Date" value="{! item.Expiration_Date__c}" rendered="{!item.Insurance_Type__c == 'Other Liability'}"/> </apex:pageBlockTable> </apex:pageBlock> </apex:form> </apex:page>
Hi Danny,
How about this - replace the pageBlockTable with a repeat element. Inside the repeat element, have a pageBlockSection that only renders if the insurance type matches what you want. Inside this pageBlockSection, have the output fields you need.
Example:
EDIT: fixed wrong closing tag.
All Answers
The problem is that doesn't work. When I change it to a output field it does not render.
Hi Danny,
It seems like you are using a apex:pageBlockTable to loop over a detail component (which I don't think will render) and a set of columns. Is your intention to have a repeating pageBlock for each item?
If you don't want the fields rendered as columns, then consider using a apex:repeat tag to repeat a group of output fields.
Alternatively, if you want to keep the data formatted as a table, you could enclose an apex:outputField in a apex:column tag, but I don't think that is what you are looking for.
Try to change you <apex:column> to the code hilighted and see if it works:
I think you need to actually describe what your problem is.
If your apex:column's value attribute refers to an sObject field and it's inside a pageBlockTable, it's automatically converted to an outputField behind the scenes.
But I'm not sure where you're going with having the rendered attribute on a column referring to just item in the iteration. Do you want an entire column hidden in a specific case, or do you just want certain cells to be hidden under specific conditions? Sravu's example would conditionally display individual cells in your table. The way you have it now I think it will show or hide columns based on the very first entry in your list, which I can't imagine is what you want.
I think using apex:outputfield inside apex:column tags will work abosulutely fine as mentioned in above post.
I tried the apex:outputField inside of the apex:column tags and I get a bunch or blank lines my column. What I want to do is make outputFields for the values inside the apex:column fields. The object that is used in the apex:columns is a related list in account. I want to show field from the object that is a related list int he account object on an visualforce page as ouputFields. I am having trouble because everytime I try to use "account.insurance_insured__r" I get an error. I want to know if there is a way to access the fields from a related list object on a visualforce page as an apex:outputField.
Hey, did you try what larkinrichards suggested in his post above - i.e. use the <apex:repeat> tag to iterate over the collection, rather than <apex:pageBlockTable> and use <apex:outputField> inside it.
i.e.
<apex:repeat var=......
<apex:outputField value="{!......
</apex:repeat>
I tried the apex:repeat tag as well. It still looks like a column but know everything is squished together. I am really trying to make the values look like fields and not like columns.
Instead of "account.insurance_insured__r" try using
account.insurance_insured__r[0].fieldname
Where would I put that? In the apex:repeat ?
Hi Danny,
How about this - replace the pageBlockTable with a repeat element. Inside the repeat element, have a pageBlockSection that only renders if the insurance type matches what you want. Inside this pageBlockSection, have the output fields you need.
Example:
EDIT: fixed wrong closing tag.