Hi,

i am a apache faces trinidad user,
now i have a problem about the charset,

i found that the charset was changed after i use some ajax action like
switch the tr:panelTabbed

i have already set the content type, and i have tried to set the content
type
through servlet-filter, but also not work.

my jsp, web.xml like this


xxx.jsp

<?xml version="1.0" encoding="UTF-8"?>
<jsp:root xmlns:jsp=" http://java.sun.com/JSP/Page"; version="2.0"
          xmlns:f="http://java.sun.com/jsf/core";
          xmlns:h=" http://java.sun.com/jsf/html";
          xmlns:af="http://myfaces.apache.org/trinidad";
          xmlns:afh=" http://myfaces.apache.org/trinidad/html";>
<jsp:directive.page contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"/>



<f:view locale="#{dataModelAction.locale }">
    <jsp:scriptlet>
        response.setContentType("text/html; charset=UTF-8");
    </jsp:scriptlet>
    <afh:html>
    <f:loadBundle basename="com.message.messages " var="msgs" />
    <afh:head title="MCPP1101M-Course Information Setup(Modify)">
        <meta content="text/html; charset=UTF-8" http-equiv="content-type"
/>
        <link rel="stylesheet" type="text/css"
href="../../../css/default.css" />
        <afh:script source="../../../scripts/common.js" />
    </afh:head>
    <afh:body styleClass="mainbgcolor">
<h:form acceptcharset="UTF-8" id="form1">
            <af:panelHorizontalLayout    halign="left">
                <af:commandButton text="Try Me"
                    actionListener="#{action.tryMe}" />
            </af:panelHorizontalLayout>
<af:panelBox background="medium" >
<af:panelGroupLayout layout="horizontal">
                    <af:inputText columns="50" maximumLength="180"
                        value="a chinese word"/>
</af:panelGroupLayout>
</af:panelBox>

            <af:panelTabbed id="all" position="above" >

                <af:showDetailItem id="tab1"  text="tab1">
                </af:showDetailItem>

                <af:showDetailItem id="tab2" text="tab2">
                </af:showDetailItem>

                <af:showDetailItem id="tab3"  text="tab3" >
                </af:showDetailItem>

            </af:panelTabbed>
</h:form>
    </afh:body>
    </afh:html>
</f:view>
</jsp:root>



tryMe() method in the bean class

    public void tryMe(ActionEvent action) {
    }

web.xml setting

    <filter-mapping>
        <filter-name>trinidad</filter-name>
        <servlet-name>faces</servlet-name>
    </filter-mapping>

    <filter>
        <filter-name>CustomCharacterEncodingFilter</filter-name>
        <filter-class>com.filter.CustomCharacterEncodingFilter</filter-class>

    </filter>

    <filter-mapping>
        <filter-name>CustomCharacterEncodingFilter</filter-name>
        <servlet-name>faces</servlet-name>
    </filter-mapping>

CustomCharacterEncodingFilter.java

public class CustomCharacterEncodingFilter implements Filter {

    public void init(FilterConfig config) throws ServletException {
        //No-op
    }

    public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain)
                                                           throws
IOException, ServletException {
        ((HttpServletRequest)request).setCharacterEncoding("UTF-8");
        ((HttpServletResponse)response).setContentType("text/html;
charset=UTF-8");
        chain.doFilter(request, response);
    }

    public void destroy() {
        //No-op
    }
}


faces-config.xml

    <application>
        <!-- Use the Trinidad RenderKit -->
        <default-render-kit-id>
            org.apache.myfaces.trinidad.core
        </default-render-kit-id>
        <locale-config>
            <default-locale>en</default-locale>
            <supported-locale>cn</supported-locale>
            <supported-locale>zh_CN</supported-locale>
        </locale-config>

    </application>


action flow:
i have enter a chinese word to the text field, and click tryMe, the chinese
word
do not have any problem, but after i switch the tab panel and click tryMe
button again,
now the chinese word have a great problem
, can you provide a solution to me?

Thanks

Regards,
Lok

Reply via email to