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
canonwcanonw 

How to generate   ?

I have to following code snippet

Code:
<apex:column ... >
{!IF(ISNULL(var.Name), "&nbsp;", var.Name)}
</apex:column>


This block does not generate &nbsp; as expected.  Instead, it renders &#160; instead. 

Does anyone know the proper coding to render &nbsp;? 


Thanks in advance.
dchasmandchasman
This one is a bit tricky on the current release. There are a couple of things going on, one that you'll have to address regardless is by default all page formula results are HTML escaped to combat possible script injection attacks. This one is easy, you need to switch to using an <apex:outputText escape="false"/> component to let visualforce know that you want to disable value escaping. The second issue is a problem with the handling of the '&' character in page formulas in the current release - that issue has already been corrected in the next major release and will greatly simplify the solution.

For now one workaround item #2 above is to push the '&nbsp;' into apex code like this:

Code:
<apex:page controller="NbspController">
Hello<apex:outputText value="{!nullValue(var.Name, nbsp)}" escape="false"/>There
</apex:page>

public class NbspController {
public String getNbsp() {
return '&nbsp;';
}
}

Move the method getNbsp() into your controller or extension if you are already using apex code behind your page(s).

NOTE In the Winter '09 release the following greatly simplifed (no apex code required) approach will work:

Code:
<apex:page>
Hello<apex:outputText value="{!nullValue(var.Name, '&nbsp;')}" escape="false"/>There
</apex:page>

 


jwetzlerjwetzler
If I get what you are trying to do you're tackling the issue where a null value in your column does not render the line separator between the rows. 

This solution doesn't solve the escaping issue but note that {!var.name}&nbsp; should work just fine without the need to check for null.  Then even if your name is not null, it will just tack a space on the end.


Message Edited by jwetzler on 07-10-2008 10:44 AM
canonwcanonw
Thanks all. 

The reason to generate &nbsp; is for css styling.  In IE, I need &nbsp; to fix look and feel on empty <td>.  Otherwise.  IE does not apply style to empty cell.
jwetzlerjwetzler
Right, that's what I said in my post.  so {!var.name}&nbsp; should work for you in this case without having to mess with the escaping.
canonwcanonw
That's a nice trick!!!

Even though I don't want to add &nbsp; unless it's necessary, this compromise would make a lot of sense.