Uncategorized

Including spaces/html entities in JSF component output.

Rather a silly problem but a problem nevertheless, including html entities as spaces special charactes etc… causes them to be escaped by the jsf.

So something like getSpacedName(){return "Hello   world";} will be outputed in the pages exactly as we have entered in out method above. On regulat h:outputText we can use ‘escape’ attribute and set it to false and get what we desire but with other components that output a dropdown or something where formating is in need thats not possible.

Solution is to use the Unicode characters

getSpacedName(){
  String space  = "\u00a0";
  return String.format("Hello%s%s%%sworld",space, space, space);
}

I know that we should not be doing crazy things like this in our backingbeans but when you have to you have to.
space_screen

One thought on “Including spaces/html entities in JSF component output.

Leave a Reply

Your email address will not be published. Required fields are marked *

* Copy This Password *

* Type Or Paste Password Here *