cancel
Showing results for 
Search instead for 
Did you mean: 

Prevent HTML escaping in RichText fields

tiago_almeida2
Explorer
0 Kudos

Hello.

In an adobe form, I am trying to use html in a richtext field to display formatted text. The form is being generated in ABAP by calling the FM associated with it and the data passed to it is, among others, a character string with valid HTML (like the following:)

<b> text </b>

The problem is that the html arrives at the form escaped ( '<' is substituted by &lt, '>' by &gt, etc.) and the result of it is that the text field shows the literal html instead of the text formatted.

Do you know a way to prevent this automatic escaping? Does it have to be unescaped with javascript?

Moreover, I believe the form's richtext field is correctly configured because it works fine in the livecycle preview (field type="Text Field", field format="Rich Text" and data format set to "XHTML").

Thanks a lot in advance.

Best regards,

Tiago Almeida

Accepted Solutions (1)

Accepted Solutions (1)

OttoGold
Active Contributor
0 Kudos

Formatting in SO10 texts into the form

Regards Otto

tiago_almeida2
Explorer
0 Kudos

Hello. Thank you for your reply.

However, I don't think this is the same problem.

The texts being passed to the form are generated dinamically in ABAP and they are passed perfectly to the function module generated from the form. Example:

CALL FUNCTION 'FP_JOB_OPEN' 
  (...)

  CALL FUNCTION p_formname
    EXPORTING
*     /1BCDWB/DOCPARAMS = fp_docparams
      rich_text_test           = '<b>bold</b>not bold'
    IMPORTING
      /1bcdwb/formoutput = gs_formoutput
    EXCEPTIONS
      usage_error     = 1
      system_error    = 2
      internal_error  = 3
      OTHERS          = 4.

(...)

but it shows up (in the pdf) literally as

<b>bold</b>not bold

instead of boldnot bold as it should be..

If I print the value of rich_text_test in theform (using javascript) I see '&ltb&gtbold&lt/b&gtnot bold' which is html escaped.

My question is how to disable this automatic escaping...

Many thanks.

Tiago Almeida

OttoGold
Active Contributor
0 Kudos

Using the FM from the example prevents from the escaping the string. But yes, I might be wrong. Otto

0 Kudos

I had the same problem. It seems there is no method to prevent escaping of angle brackets. So I Base64 encode the xhtml on the abap side and decode it via JavaScript in the form.

tiago_almeida2
Explorer
0 Kudos

Thank you for your answers!

I'll try using that technique as soon as possible. I suppose you update the rawValue property of the text field with the base64decode? Or should it be another property?

Many thanks!

Best regards,

Tiago Almeida

0 Kudos

I use the following in the initialize event of the rich text field:

var b64 = this.rawValue;

if (b64 == undefined) {
  this.presence = "hidden";
}
else {
  var xhtml = base64.Base64.decode(b64);
  this.value.exData.loadXML(xhtml);
}

base64 is a global script variable containing the JavaScript Base64 en/decoder from http://www.webtoolkit.info/javascript-base64.html

Best regards,

Sebastian

Former Member
0 Kudos

Could you please elaborate on your solution??

I'm trying to do the same thing,and it isn't working.

Where exactly are you putting the script? You speak of global script variables, where do you add these?

Some details would be much appreciated!!!!

Thanks !!

tiago_almeida2
Explorer
0 Kudos

Thanks a lot for your answers. Finally found the time needed to test this and got it working (found a workaround for my original problem).

To create the global script object Sebastian refers, go to "Insert script object" in adobe livecyle (right click on the form hierarchy root), rename the new object to "base64" and then paste there, the code Sebastian links (Base64).

Afterwards, edit the initialize event code to decode the base64 encoded string and load it as XML.

e.g.


b64 = this.rawValue;
xhtml = base64.Base64.decode(b64);
this.value.exData.loadXML(xhtml);

and that's it!

I originally had 2 problems: First I was passing the xhtml in plain text so it got escaped (that's why you need to first encode it in base64 and then decode it, in javascript, in the form (thank you Sebastian!)).

Then, the string which gets ultimately passed to the loadXML method, must be a proper XML document (with the body and the namespace etc.) not just an XML fragment like I was testing initially.

e.g (this should work if pasted on the initialize event of the rich text field)


this.value.exData.loadXML('<body xmlns="http://www.w3.org/1999/xhtml" xmlns:xfa="http://www.xfa.org/schema/xfa-data/1.0/"><p><b>this should be bold</b>this is not bold</p></body>');

BR,

Tiago

IvanAlonsoBes
Explorer

Hi

I needed this for adobe fragments in the output scenario.

Here we are rendering some texts in a text configured as footer for master page (manage my texts app) in footer area of the master page template form.

We added something like this sample code in the initialize event of a rich text field using javascript:

// gather data from context for footer

var lv_data = xfa.resolveNode("$record.FormMaster.Footer.FooterBlock1Text").value;

//this.rawValue = "test"+lv_data;

// render in html into a rich text text field this.value.exData.loadXML('http://www.w3.org/1999/xhtml" xmlns:xfa="'+lv_data+'http://www.xfa.org/schema/xfa-data/1.0/">'+lv_data+'>');

or in one line:

this.value.exData.loadXML('http://www.w3.org/1999/xhtml" xmlns:xfa="'+$record.FormMaster.Footer.FooterBlock1Text.value+'http://www.xfa.org/schema/xfa-data/1.0/">'+$reco...

Our context is from root node navigate to FormMaster then Footer then FooterBlock1Text ($record.FormMaster.Footer.FooterBlock1Text)

Regarding output carry returns are skipped and you will need to add <br/> to each line in the manage text app text

For bold characters as stated by Thomas use <b> text </b>

Answers (2)

Answers (2)

Former Member
0 Kudos

Please help

         I have the same requirement, The data is gathering from web dynpro component in rich text format and I want to display it on my PDF.

        But the problem is that, The data which is to be display are coming from table having a line type tdline.So how can I decode such large number of data into base64 format and show it on my PDF....

        Please suggest..........Its very important and urgent for us, we not able to handle this issue and now it becomes so critical.

Regards,

Mandar Gavkar

Former Member
0 Kudos

hi guys,

i have tried your solution for the same problem but i got a script error as below (just remove the dot)

accessor 'base64.Base64.decode("<.b> BOLD <./b>")' is unknown.

can anyone help me on this?

thanks in advance!

maria

0 Kudos

Hello Maria,

perhaps your routine/variable isn't on the correct place in scripting. Even then it wouldn't work, because the string is not in base64-Format.

By trying the solution of the collegues above I found out, that it is not necessary to encode ABAP-xhtml in base64 and to decode it in the form (I had some problems with base64 in special texts, so I want to leave out this en-/decoding).

Tiago gives the short way too: Just embrace your ABAP-xhtml-string with the body-Tags Tiago mentioned. That works very well.

So I wrote the small scripts (thanks to Sebastian because of the check to "undefned") to the Rich Text fields in my form:

---

this.value.exData.loadXML(textconv.TC.makexml(this.rawValue));

---

I put the called routine/variable textconv.TC.makexml() in the hierarchie as variable (use popup menu "Insert ScriptObject" to insert the variable named textconv) with the following code:

---

var TC =

return xmlstr;

}

}

---

With this scripts, the allowed XHTML-Tags in the ABAP-string are interpreted in the correct way.

Regards

Raphael