1 Reply Latest reply on May 30, 2007 12:38 AM by Anvar Sart

    How to define default encoding ?

    Anvar Sart Newbie

      Hello =))
      I wondering where can i define default page charset and encoding ?

      I tryed to set PhaseListener

      public class EncodingPhaseListener implements PhaseListener {
       /**
       *
       */
       private static final long serialVersionUID = - 5249591857614335618L;
       private static final String ENCODING = "UTF-8";
      
       public void afterPhase (final PhaseEvent event) {
       }
      
       public void beforePhase (final PhaseEvent event) {
       try {
       ((ServletRequest) FacesContext.getCurrentInstance ().getExternalContext ().getRequest ()).setCharacterEncoding (ENCODING);
       ((ServletResponse) FacesContext.getCurrentInstance ().getExternalContext ().getResponse ()).setCharacterEncoding (ENCODING);
       } catch (final UnsupportedEncodingException e) {
       e.printStackTrace();
       }
      
       }
      
       public PhaseId getPhaseId () {
       return PhaseId.ANY_PHASE;
       }
      
      
       }
      

      faces-config.xml
      <lifecycle>
       <phase-listener>
       com.myproject.project.EncodingPhaseListener
       </phase-listener>
      </lifecycle>
      


      but it's not working....

      best regards

        • 1. Re: How to define default encoding ?
          Anvar Sart Newbie

          And i tryed to set filter but it's eather do not work.

          import javax.servlet.*;
          import java.io.IOException;
          public class EncodingFilter implements Filter{
           public void destroy(){ }
          
           public void doFilter(ServletRequest req, ServletResponse resp,
          FilterChain chain) throws ServletException, IOException{
           req.setCharacterEncoding("utf-8");
           chain.doFilter(req, resp);
           }
           public void init(FilterConfig config) throws ServletException
          { }
          


          web.xml

          <filter>
           <display-name>EncodingFilter</display-name>
           <filter-name>EncodingFilter</filter-name>
           <filter-class>com.myproject.project.EncodingFilter</filter-class>
          </filter>
          
          <filter-mapping>
           <filter-name>EncodingFilter</filter-name>
           <url-pattern>*.seam</url-pattern>
          </filter-mapping>
          


          please, someone help =))