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

styleClass doesn't work with outputField

The class attribute isn't being set when I use outputField. As you can see in my example the HTML output is missing the class attribute which was set to XXX

My Page:

<apex:page controller="TestPageCon">
<apex:outputField styleClass='XXX' value='{!field.amount}'/>

My Controller:

public class TestPageCon {
public Opportunity getField() {
return [select id, amount from Opportunity limit 1];

Actual HTML output:

<span id="j_id0:j_id1">$60,000.00</span>

Where did my XXX go?

Where is the css? Is it embed with Style tags or are you using the apex:stylesheet tag?

TehNrd wrote:
Where is the css? Is it embed with Style tags or are you using the apex:stylesheet tag?
I don't have one defined but that's besides the point. I could add <style>.XXX{color:red;}</style> if I wanted to and I still wouldn't get my class="XXX" in my HTML output.
You are correct. I think I remember reading about a knowb issue with style and styleClass attributes on outputFields. I think the suggested solution was to wrap the output field in a <span class="xxx"> element.
Message Edited by TehNrd on 02-04-2009 04:45 PM
I found that if I use outputText the class="XXX" HTML output works, but now my currency isn't formatted with with dollar signs and commas. Is there an easy way to format a number to look like currency?

Wrapping the fields in an outputpanel works for me, styling and formatting:


<apex:outputpanel styleClass="OfferTextHeader"> <apex:outputtext value="{!$Label.RMOfferPrice} "/> <apex:outputfield value="{!Offer.Price__c}"/> </apex:outputpanel>


Crazy that in 2015, we are still having this exact same issue.
In 2016, too.

I noted in a related thread ( that no attributes of outputField work except "value".