Render Domain Field as HTML in GSP? - grails

I have a domain. User with a field description. In my Grails GSP page I can display it as:
${user.description}
The problem is that description contains valid html content like this:
<ul><li>test</li><li>test2</li><li>test3</li></ul><br>
This content should be rendered to be visible as HTML instead of a String.
How can I render a String containing HTML as HTML on a GSP?

To generate raw output use any of the following:
${raw(user.description)}
or
${user.description.encodeAsRaw()}
You can read this blog post that details this further. In later versions the default codec being used is HTML. You can control the default codec via Config.groovy.

Related

Why does an Action Text attachment render out an "action-text-attachment" tag when rendered as HTML?

I understand that Action Text attachments are store in the DB in a compressed form that appears as an "action-text-attachment" tag. However when rendered using to_trix_html this tag is not rendered as I suppose it would mess with Trix's internal model.
I cannot understand why this tag is required when Rich Text is rendered as HTML (for example in a show action). I'd really appreciate if someone could explain why this has been designed this way.
its need to be there as an identifier and its saved like that inside the database
the tag contain 5 attributes content-type
url
filename
filesize and sgid
sgid is Signed Global IDs its unique to each file the function is as an anti-tamper and identifier about the attached file
as for the .to_trix_html giving different tag yes its need to be like that
because we want different way to handle the attachment inside the trix editor and when it outside the trix editor.
and if you want to know more about how the attachments works in action_text you could check this blog post

Render HTML with MVC ViewBag

Is there a way to render HTML tags from a ViewBag? I am pulling article content out of a database, but the HTML tags included in the article aren't rendered.
For example:
ViewBag.ArticleContent = "Machine <strong>Language</strong> Content";
The tag doesn't render, it just shows up as text. This is a static string, but I get the same issue when I assign to ViewBag.ArticleContent from the database.
I figured it out. This appears to be working:
#Html.Raw(ViewBag.ArticleContent)

Generate Text (.txt) file for Data displayed in GSP

I have a Grails app developed in 2.3.6
There's a GSP file with HTML and CSS elements in it, and that displays data in multiple tables with headers.
I want this data to be saved into a text file and save it. So basically what i want to do is, there will be a Export button in this GSP page, and when user clicks on it, it will download the text file with all the data from that GSP.
What i tried so far?
def textFile = {
response.setHeader('Content-Disposition', 'Attachment;Filename="textFile.txt"')
render view: 'textFile', contentType: 'text/plain'
}
The problem with above is, it saves not just data, but also HTML & CSS elements.
I don't want any HTML or CSS in the text file. Only data from GSP is needed.
Is there a simple way of doing it.
the answer is simple - you need another view withouth the html and css parts.
The rest of your code looks good. But Grails itself does not convert your view, it just sends the content type to the browser and the browser tries to diesplay the data according to the content type.
If you don't want to write a new view (in most cases, writing the new view is dead simple), you could write your own converter (something which strips the HTML and CSS from your file) by creating an afterView-Filter: http://grails.github.io/grails-doc/2.4.0/guide/single.html#filters
Hope that helps

render html in a rich text box in active reports software

I have a string with basic html markup which I want to put into a rich textbox
string ab = #"<b> a b </b>"
I want it to render as it would appear in a browser ie:
a b
how can I do this in active reports 7? According to http://www.datadynamics.com/forums/77664/ShowPost.aspx, a richtextbox supports these tags. Do I have to specify a property to allow it to render html? How should I approach this?
Thanks,
Sam
More information (Update 8/11):
I'm binding the data from a database field - an oracle nclob. The field repeats within the detail section (with different information each time).
If I bind the field directly to a textbox or label it renders the string, but doesnt encode the html
<b> a b </b>
but it encode the string.
Solution Summary
Solution (as suggested by #activescott)
Bind rtx directly to the datafield
'Reformat' the text into html in
the script
public void detail_Format()
{
rtxBox.Html = rtxBox.Text;
}
result: renders the html field with some degree of html formatting
notes:
binding directly in the script doesnt work,
ie. rtxBox.Html = pt.Fields["CONT_ID"].ToString(); yields some wierd meta data string
the Datafield only binding approach doesn't work
(it will yield it as text)
there are some extra spacing that occurs with p tags. It may be worth regexing them out or somehow providing some formatting control.
The actual property you are looking for is the Html Property. You can also load a file into that control using the step-by-step walkthrough here.
I am assuming you are using Section Reports and not Page Reports.
To use HTML from the database in a bound report, you should be able to use the DataField property of the RichTextBox control (set it to the name of the corresponding Data field at design time). However, I noticed this "Render HTML tags in DB in ActiveReport pdf or HTML" article which kind of implies that doesn't work since it loads the HTML from a database programatically. One of the two should work.

Textareas and unsafe content

I've got wiki style content which is sanitized and stored in another field of the db for output as html. The original body field I'm not sure how to deal with as when I santize it characters are escaped and don't display well in the textarea.
What are the dangers of unsafe content in textareas? I'm sure I read previously that downloading such textarea content with ajax is preferable but I'd rather not go down that route if not necessary.
all HTML tag are no safe. by example if you close the textarea, you can add all nez HTML tag or what you want like JS. So it's exactly like inside a non textarea tag.

Resources