0

I am developing web app using PrimeFaces and postgresql.

I have some forms which are related to the database. The project need to work with cyrillic characters. So when I fill some characters in the text field the cyrillic is ok but when I click the button and the form reloads I see some garbage characters.

I am using tomcat as a server and I am developing the app locally on my computer.

Here my faces-config.xml file

<?xml version="1.0" encoding="UTF-8"?>
<faces-config
    xmlns="http://xmlns.jcp.org/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-facesconfig_2_2.xsd"
    version="2.2">
 <application>
      <message-bundle>
        bg_messages
      </message-bundle>
      <locale-config>
        <default-locale>bg_BG</default-locale>
        <supported-locale>bg</supported-locale>
      </locale-config>

     </application>
</faces-config>

On the xhtml pages I have

<?xml version="1.0" encoding="UTF-8"?>

The database is OK because when I try to add some cyrillic characters manually they are working. I also have some autocomplete in one of the pages and when I manually add some data in cyrillic in the database and then try the autocomplete it is working fine.

Here is one of my pages:

<h:body>
    <h1>Вход</h1>
    <h:form>

        <h:outputText value="Потребителско име: " />
        <p:inputText value="#{USER.username}" />

        <br />
        <br />
        <h:outputText value="Парола: " />
        <p:password id="nonFeedback" value="#{USER.password}" />

        <br />
        <br />


        <h:commandButton value="Вход" action="#{USER.login}" target="_self" />



    </h:form>

</h:body>

So when I put some cyrillic data into

<p:inputText value="#{USER.username}" />

and then click the button I get garbage strange characters. It's the same with my register form. When I fill the data into the form and submit it again the strange characters are showing and they are stored in the database instead of the real proper data.

Here my register form:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:p="http://primefaces.org/ui">

<h:head>

 <title>Home | E-Shopper</title>
    <h:outputStylesheet library="css" name="bootstrap.min.css" />
    <h:outputStylesheet library="css" name="font-awesome.min.css" />
    <h:outputStylesheet library="css" name="prettyPhoto.css" />
    <h:outputStylesheet library="css" name="price-range.css" />
    <h:outputStylesheet library="css" name="animate.css" />
    <h:outputStylesheet library="css" name="main.css" />
    <h:outputStylesheet library="css" name="responsive.css" />



    <h:outputScript library="js" name="bootstrap.min.js" />
    <h:outputScript library="js" name="jquery.scrollUp.min.js" />
    <h:outputScript library="js" name="price-range.js" />
    <h:outputScript library="js" name="jquery.prettyPhoto.js" />
    <h:outputScript library="js" name="main.js" />






    <h:link rel="shortcut icon" href="images/ico/favicon.ico"></h:link>
   <h:link rel="apple-touch-icon-precomposed" sizes="144x144" href="images/ico/apple-touch-icon-144-precomposed.png"></h:link>
   <h:link rel="apple-touch-icon-precomposed" sizes="114x114" href="images/ico/apple-touch-icon-114-precomposed.png"></h:link>
    <h:link rel="apple-touch-icon-precomposed" sizes="72x72" href="images/ico/apple-touch-icon-72-precomposed.png"></h:link>
   <h:link rel="apple-touch-icon-precomposed" href="images/ico/apple-touch-icon-57-precomposed.png"></h:link>



</h:head>
<h:body>

<div id="main_container_reg">

    <h1 class="reg_title">Регистрация</h1>


 <h:form>



<h:outputLabel styleClass="labels_reg" for="name" value="Име:  " />
<p:inputText styleClass="fields_reg" id="name" value="#{USER.name}"/>
<br/><br/>

<h:outputLabel styleClass="labels_reg" for="lastname" value="Фамилия:  " />
<p:inputText styleClass="fields_reg" id="lastname" value="#{USER.surname}" />
<br/><br/>
<h:outputLabel styleClass="labels_reg" for="username" value="Потребителско име: * " />
<p:inputText styleClass="fields_reg" id="username" required="true" value="#{USER.username}"  />


    <h:panelGrid styleClass="pass_reg" columns="2" id="matchGrid" >                  
        <h:outputLabel styleClass="labels_reg" for="password" value="Парола: *" />
        <p:password styleClass="fields_reg" id="password" match="pass_conf" label="Парола" required="true" value="#{USER.password}" />

        <h:outputLabel styleClass="labels_reg" for="pass_conf" value="Потвърди парола: *" />
        <p:password styleClass="fields_reg" id="pass_conf" value="EditorBean" label="полето за потвърждение" required="true" />
    </h:panelGrid>

 <br/>
<h:outputLabel styleClass="labels_reg" for="email" value="Електронна поща: * " />
<p:inputText styleClass="fields_reg" id="email" required="true" value="#{USER.email}" />
 <br/><br/>
<h:outputLabel styleClass="labels_reg" for="phone" value="Телефон: " />
<p:inputText styleClass="fields_reg" id="phone" value="#{USER.phone}"  />


<h:panelGrid styleClass="user_type" columns="2" style="margin-bottom:10px" >
        <p:outputLabel  value="Тип потребител" />
        <br/>
   <p:selectOneRadio id="data" binding="#{yesOrNo}" required="true" value="No">
   <f:selectItem itemValue="No"  itemLabel="Частно Лице" />
   <f:selectItem itemValue="Yes" itemLabel="Фирма" />
   <p:ajax update="campany_name" />
   <p:ajax update="city" />
   <p:ajax update="street" /> 
   <p:ajax update="street_number" />
   <p:ajax update="zip" />
    <p:ajax update="upload" />
</p:selectOneRadio>

    </h:panelGrid>


<h:outputLabel styleClass="labels_reg" for="company_name" value="Име на фирма: "  />
<p:inputText styleClass="fields_reg" value="#{USER.companyName}"  id="campany_name" disabled="#{yesOrNo.value != 'Yes'}" />
 <br/> <br/>

<h3 style="margin:0 0 0 15px;">Адрес: </h3>
<br/>
<h:outputLabel  styleClass="labels_reg" for="city" value="Град: "  />
<p:inputText styleClass="fields_reg" value="#{USER.city}" id="city" disabled="#{yesOrNo.value != 'Yes'}" />
<br/><br/>
<h:outputLabel styleClass="labels_reg" for="street" value="Улица: "  />
<p:inputText styleClass="fields_reg" value="#{USER.street}" id="street" disabled="#{yesOrNo.value != 'Yes'}" />
<br/><br/>
<h:outputLabel styleClass="labels_reg" for="street_number" value="Номер на Улица: "  />
<p:inputText styleClass="fields_reg" value="#{USER.streetNumber}"  id="street_number" disabled="#{yesOrNo.value != 'Yes'}" />
<br/><br/>
<h:outputLabel styleClass="labels_reg" for="zip" value="Пощенски код: "  />
<p:inputText styleClass="fields_reg" value="#{USER.zip}" id="zip" disabled="#{yesOrNo.value != 'Yes'}" />

<br/> <br/>

<p:messages id="messages" showDetail="true" autoUpdate="true" />
        <p:fileUpload fileUploadListener="#{USER.getImageURL}"
            allowTypes="/(\.|\/)(gif|jpe?g|png)$/" sizeLimit="100000"
            description="Select Images" disabled="#{yesOrNo.value != 'Yes'}"
            id="upload" />

        <br />
        <br />
        <h:form enctype="multipart/form-data">
            <p:growl id="messages" showDetail="true" />





            <p:commandButton styleClass="reg_button"  action="#{USER.addUser}" value="Регистрация" ajax="false"
                disabled="false" />
            <br />
            <br />
        </h:form>

    </h:form>

</div>


</h:body>
</html>
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Berchev
  • 87
  • 4
  • 12
  • That's the result : ???µ???µ???µ?????? when do System.out.println(user.getName()); and fill cyrillic characters in the name field – Berchev May 09 '15 at 17:57
  • OK, so I have made the changes to the workspace to UTF-8 and from the project properties but still I am not getting the cyrillic content and I get the following warning V 09, 2015 9:05:06 PM org.apache.tomcat.util.digester.SetPropertiesRule begin WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:Hotels' did not find a matching property. But there is a change also in the output now in the console I get едÑвÑÐµÐ²Ñ not just ????? marks, Yes I am using Eclipse Mars – Berchev May 09 '15 at 18:10
  • The content-type for register.xhtml is "text/html;charset=UTF-8" – Berchev May 09 '15 at 18:22
  • I am using Primefaces from the beginning. How can I check if there is other filter which runs before? – Berchev May 09 '15 at 18:30
  • Oh? Well, then this is applicable as duplicate http://stackoverflow.com/a/9839362, right? – BalusC May 09 '15 at 18:53
  • I think this is different. I have not updated primefaces, I am using 5.1 from the start of the project. I also use tomcat 8 not glassfish. So as I understand if I set filter or to configure the server encoding will solve the problem maybe... but I don't know where to set that filter and how to set it. In the server.xml file I have `` – Berchev May 09 '15 at 19:06
  • Just put that class in Java source folder. That Tomcat config only applies to GET requests, not POST requests (the filter does). – BalusC May 10 '15 at 06:11
  • ok, I have created new class for the encoding but I am getting error on the `@WebFilter("/*")` anotation there's what I have imported: `package encoding; import java.io.IOException; import javax.servlet.Filter; import javax.servlet.FilterChain; import javax.servlet.FilterConfig; import javax.servlet.ServletException; import javax.servlet.ServletRequest; import javax.servlet.ServletResponse;` – Berchev May 10 '15 at 08:47
  • I found the problem it was in my servlet api version, it was 2.5 and that's why there was no such annotation since they are available after version 3 as I read on the web. So I have put the right version, created the filter and now it's working like a charm. If you want just post an answer to the question so that I can mark it as the best answer. Thank you a million for the help – Berchev May 10 '15 at 09:27

0 Answers0