Problem:
We have a Java web application based on Apache MyFaces Trinidad. We encounter some problems when trying to partially submit (i.e.: via Ajax) the form, when the field contains some special characters, such as Ñ, á, etc.
When we write a value similar to camiónin a text field, the resulting message Hola cami(it misses the special char and the next one).
The application server on which we run our code is IBM WebSphere AS 7.0.
This behavior is observed in the browsers IExplorer and Firefox, they all run from Windows XP Professional (Spanish version).
Key snippets of code :
UPDATE: Based on lkdganswer (thanks), I updated the JSP and subsequent HTML snippets.
JSP Page Code:
<%@page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
<%@ taglib uri="http://myfaces.apache.org/trinidad" prefix="tr" %>
<%@ taglib uri="http://myfaces.apache.org/trinidad/html" prefix="trh" %>
<f:view>
<tr:document>
<trh:head title="Prueba de AJAX con todas las Cabeceras">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
</trh:head>
<tr:form>
<tr:panelHorizontalLayout halign="left">
<f:facet name="separator">
<tr:spacer width="10" height="5"/>
</f:facet>
<tr:inputText id="elCampo" label="Your name" value="#{commandButtonBean.name}"
requiredMessageDetail="Name is required"
/>
<tr:commandButton id="sayHello" text="Say Hello"
partialSubmit="true"
action="#{commandButtonBean.sayHello}"
/>
</tr:panelHorizontalLayout>
<tr:spacer height="15px"/>
<tr:outputText value="#{commandButtonBean.message}" partialTriggers="sayHello"
inlineStyle="font-weight: bold;"/>
</tr:form>
</tr:document>
</f:view>
This is the result of HTML output (some blank lines removed):
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html dir="ltr" lang="es-ES">
<head>
<meta name="generator" content="Apache MyFaces Trinidad">
<link rel="stylesheet" charset="UTF-8" type="text/css" href="/ModuloTrinidadPilotoWeb/adf/styles/cache/bigfont-desktop-nur72r-ltr-gecko.css">
</head>
<body onload="_checkLoad()" onunload="_checkUnload(event)"><script type="text/javascript">var _AdfWindowOpenError='Se ha detectado un bloqueo de ventana emergente en el explorador. Estos bloqueos interfieren con el funcionamiento de esta aplicación. Desactívelo o permita elementos emergentes desde esta dirección.';</script><script type="text/javascript" src="/ModuloTrinidadPilotoWeb/adf/jsLibs/Common1_2_10.js"></script><div id="tr_pprBlockingDiv" onclick="return _pprConsumeClick(event);" style="position:absolute;left:0;top:0;width:0;height:0;cursor:wait;" onkeydown="return false;" onkeyup="return false;" onmousedown="return false;" onmouseup="return false;" onkeypress="return false;"></div><a name="top"></a>
<noscript>Esta página utiliza JavaScript y necesita un explorador activado para JavaScript. Su explorador no está activado para JavaScript.</noscript>
<head>
<title>Prueba de AJAX con todas las Cabeceras</title>
<meta name="generator" content="Apache MyFaces Trinidad">
<link rel="stylesheet" charset="UTF-8" type="text/css" href="/ModuloTrinidadPilotoWeb/adf/styles/cache/bigfont-desktop-nur72r-ltr-gecko.css">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
</head>
<form id="j_id_jsp_1876237926_3" name="j_id_jsp_1876237926_3" style="margin:0px" method="POST" onkeypress="return _submitOnEnter(event,'j_id_jsp_1876237926_3');" action="/ModuloTrinidadPilotoWeb/jsp/sgtc/pruebaAjax2.faces"><table cellpadding="0" cellspacing="0" border="0" summary=""><tr>
<td><table id="elCampo__xc_" class="af_inputText" cellpadding="0" cellspacing="0" border="0" summary=""><tr>
<td class="af_inputText_label" nowrap><span id="elCampo::icon" style="display:none;"><a name="_msgAnc_elCampo" title="Error" class="AFErrorIconStyle">X</a></span> <label for="elCampo">Your name</label></td>
<td valign="top" nowrap class="AFContentCell"><input id="elCampo" name="elCampo" class="af_inputText_content" size="30" type="text"></td>
</tr><tr>
<td></td>
<td class="AFComponentMessageCell"><span id="elCampo::msg" class="OraInlineErrorText"></span></td>
</tr></table></td>
<td><img src="/ModuloTrinidadPilotoWeb/adf/images/t.gif" alt="" width="10" height="5"></td>
<td><script type="text/javascript">var _pprUpDatemode=false;function _adfspu(f,v,e,s,o){_pprUpdateMode=true;if(!o)o=new Object();if(e)o.event=e;if(s)o.source=s;_submitPartialChange(f,v,o);}</script>
<button id="sayHello" name="sayHello" type="button" onclick="TrPage._autoSubmit('j_id_jsp_1876237926_3','sayHello',event,1);return false;" class="af_commandButton">Say Hello</button>
</td>
</tr></table><div style="margin-top:15px"></div><span id="j_id_jsp_1876237926_9" style="font-weight: bold;"></span><input type="hidden" name="org.apache.myfaces.trinidad.faces.FORM" value="j_id_jsp_1876237926_3"><span id="tr_j_id_jsp_1876237926_3_Postscript"><input type="hidden" name="javax.faces.ViewState" value="!-4fd3ee50"><script type="text/javascript">function _j_id_jsp_1876237926_3Validator(f,s){return _validateInline(f,s);}var j_id_jsp_1876237926_3_SF={};</script></span><script type="text/javascript">_submitFormCheck();</script></form>
</body>
</html>
CommandButton bean Code:
public class CommandButtonBean {
public String name;
public String message;
public String sayHello(){
message = "Hola " + name;
return "";
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
}
Of course, the command button is configured in faces-config.xml (I think this snippet doesn't matter).
Attempted correction:
- We checked the encoding of the encoding at different levels (application, JVM, etc.). It seems to be aligned between different layers.
In addition, we included the following context parameter in web.xml:
<context-param>
<param-name>PARAMETER_ENCODING</param-name>
<param-value>UTF-8</param-value>
</context-param>
We registered what the value is as an argument
setName, because if it were a mistake in writing the answer. the value passed is already incorrect.
-,
UTF-8 (
, ).
,
.
,
partialSubmit
.
,
(
).
, POST, , Ajax, .
, , :
- ?
.