You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Rene Pirringer <re...@ciqua.com> on 2007/10/03 11:57:27 UTC

Post request encoding problem

Hi,

in the project I'm working on we have the problem that when we try to  
submit a form that contains german umlauts the string in the backing  
bean is not encoded correctly.
All our sites are in UTF-8 an in the post request the parameters are  
also send url encoded in UTF-8.
I debugged this and found out that the default encoding of post  
parameters that tomcat (5.5.x) uses is ISO-8859-1, and this is the  
reason for the wrong encoding. The only way to tell tomcat
to use UTF-8 is to set the enctype at the form tag to 'application/x- 
www-form-urlencoded;charset=UTF-8'
I have tested this with a header modify plugin with firefox that  
overrides this parameter.
Now I can add to every <h:form> tag the enctype, but it does not work  
for me, because JSF adds form tags itself when for example a  
commandLink is rendered, an then the charset is not set.

At my point of view the cleanest solution would be, to override the  
enctype that is defined in the standard-faces-config.xml of myfaces  
(I use version 1.1.5).
So is it possible to override this value?

Another solution is to write a custom renderer for the form tag. But  
I would prefer the first option.

Rene

Re: Post request encoding problem

Posted by Rene Pirringer <re...@ciqua.com>.
Hi,

thx for the hint.
I found this today by myself and it solved my problem.

Rene

On 04.10.2007, at 09:47, Michael Heinen wrote:

> What about using a Filter for setting the encoding ?
>
> public void doFilter(ServletRequest srequest, ServletResponse  
> sresponse,
> FilterChain chain)
>       throws IOException, ServletException
>   {
>    srequest.setCharacterEncoding("UTF-8");
>
>     chain.doFilter(srequest, sresponse);
>   }
>
> Michael
>
> -----Original Message-----
> From: Rene Pirringer [mailto:rene.pirringer@ciqua.com]
> Sent: Mittwoch, 3. Oktober 2007 11:57
> To: users@myfaces.apache.org
> Subject: Post request encoding problem
>
> Hi,
>
> in the project I'm working on we have the problem that when we try to
> submit a form that contains german umlauts the string in the backing
> bean is not encoded correctly.
> All our sites are in UTF-8 an in the post request the parameters are
> also send url encoded in UTF-8.
> I debugged this and found out that the default encoding of post
> parameters that tomcat (5.5.x) uses is ISO-8859-1, and this is the
> reason for the wrong encoding. The only way to tell tomcat
> to use UTF-8 is to set the enctype at the form tag to 'application/x-
> www-form-urlencoded;charset=UTF-8'
> I have tested this with a header modify plugin with firefox that
> overrides this parameter.
> Now I can add to every <h:form> tag the enctype, but it does not work
> for me, because JSF adds form tags itself when for example a
> commandLink is rendered, an then the charset is not set.
>
> At my point of view the cleanest solution would be, to override the
> enctype that is defined in the standard-faces-config.xml of myfaces
> (I use version 1.1.5).
> So is it possible to override this value?
>
> Another solution is to write a custom renderer for the form tag. But
> I would prefer the first option.
>
> Rene
>


RE: Post request encoding problem

Posted by Michael Heinen <mh...@recommind.com>.
What about using a Filter for setting the encoding ?

public void doFilter(ServletRequest srequest, ServletResponse sresponse,
FilterChain chain)
      throws IOException, ServletException
  {
   srequest.setCharacterEncoding("UTF-8");

    chain.doFilter(srequest, sresponse);
  }

Michael

-----Original Message-----
From: Rene Pirringer [mailto:rene.pirringer@ciqua.com] 
Sent: Mittwoch, 3. Oktober 2007 11:57
To: users@myfaces.apache.org
Subject: Post request encoding problem

Hi,

in the project I'm working on we have the problem that when we try to  
submit a form that contains german umlauts the string in the backing  
bean is not encoded correctly.
All our sites are in UTF-8 an in the post request the parameters are  
also send url encoded in UTF-8.
I debugged this and found out that the default encoding of post  
parameters that tomcat (5.5.x) uses is ISO-8859-1, and this is the  
reason for the wrong encoding. The only way to tell tomcat
to use UTF-8 is to set the enctype at the form tag to 'application/x- 
www-form-urlencoded;charset=UTF-8'
I have tested this with a header modify plugin with firefox that  
overrides this parameter.
Now I can add to every <h:form> tag the enctype, but it does not work  
for me, because JSF adds form tags itself when for example a  
commandLink is rendered, an then the charset is not set.

At my point of view the cleanest solution would be, to override the  
enctype that is defined in the standard-faces-config.xml of myfaces  
(I use version 1.1.5).
So is it possible to override this value?

Another solution is to write a custom renderer for the form tag. But  
I would prefer the first option.

Rene