0

I set value from queryString into managedBean's property with the help of <f:viewParam>.If I print the value of property it works properly for normal character. But when queryString contain accented characters, after set value into managedBean's property if I print value of that property , the accented characters not display properly.

.xhtml code snippet are given below :

<f:metadata>
<f:viewParam id="requestString" name="requestString" value="#{aproveOrDenyController.requestString}" />
</f:metadata>

ManagedBean:

@ManagedBean(name = "aproveOrDenyController")
@ViewScoped
public class AproveOrDenyController extends BaseWebController implements Serializable 
{
private String requestString;


public final String getRequestString() {
    return requestString;
}
public final void setRequestString(String requestString) {
    this.requestString = requestString;
    System.out.println(this.requestString);
}
}

If query string contain...&requestString=abcdefgh&..... then it prints abcdefgh correctly. But if query string contain ...&requestString=SociétéGéniale&.. then it prints SociétéGéniale. But I want SociétéGéniale. Any pointer will be very helpful to me.

Edit-1 Generated error :

19:52:49,594 ERROR [org.jboss.as.server] JBAS015956: Caught exception during boot: org.jboss.as.controller.persistence.ConfigurationPersistenceException: JBAS014676: Failed to parse configuration
at org.jboss.as.controller.persistence.XmlConfigurationPersister.load(XmlConfigurationPersister.java:141) [jboss-as-controller-7.1.1.Final.jar:7.1.1.Final]
at org.jboss.as.server.ServerService.boot(ServerService.java:266) [jboss-as-server-7.1.1.Final.jar:7.1.1.Final]
at org.jboss.as.controller.AbstractControllerService$1.run(AbstractControllerService.java:155) [jboss-as-controller-7.1.1.Final.jar:7.1.1.Final]
at java.lang.Thread.run(Unknown Source) [rt.jar:1.7.0_10]
Caused by: javax.xml.stream.XMLStreamException: ParseError at [row,col]:[8,5]
Message: JBAS014789: Unexpected element '{urn:jboss:domain:1.2}extensions' encountered
at org.jboss.as.controller.parsing.ParseUtils.unexpectedElement(ParseUtils.java:85) [jboss-as-controller-7.1.1.Final.jar:7.1.1.Final]
at org.jboss.as.server.parsing.StandaloneXml.readServerElement_1_1(StandaloneXml.java:351) [jboss-as-server-7.1.1.Final.jar:7.1.1.Final]
at org.jboss.as.server.parsing.StandaloneXml.readElement(StandaloneXml.java:127) [jboss-as-server-7.1.1.Final.jar:7.1.1.Final]
at org.jboss.as.server.parsing.StandaloneXml.readElement(StandaloneXml.java:100) [jboss-as-server-7.1.1.Final.jar:7.1.1.Final]
at org.jboss.staxmapper.XMLMapperImpl.processNested(XMLMapperImpl.java:110) [staxmapper-1.1.0.Final.jar:1.1.0.Final]
at org.jboss.staxmapper.XMLMapperImpl.parseDocument(XMLMapperImpl.java:69) [staxmapper-1.1.0.Final.jar:1.1.0.Final]
at org.jboss.as.controller.persistence.XmlConfigurationPersister.load(XmlConfigurationPersister.java:133) [jboss-as-controller-7.1.1.Final.jar:7.1.1.Final]
... 3 more
Diganta
  • 671
  • 3
  • 11
  • 27
  • Are the values still garbled when you debug and inspect the `requestString` ? I suspect the console character set might be playing spoilsport here. – Santosh Jul 16 '13 at 10:46

2 Answers2

2

Decoding of URI query strings is managed by the servletcontainer (Tomcat, JBoss, Glassfish, etc). This has often a default of ISO-8859-1. You need to configure the query string decoding charset in the servletcontainer to be the same as used by JSF/Facelets to encode the responses and POST requests, which is by default UTF-8. In your case the query string encoding is apparently using the default of ISO-8859-1. The é character exist in UTF-8 encoding of two bytes 0xC3 and 0xA9 which each in turn represent in ISO-8859-1 encoding the characters à and ©, exactly the characters you're seeing. This confirms that ISO-8859-1 is incorrectly been used instead of UTF-8.

As you're using JBoss AS, you need to add the following entry to <server> of JBoss' /standalone/configuration/standalone.xml, between <extensions> and <management> in:

<system-properties>
    <property name="org.apache.catalina.connector.USE_BODY_ENCODING_FOR_QUERY_STRING" value="true" />
</system-properties>

This will instruct JBoss to use ServletRequest#getCharacterEncoding() to decode query string, instead of the default encoding of ISO-8859-1. If that still doesn't work (which may happen when you're using PrimeFaces), then you need in addition to the above configuration entry to explicitly set the character encoding to UTF-8 as well using a servlet filter. This part is answered in solution 1 of Unicode input retrieved via PrimeFaces input components become corrupted.

Another possible cause is that the output destination where the System.out.println() ends up in is not using UTF-8 to present the printed characters. This is in turn completely unrelated to JSF and the servletcontainer. You also didn't tell anything about the context the System.out.println() is running in, so it's hard to give a suited answer here as well. But if it were for example Eclipse, then you could configure it by setting Window > Preferences > General > Workspace > Text File Encoding to UTF-8.

See also:

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • Thank you @BalusC for reply: I have tried to add given `` configuration into JBoss's standalone.xml file. But error generated during server start. – Diganta Jul 16 '13 at 14:13
  • It's helpful if you tell in detail about the error instead of overgeneralizing it as "an error". The error itself namely contains the answer to the concete problem. Failing to interpret an error doesn't mean that the error should be ignored. – BalusC Jul 16 '13 at 14:23
  • You need to put `` between `` and `` in. – BalusC Jul 16 '13 at 14:32
  • problem is still remain. Output `20:04:46,685 INFO [stdout] (http-localhost-127.0.0.1-8080-1) ::::::::::::::::::::::::::Avinaba-Bandhu-MAJUMDER-has-requested-to-create-customer-Société-Génial-In-ADB.-` – Diganta Jul 16 '13 at 14:36
  • Then just advance to the next paragraph in the answer. – BalusC Jul 16 '13 at 14:37
0

In integration to the previous answer you could try adding:

<system-properties>
    <property name="org.apache.catalina.connector.URI_ENCODING" value="UTF-8"/>
    <property name="org.apache.catalina.connector.USE_BODY_ENCODING_FOR_QUERY_STRING" value="true" />
</system-properties>

to the standalone.xml configuration file.

giusc
  • 103
  • 3