Emoji Javaee JSF JBOSS ORACLE

Asked

Viewed 148 times

4

I have a WEB system and I was asked to put emoticons to send email.

I had some problems with the coding of the database which is Oracle and the NLS_CHARACTERSET was defined as WE8MSWIN1252. Not to change the structure of the bank I made a solution that saves the emoticons in a field of type BLOB, that is to say:

// pego esse valor e salvo no BD na coluna Tipo BLOB
String em = emoji.getBytes("UTF-8");

To redeem the value of emoji as String i do:

// BLOB formatado para string
String em = new String(getEmoji, "UTF-8"); 

If I make one System.out.printl(em) emoji usually appears on my console, but when I send this String for a value of <h:inputText/> there appears a black diamond with a ?.

I’ve been trying to solve for hours, including changing JBOSS settings to UTF-8 encoding and xhtml files are saved as UTF-8. Could someone point me in some direction towards the solution?

Updating The HTML header is as follows:

<f:view contentType="text/html; charset=UTF-8"
        encoding="UTF-8"
        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:a="http://richfaces.org/a4j"
        xmlns:rich="http://richfaces.org/rich"
        xmlns:s="http://jboss.com/products/seam/taglib">

       <html>
          <head>
             <meta http-equiv="X-UA-Compatible" content="IE=8"/>
             <meta name="author" content="#{applicationService.getPropertyValue('app.fullname')}"/>
             <meta http-equiv="Content-Language" content="pt-BR"/>
             <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
            <meta http-equiv="Cache-Control" content="public, must-revalidate"/>
          </head>
      </html>
</f:view>

Updating

As suggested by Gustavo Fragoso I saved the emoji string &#x1F354 by passing the value to inputText the string was converted to

Update: As suggested by Gustavo Fragoso could be a problem with my browser but it is not; I am using a library called jQuery-emoji-Picker and my front-end works perfectly, if I click on some emoji it will normally for input, the problem is when I do the reverse ie, if the emoji string comes from the bank or if I manually paste the emoji in inputText value when rendering html the emojis are converted to ; i was almost certain that some configuration in JBOSS was converting all request and Response to other encoding than UTF-8; so I made a filter that forced HTTP requests for UTF-8 encoding and it was like this:

package br.com.dt.filter;

import static org.jboss.seam.ScopeType.APPLICATION;

import static org.jboss.seam.ScopeType.APPLICATION;

import java.io.IOException;

import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

import org.jboss.seam.annotations.Install;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Scope;
import org.jboss.seam.annotations.intercept.BypassInterceptors;
import org.jboss.seam.annotations.web.Filter;
import org.jboss.seam.web.AbstractFilter;

@Scope(APPLICATION)
@Name("encodingFilter")
@Install(precedence = Install.BUILT_IN)
@BypassInterceptors
@Filter
public class EncodingFilter  extends AbstractFilter{
    /** Preform the filtering. */
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {  
           response.setContentType("text/html; charset=UTF-8");  
           request.setCharacterEncoding("UTF-8");  
           response.setCharacterEncoding("UTF-8");  
           chain.doFilter(request, response);  
      }  
}

more unsuccessfully, so I set up JBOSS on standalone.xml by putting:

 system-properties
        property name="file.encoding" value="utf-8"/
        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

more also unsuccessful so far.

Updating:

In Web Resources - Configuration there are several configuration files of faces-config.xml and one of them is called jsf-facelets.jar and see how this is configured:

<?xml version="1.0" encoding="ISO-8859-1" ?>

<!DOCTYPE faces-config PUBLIC
 "-//Sun Microsystems, Inc.//DTD JavaServer Faces Config 1.1//EN"
 "http://java.sun.com/dtd/web-facesconfig_1_1.dtd">

<faces-config>
    <component>
        <component-type>facelets.ui.Repeat</component-type>
        <component-class>com.sun.facelets.component.UIRepeat</component-class>
    </component>
    <component>
        <component-type>facelets.ui.ComponentRef</component-type>
        <component-class>com.sun.facelets.tag.ui.ComponentRef</component-class>
    </component>
    <component>
        <component-type>facelets.ui.Debug</component-type>
        <component-class>com.sun.facelets.tag.ui.UIDebug</component-class>
    </component>
    <render-kit>
        <render-kit-id>HTML_BASIC</render-kit-id>
        <renderer>
            <component-family>facelets</component-family>
            <renderer-type>facelets.ui.Repeat</renderer-type>
            <renderer-class>com.sun.facelets.component.RepeatRenderer</renderer-class>
        </renderer>
    </render-kit>
</faces-config>

is this ISO-8859-1 configuration the reason for this problem?

  • Does your html file have a charset set set in header? Saving as utf-8 is one thing, another is how browser interprets.

  • 1

    Yes; the header is as follows: <meta http-equiv="content-type" content="text/html; charset=UTF-8" /> also sets f:view to: f:view contenttype="text/html; charset=UTF-8" encoding="UTF-8"

  • Take a look at this question to see if it helps: https://stackoverflow.com/questions/42324696/insert-emoji-to-ptexteditor-or-pinputtextarea-on-primefaces?rq=1

  • Alex, you don’t have to put # in place of < and >. Just select the code and press Ctrl+K or the button {} editor. See more tips on how to format code in help center

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.