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
modoleamodolea 

Problem with outputField in custom component

Hi,
 
I try to make dinamicaly a custom component in order to display an outputLabel and an outputField from a single vf tag.
Here is the code I use in the custom component called 'detailField':
 
Code:
 <apex:component>
    <apex:attribute name="label" type="String" required="true" description=""/>
    <apex:attribute name="value" type="SObject" required="true" description=""/>
    <apex:attribute name="style" type="String" required="true" description=""/>
    
    <apex:outputLabel value="{!label}" styleClass="{!style}"/>
    <apex:outputField value="{!value}"/>
</apex:component>
 
I get an error when I save: Error: Could not resolve the entity from <apex:outputField> value binding '{!value}'. outputField can only be used with SObject fields.
 
Can someone provide me a solution?
 
Thanks
adrian
 
 
 
YashYash
Hi,
as apex:outputField is used only with SObject , so try to use apex:outputText instead of outputField.


Thanks & Regards,
Yash
modoleamodolea

Thank you for your reply.

I already try to use outputText but the problem is that I lose the the stylesheet for the row.

regards

 

jwetzlerjwetzler
OutputField doesn't take an SObject, it takes an SObject field.  We don't have a data type for that yet.  If you change it to String does it work?

(Also don't forget to use the "for" attribute on outputLabel)

modoleamodolea

no, I change to 'String' but I get the same error. Also, when I use the 'for' attribute.

Also, when I use the 'for' attribute with outputText, there in no error, but the standard css style for the label and value in the detailTable is ignored. 

Component Code:
<apex:component >
    <apex:attribute name="label" type="String" required="true" description=""/>
    <apex:attribute name="value" type="String" required="true" description=""/>
    <apex:attribute name="style" type="String" required="false" description=""/>
    
    <apex:outputLabel value="{!label}" styleClass="{!style}" for="my_{!label}"/>
    <apex:outputText value="{!value}" id="my_{!label}"/>
</apex:component>

regards
 


 
jwetzlerjwetzler
oh... I see what the issue is.  I guess outputField needs to accept non SObject field types when it's inside a custom component.  I will log a bug for that to my team.

You should definitely stick to outputText for now.  Your styles should work for both of those.  You do realize that your custom component takes a style and that you're assigning that to styleClass instead of style on your outputLabel, right?  style takes things like "color:red" and styleClass takes the actual name of a css class.  You should be able to view the HTML source on your page and verify that the style you are passing in is getting generated.