Sunday, August 8, 2010

JBoss Seam UTF-8 encoding

UTF-8 encoding of JBoss Seam can cause a lot of the problem. I went through of everything that's probably possible cases, and try to show you how to properly configure Seam to UTF-8 to work properly.
At the beginning of some of the tools used to work. The most important is probably installed Eclipse with JBoss Tools. Next ... Well no more, Eclipse itself is enough :-)
Okay, so yes, there are several cases to consider:
  1. We want to do a connection to the database in UTF-8
  2. We want to display a static XHTML in UTF-8
  3. We want to have URLs in UTF-8
Let us take the first point. The case is quite simple, open the file hibernate-console.properties and set the URL so that it is in UTF-8. If you are using a PostgreSQL database is a matter of even more simplified, because the default is UTF. Remember that a database was created in UTF too.
Second point.
Here you can help Eclipse. To display a static XHTML in JavaServer Faces (UTF-8), which is built on JBoss Seam, you must file with the JSF is to encode to UTF-8. Now you can put this file in UTF. Oh, one more thing - how to encode in Eclipse? It's easy, from the main menu click File, then Properties, from section Text file properties choose Other and UTF-8 select. Click Apply and OK. Oh, and do it with an open file that you want to encode.
And the last, URL encoding in UTF-8. Here are more combinations. Open a file components.xml and add tag:
<web:character-encoding-filter encoding="UTF-8" override-client="true" url-pattern="*.html" />
Instead, *. html, use your own pattern (default is *. seam). I use the JBoss application server, and it is for this server will further tip. One must set the connector support the processing of URLs with UTF. Generally, this is a setting for Tomcat, so if you have another application server, you probably also will use Tomcat, and the configuration process is similar. Open the file server.xml located in $JBOSS_HOME / server / (your server configuration) / deploy / jbossweb.sar.
See for this part of the file:

<Connector protocol="HTTP/1.1" SSLEnabled="true"
   port="8443" address="${jboss.bind.address}"
   enableLookups="true" disableUploadTimeout="true"
   useBodyEncodingForURI="true" URIEncoding="UTF-8"
   scheme="https" secure="true" clientAuth="false"
   sslProtocol = "TLS" SSLCertificateKeyFile="${jboss.server.home.dir}/conf/459659.crt"
   SSLCertificateFile="${jboss.server.home.dir}/conf/privatekey.pem" />

In your file is certainly a little different this entry, but the two most important fields that you need to add are those that have mark red. Add them, and restart the JBoss AS.

IT Systems Java Developers

No comments:

Post a Comment