4 Replies Latest reply on Aug 28, 2008 1:54 PM by rajshake

    How to change characterEncoding?

    rajshake

      Ajax response always seems to come back with "utf-8" encoding.
      I would like to use iso-8859-1 encoding for all the requests (including Ajax), as that is the charset used in the backend database.
      Is there a way to force a different character Encoding when sending AJAX requests?

        • 1. Re: How to change characterEncoding?
          rajshake

          bump.

          • 2. Re: How to change characterEncoding?

            utf-8 is required by client site library is used to parse XML. So, no way to change.

            • 3. Re: How to change characterEncoding?
              rajshake

              I have to use iso-8859-1 encoding, I cannot move to utf-8 until our database server's charset is changed.
              With iso-8859-1 encoding, we have been successful in allowing users to enter Non-ASCII characters through browser and save it in the database.
              Now the real issue is, let's say I have a inputText, where I enter a Euro symbol €. If I have a h:selectBooleanCheckbox, and add a4j support so it reRenders the text box, the Euro symbol looks messed.

              Here is a very simple usecase of what I am taling about: Looking through "LiveHttpHeaders", I notice that the contentType is set to "utf-8" in the response, as soon as I clicked on the checkbox (Ajax Request). And I am "guessing" that the Euro character getting distorted is becaused of this.

              Is there any way of avoiding or working around this issue?



              <!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:h="http://java.sun.com/jsf/html"
              xmlns:f="http://java.sun.com/jsf/core"
              xmlns:t="http://myfaces.apache.org/tomahawk"
              xmlns:a4j="https://ajax4jsf.dev.java.net/ajax"
              xmlns:rich="http://richfaces.ajax4jsf.org/rich"
              >



              <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />


              <f:view>
              <h:form id="mainForm">
              <h:outputText value="Enter char: " />
              <h:inputText id="inpText" styleClass="formtextbx" value="#{charsetBean.foo}" />


              <h:outputText id="fooText" value="#{charsetBean.foo}" />


              <h:selectBooleanCheckbox id="courtesyCase" value="#{charsetBean.courtesyCase}" style="vertical-align: bottom">
              <a4j:support event="onclick" reRender="inpText" />
              </h:selectBooleanCheckbox>



              <a4j:commandLink action="#{charsetBean.testAction}" value="a4j:commandLink" reRender="inpText, fooText">
              </a4j:commandLink>
              </h:form>
              </f:view>



              Backing Bean:

              import org.jboss.seam.ScopeType;
              import org.jboss.seam.annotations.Name;
              import org.jboss.seam.annotations.Scope;

              @Scope(ScopeType.SESSION)
              @Name("charsetBean")
              public class CharsetBean extends BaseBean implements java.io.Serializable{

              public String foo;
              public boolean courtesyCase = false;

              public boolean isCourtesyCase() {
              return courtesyCase;
              }

              public void setCourtesyCase(boolean courtesyCase) {
              this.courtesyCase = courtesyCase;
              }

              public String getFoo() {
              return foo;
              }

              public void setFoo(String foo) {
              this.foo = foo;
              }

              public void testAction(){
              System.out.println("foo: " + foo);

              }

              }


              • 4. Re: How to change characterEncoding?
                rajshake


                Any suggestions, anyone? Sergey?