You need to sign in to do that
Don't have an account?
sean*harrison
databinding or including HTML
I'm playing with databinding and have a question that is probably obvious to more knowledgeable folks...
If I write a class like this:
public class HelloWorld
{
public String getHTML
{
get
{
return '<strong>The Earth says Hello</strong>';
}
set;
}
}
and create a page like so:
<apex:page controller="HelloWorld"> <h1>Good morning, Starshine</h1> {!getHTML} </apex:page>
I expect the output on my apex page to be something like:
Good morning, Starshine
The Earth says Hello
but instead I get:
Good morning, Starshine
<strong>The Earth says Hello</strong>
in other words my html tags are getting encoded so the databinding returns "<strong>...etc."
I want to send HTML to the page to be interpreted by the browser as HTML. Is there something I'm doing obviously wrong?
Hey
You can also use the visualforce outputText elements with the escape attribute set to false i.e.
Cheers,
Wes
All Answers
You have included HTML tags in your get method :-
get
{
return '<strong>The Earth says Hello</strong>';
}
instead any formatting please do it on the VF page.
Please try the following:-
<apex:page controller="HelloWorld">
<h1>Good morning, Starshine</h1>
<b>getHTML}</b>
</apex:page>
Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved.
Thanks, but that doesn't really get at it.
If I want to send HTML or XML or whatever to the VF page and have it NOT encoded, is that possible?
Say, for example, I want to do a RESTful callout to some webpage, get the body, maybe do something with the DOM and then send it on to the VF page to be included. It's no good if the VF page always encodes every tag in the data.
You can use a simple js like this
<apex:page controller="Test">
<h1>Good morning, Starshine</h1>
<span id="test"/>
<script>
document.getElementById('test').innerHTML = '{!getHTML}';
</script>
</apex:page
Hey
You can also use the visualforce outputText elements with the escape attribute set to false i.e.
Cheers,
Wes
Ahhh...nice. Helps to learn all the params for the vf tags. Thanks!