I am trying to format the new Time field type in Visualforce but with no success.
I'm trying to use the same method as i use for date formatting but it does not compile my code with the error:
'The value attribute on
<apex:outputText>
is not in a valid format. It must be a positive number, and of type Number, Date, Time, or Choice.'.
And i can't seem to find any documentation about this new field type or formatting only time variables. My code atm:
<apex:outputText value="{0,time,HH':'mm}">
<apex:param value="{!obj.Time_field__c}"/>
</apex:outputText>
Best Answer
I think this is a bug or an oversight, but I can't really prove it.
The
Time
class in Salesforce is very limited, especially compared to theDateTime
class. It doesn't even have its ownformat
method, which I think may be the underlying problem here. Without aformat
method to accept the formatting string, Salesforce might not be able to properly format the field, but the error reported doesn't seem to relate.. although a value which cannot be formatted could be considered an invalid value in this case.I also think the
Time
option for theapex:outputText
was not meant for this field, but rather, theTime
component of aDateTime
class. For example, in the code below, I'm using theTime
option in the value, but I'm using aDateTime
field, and it renders without any problems.The same
outputText
causes a compile error if we try to use a Time field instead.As for a solution, I would do the formatting myself in the controller, instead of relying on the visualforce to do it for me.
Apex:
Visualforce: