0

This is similar to question about charset validation except that some characters (e.g. "żźć") are shown as HTML entities ("żźć") after submit. Strange thing is things like "&" save as "&".

I've already tried Spring's CharacterEncodingFilter and Connector on Tomcat side but that didn't seem to help at all. Database encoding doesn't seem to be a problem as my form is working fine when used with AJAX request and a session bean (as opposed to normal submit and request scope).

Here is a part of my 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:p="http://primefaces.org/ui"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      >
  <h:body>
   <ui:composition template="/tpls/main-layout.xhtml">
   <ui:define name="content">
    <h:form>
    ...
     <p:commandButton value="#{i18n.msg('_Save')}"
      action="view" actionListener="#{readerController.save}" ajax="false" />
    ...
     <p:panelGrid>
      <p:row>
       <p:column><h:outputLabel for="lastName" value="#{i18n.msg('Reader.lastName')}" /></p:column>
       <p:column><p:inputText id="lastName" value="#{readerController.currentReader.lastName}" required="true">
        <p:ajax update="msg-lastName" event="change" />
        <f:validateRegex pattern="#{applicationConfiguration.nameValidationPattern}" />
        <f:validateLength maximum="50" />
       </p:inputText></p:column>
       <p:column><p:message for="lastName" id="msg-lastName" /></p:column>
      </p:row>
      ...
     </p:panelGrid>
    </h:form>
  </ui:define>
  </ui:composition>
</h:body>
</html>

EDIT: Just as a clarification - you can replace things like #{i18n.msg('_Save')} with Save and #{applicationConfiguration.nameValidationPattern} with e.g. [^0-9].

Community
  • 1
  • 1
Nux
  • 9,276
  • 5
  • 59
  • 72
  • Have you tried with in the ? – Adrian Mitev Jul 17 '12 at 14:07
  • Yes I had that previously and tried `f:view` too. Unfortunately none of them help. – Nux Jul 17 '12 at 14:38
  • Of course it won't help, the meta http-equiv head is ignored on HTTP requests. The f:view encoding only controls the response encoding which defaults to UTF-8 already. – BalusC Jul 17 '12 at 14:43
  • I was trying out the approach "every logical way seem to have failed - let's try everything else" ;-). – Nux Jul 17 '12 at 15:39

1 Answers1

0

Totally magic.

I was using this to go to my edit view:

<p:commandButton action="#{readerController.edit(list.id)}" title="#{i18n.msg('_Edit')}" icon="ui-icon-gear" />

And this to submit:

<p:commandButton ajax="false" value="#{i18n.msg('_Save')}" action="view" actionListener="#{readerController.save}" />

And encoding doesn't work right.

Using this to go to edit view:

<p:commandButton ajax="false" action="#{readerController.edit(list.id)}" title="#{i18n.msg('_Edit')}" icon="ui-icon-gear" />

And the same to submit and encoding work fine... To be more exact using ajax="false" or ajax="true" on both ends work.

Go figure.

Edit: Actually it was the above and CharacterEncodingFilter from Corrupted characters redisplayed in inputs after submitting form.

Community
  • 1
  • 1
Nux
  • 9,276
  • 5
  • 59
  • 72