How do the <p:editor> of the first faces escape the special characters typed by the user before saving them?

Asked

Viewed 640 times

6

I am using the primefaces component. My problem is that it is recording the accents that the user type into the text without doing the proper Escaping HTML. There’s a way to change this so he knows that the letter is an accent and needs to perform the proper Escaping HTML?

Below follows the code:

<p:editor id="corpoEmail" widgetVar="editorWidget" value="#{corpoEmailControl.corpoEmail}" width="700"  maxlength="2000"  />
  • You know that not everything the user can type is in the ASCII table, right? Are you sure you didn’t mean UTF-8 or Unicode?

  • I wish instead of him recording the accent records the asciii code. Example: the user types gas and he records g&aacute;s I will use this text to send an email, if I let the accent the browser of the person who receives this email will not recognize the accent.

  • Or whatever you want him to record g&acute;s instead of gás?

  • Yes, as I said this text will be sent in the body of the email.

  • Okay, but in this case you have to agree that what you want is to escape the characters that are not in the 7-bit ASCII/ANSI table. This is something very different from "do not write ASCII code".

  • I edited the question to be clearer, I hope you agree with my edition.

  • Okay. I just hope I get the answer. I’m looking on the internet.

  • I’m thinking about replacing the string in every possible accent.

  • Guys I ended up using this class Stringescapeutils the problem that it converts everything up to html tags.

  • @Renatoromão, it would be interesting to post as an answer how you solved the problem

Show 5 more comments

1 answer

1

When saving the field to the database, use the Stringescapeutils of Apache Commons Lang:

import org.apache.commons.lang3.StringEscapeUtils;

// ...

String corpoEmailEscapado = StringEscapeUtils.escapeHtml4(corpoEmail);

Browser other questions tagged

You are not signed in. Login or sign up in order to post.