1

Possible Duplicate:
UTF-8 form submit in JSF is corrupting data

This is a code I wrote

    <?xml version='1.0' encoding='ISO-8859-1' ?>
<!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:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.org/ui"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
    </head>
    <body>

        <ui:composition template="../WEB-INF/templates/template.xhtml">

            <ui:define name="titleHeader">
                <h:outputText value="#{bundles.messages['message.NouveauClient']}" styleClass="titreContainer"/>
            </ui:define>

            <ui:define name="content">
                <p:growl  autoUpdate="true"/>
                <h:form>
                    <h:panelGrid columns="1" width="100%" columnClasses="top1,top2">
                        <h:panelGrid columns="2" width="80%">
                            <h:outputText value="#{bundles.messages['message.NomClient']}"/>
                            <p:inputText value="#{clientController.client.nom}" required="true"/>
                            <h:outputText value="#{bundles.messages['message.honoraire']}"/>
                            <p:inputText value="#{clientController.client.honoraire}" required="true"/>
                        </h:panelGrid >
                        <p:commandButton action="#{clientController.newClient()}" value="Valider" ajax="false"/>
                    </h:panelGrid>
                </h:form>
            </ui:define>

        </ui:composition>
    </body>
</html>

this is the code of newClient

 public String newClient() {
         serviceClient.create(getClient());
         message.info(new BundleKey("messages", "message.success"));
         return "lstClient";
    } 

the problem is that: when I put a client with name zéro it is saved in database with name zéro.

Can anyone help me find a solution to this problem

Community
  • 1
  • 1
ktaria
  • 423
  • 6
  • 16
  • 1
    You need a filter that sets the character encoding in the request, as most browsers don't set the encoding if it's UTF-8 (the default for most, if not all, browsers); on the other hand, the default in the servlet containers is ISO-8859-1. If you're using tomcat, please read this [wiki entry](http://wiki.apache.org/tomcat/FAQ/CharacterEncoding#Q3). If you're using any other web container, just copy paste the code of the filter into your codebase. – Augusto Jan 08 '13 at 15:12
  • BalusC, I saw this post, but I don't know where to put the code you put in – ktaria Jan 08 '13 at 15:19
  • 1
    @ktaria what part of creating a WebFilter you have problem with? If you don't know how to do it, read [our Servlet Filters wiki](http://stackoverflow.com/tags/servlet-filters/info). – Luiggi Mendoza Jan 08 '13 at 15:34
  • Just create the class and put it somewhere in your webapp. It's auto-registered by `@WebFilter`. You can leave the `init()` and `destroy()` implementations empty. All you need to do is probably to finetune the URL pattern in the value of `@WebFilter` annotation so that it matches all JSF requests. You could for instance use `@WebFilter({ servletNames="facesServlet"})` where `facesServlet` is the exact `` of the Faces Servlet as already registered in `web.xml`. – BalusC Jan 08 '13 at 15:38
  • @BalusC Wouldn't it be better to register the filter in the `web.xml`, just to make sure it is the first in the chain? – Elias Dorneles Jan 08 '13 at 16:16
  • @elias: it may depend on your other filters, but it wouldn't matter for this particular case as the encoding is used after the `FacesServlet` is invoked (and thus all filters are already invoked). – BalusC Jan 08 '13 at 16:18

0 Answers0