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
Sunny670Sunny670 

Can someone please look why this is not working?

Hi all, below is my code peice.

 

<apex:outputText value="{0, number, $###,###,###,###,###}" rendered="{!if(my field<>null,(if( my field< 0, '(' + text(abs(my field)) + ')',text(my field))),my field)}">

<apex:param value="{!my field}"/>

</apex:outputText>

 

if my field value is = -20 expected output:($20) but i am getting as -$20.

devfyadevfya
You're using 'rendered' incorrectly. It is a Boolean property that defines whether a control is shown. I don't think you can format your value this way using just Visualforce. I'd suggest you do the formatting in your Apex code. For example:
String formatted = decVal.format();
formatted = formatted.startsWith('-') ? ('($' + formatted.remove('-') + ')') : ('$' + formatted);
Sunny670Sunny670
The condition which i used above was working previously before i add the null check. After adding null check it was not working properly.i cannot modify anything in class.i want to do it in page itself.
Michael_TorchedloMichael_Torchedlo

devfja is right, you are using the rendered attribute in a slightly incorrect way.  Rendered is supposed to be a boolean value, but you are using it as though you could return a numberic value to display.  So, I'm not sure why it was working before as you claim.

 

Regarding your question, the syntax my field<>null doesn't work in this context.  Instead, you can try using NOT(ISNULL(my field))

 

You might want to also try creating two different outputText fields, one renders TRUE if the number is non-negative, the other one renders TRUE if the number is negative.  That way you should be able to have 2 different formatting strings without going into your controller.

 

<apex:outputText value="{0, number, $###,###,###,###,###}" rendered="{!AND(NOT(ISNULL(my field)), my field>=0)}">
<apex:param value="{!my field}"/>
</apex:outputText>

 

<apex:outputText value="{0, number, ($###,###,###,###,###)}" rendered="{!AND(NOT(ISNULL(my field)), my field<0)}">
<apex:param value="{!ABS(my field)}"/>
</apex:outputText>

 

Sunny670Sunny670
i have used <apex:output Field> instead of <apex:output Text>, it is working fine now.