How to allow UTF-8 data in request received from Facelets page - jsf

I am using JBoss AS 7. I created a Facelets page which is bound to a managed bean. I have JSF input text field in my page. If I write some special characters in input text field and submit the page, then it send a request to server. But special characters are already converted to some other characters. I added UTF-8 support tag in Facelets page, but I am still not getting UTF-8 data on server side. Do I need to add some settings on JBoss server so that it can accept UTF-8 data?
i Added a simple Text field
<h:inputText value="#{myBean.value}" />
and wrote text like this
"“ ©” ‘with special character’ — » É €"
i added a breakpoint on server and examined the value and i am getting something like this
â éâ âÂÂwith special characterâ â û àâ¬
I don't know how to get actual value on the server side

Related

PrimeFaces p:textEditor component - readOnly with format

I am using PrimeFaces 6.0.15 and JSF 2.2. I am currently using the component p:textEditor to allow the user to format text (bold, italics, etc.) For example, if I have bolde and underline content, in the DB it would be stored as: <p><strong><u>TEST</u></strong></p>.
On the edit mode of my application, I pull the data from the database and because the format is persisted in the DB, it automatically shows the content bolde and underlined. But is there a read only version of the text editor such as but with the textEditor formatting functionality?
Since what is stored on the DB is pure HTML, I tried doing something like:
<h:panelGroup>#{bean.description}</h:panelGroup>
But it displayed this: <p><strong><u>TITLE</u></strong></p>
How could I display the content so that it shows the formatted content?
To enable HTML insertion without escaping, just set the escape attribute of h:outputText to false:
<h:outputText value="#{bean.description}" escape="false" />
Note: Presenting the HTML input of user A to user B may raise security issues
(see: cross site request forgery).

JSF request parameter encoding struggles

On our web application we've got different forms which nearly all have a encoding problem on text input fields.
When the input includes special characters like a Ͳ the value in the Bean of the site shows a question mark. Umlauts and accents eg. get to the Bean without any problem.
The sent request tracked with firebug looks fine. The header shows an UTF-8 charset:
application/x-www-form-urlencoded; charset=UTF-8
And the request-parameter gets displayed right:
formInputPanel:comment hello Ͳ
I googled a lot and most of the solutions I found tell me to implement a filter via the web.xml to set the right encoding for the request. The problem is when the filter is called the encoding is set right to UTF-8 but the parameter is already broken and shows hello ?
I also added following to lines to the system-properties of the JBoss without any results:
<property name="org.apache.catalina.connector.URI_ENCODING" value="UTF-8"/>
<property name="org.apache.catalina.connector.USE_BODY_ENCODING_FOR_QUERY_STRING" value="true"/>
This problem occurs on all pages except the login page. There the parameters get passed well to the Bean. The login page is implemented via a JSP-Page and a LoginServlet.
Maybe someone can give me a hint where else I can search for the problem.
Problem was solved through adapting the connection-url of the database connection in the JBoss configuration to:
jdbc:mysql://servername:3306/dbname?characterEncoding=UTF-8&useUnicode=true.
The encoding in the console output of the IDE wasn't UTF-8 encoded. So the request parameter were shown in the wrong encoding but the value was correct.

Question marks instead of Unicode characters with resource bundle in view

I use Primefaces 3.5 + Lifaray 6.2.
I need some internalization in my app.
I use Language_en_US.properties file and others for string resources.
In backbean I use ResourceBundle.getBundle and it's working propertly.
But in view I use
<p:outputLabel value="#{i18n['server-address']}"/>
And with Cyrillic i always got question marks on page
?????? ??????
It's in page code already as question marks, so it's not a browser problem.
If I use ResourceBundle.getBundle directly
<p:outputLabel value="#{adminBean.getString('main')}"/>
then I got Cyrillic.
Is there any way to use i18n without bean?
Liferay expects the resource bundles to be encoded in UTF-8 (unlike PropertyResourceBundle in plain Java, which uses ISO-8859-1).
Check encoding of you Language_ru_RU.properties file - most likely it is not UTF-8. That would explain that ResourceBundle.getBundle works correctly, while #{i18n['server-address']} doesn't.
While it's a deviation from the standard, UTF-8 encoding is quite comfortable, as there's no need for character escaping.
See Localizing JSF Portlets in Liferay documentation.

Set request character encoding of JSF input submitted values to UTF-8 in GlassFish

I have a problem with the values inserted in all my <h:inputText> fields. Some characters are not encoded in the right way. E.g. if I put ciò in the input field I get ciò.
How can I allow a user to insert text with those characters and save them correctly? The problem in not in the DB encoding since I already have the wrong value before inserting it in the DB.
I'm using JSF 2 with Facelets and GlassFish as application server.
You need to tell Glassfish to use UTF-8 to decode paramters instead of (default) ISO 8859-1. Add the following entry to the <glassfish-web-app> of your /WEB-INF/glassfish-web.xml file:
<parameter-encoding default-charset="UTF-8" />

Facelet does not convert formatted currency correctly

I have the follwing code inside a facelet page:
<h:inputNumber value="bean.property">
<f:convertNumber type="currency" />
</h:inputNumber
The converter is because there can be a kind of default value inside the input field, which comes from the bean property. Everything is rendered correctly. The value inside the input field is rendered with an "€" character (e.g. "1.453 €".
When I submit the form there comes an error up:
"nameOfInputField" konnte nicht als ein Geldbetrag erkannt werden '304,00 â¬'
In english it is some like:
"nameOfInputField" could not be regognized as an amount of money '304,00 â¬'
Please have a look at the "€" character. It seems to be printed as "â¬". While it was rendered correctly before submitting the form, now it looks like "â¬" inside the error message and inside the input field.
All pages are encoded in UTF-8.
What is the reason for this error?
How can fix it?
Thanks in advance
â¬
This is typical for the € from an original UTF-8 source which is incorrectly been decoded using ISO-8859-1. Here's a small snippet which demonstrates that:
System.out.println(new String("€".getBytes("UTF-8"), "ISO-8859-1"));
All pages are encoded in UTF-8.
You're likely talking about response encoding. You need to set the request encoding as well.
To set the encoding for GET requests (basically: URI encoding), you need to consult the appserver specific documentation. As it's unclear which one you're using, here's a Tomcat targeted example: <Connector URIEncoding="UTF-8" />. To set the encoding for POST requests, you need to create a simple filter which does request.setCharacterEncoding("UTF-8") if it is null. More background information and hints can be found in this article.
Put this ontop of your facelets page:
<?xml version="1.0" encoding="UTF-8" ?>
It will instruct the facelets parser.

Resources