Hi,
I have been experimenting with simple text markup using Rtf/Html areas.
(Bold/Italic/color/underline)
Jasper Reports can print these now.
A disadvantage is that the markup is also stored in the database field.
I created an extra field that is filled with the “clean” text. We need the clean text
because we also export data to other systems that are not aware of markup.
Are there other people who use simple markup and how did they implement this ?
Regards,
Hans
You can also store it in a global field (temporarily) for reporting purposes. Alternatively, you may want to consider having tables for purpose of publishing or view. In these parallel tables/fields you can store (Markup of Text Fields) for the application’s users to see and keep your database “clean” fields apart. You’ll need to have a method the automatically populate the “clean” fields after changes in the RTF fields are committed.
You probably want to take a look at Bob Cusick’s example file about converting RTF to HTML (and back).
http://www.clickware.com/downloads/servoy/cw_sample_rtf_to_html.servoy
Bob’s example file demonstrates some text parsing and re-writing code when you need to create a way to convert RTF to HTML or HTML to RTF. The methods are pretty self-explanatory - but rather long. I guess you may be able to use this technique to convert RTF to simple text and from simple test to RTF.
Hans Nieuwenhuis:
Are there other people who use simple markup and how did they implement this ?
Hi Hans,
I have been doing the same thing for one of our project, using a customized html editor to build the markup and then converting it to plain text and store both in the DB.
I use a trick to convert the html to plain text without having to parse it at all.
I put a text field set as html area, with a visible = false on my form. Now when the user finishes editing the html in the editor (onFocusLost event), I set the value of this hidden text area to the resulting html and then simply use “getAsPlainText()” on it to retrieve the text I want to store in the DB…
It takes only a few lines vs tons of lines of parsing!
Oh God! Patrick, you are good.
Quick question: Does the getAsPlainText() function remove all of the html tags properly?
From my experience, yes. Although I didn’t make a test case of every possible tags.
When using basic formatting tags and tables, it works fine!
I see that the
“lazy programmer paradigm” is alive in well…
We use the ‘getAsPlainText’ function as well.
As I don’t want to end up having hidden elements throughout the application, we simply defined a formvariable on our main form.
This is a hidden element on the main form, last step was creating a global method as the example below.
function removeHtmlTags()
{
var $text = '' + arguments[0];
forms.Main.fHtml = $text;
var $result = forms.Main.elements.html_to_plain.getAsPlainText();
return $result;
}