views:

128

answers:

1

Hello guys,

For many internal problems that doesn't count now, We have a Servlet filter that changes all outcome that's application/xhtml+xml and rewrite to text/html;charset=UTF-8 so even using the facelets it'll work with no problem with IE 6.0.

My question is on the HtmlResponseWriter, which is the component responsible for the rendering. Is it possible to extend it and override its methods so we accomplish the desired effect of the filter?

  • The content type will always be output as text/html;
  • The encoding will be always UTF-8;
  • The script tag will be wrapped inside a < ! -- <[[CDATA ]]> --> .

Thanks in advance.

+1  A: 

Yes, we have extended JSF (actually Oracle ADF) components in order to meet special requirements that could not be done out of the box. You will need to get all of the source files of those renders and do a recursive search for the offending HTML you want removed, the application/xhtml+xml. This is just to make sure it is in fact inside the HtmlResponseWriter class. JSF component frameworks can be complex so you never know, there may be other instances where this header is rendered.

Since the HtmlResponseWriter isn't declared final like some components are, you can just extend this, and override the method where application/xhtml+xml is being printed and register it in faces-config.xml. The only obstacles to this is if there are private variables declared inside of HtmlResponseWriter being referenced in the method that you need to override. If that is the case you will either not be able to reference them in your reimplementation or you will have to completely re-build a new HtmlResponseWriter class (by extending the ResponseWriter and mimicking each method and instance variable). The benefit of extending the HTMLResponseWriter is that you will pick up any changes (from JSF updates) to it automatically (except in the overridden method of course).

Update: This is what I did for my faces-config.xml, but it is using Oracle ADF:

<?xml version="1.0" encoding="windows-1252"?>
<faces-config version="1.2" xmlns="http://java.sun.com/xml/ns/javaee"&gt;
  <application>
    <default-render-kit-id>oracle.adf.rich</default-render-kit-id>
  </application>
  <render-kit>
    <render-kit-id>oracle.adf.rich</render-kit-id>
    <renderer>
      <component-family>org.apache.myfaces.trinidad.Input</component-family>
      <renderer-type>oracle.adf.rich.Text</renderer-type>
      <renderer-class>com.company.jsf.renders.text.CustomRenderer</renderer-class>
    </renderer>
  </render-kit>
</faces-config>
Zombies
@Zombie, yes! That is exactly what a need to do it but I don't know how to declare the extended component for proper usage. Could you provide me a little more info?
Kamia
@Kamia, Once you have your Java Class written, point to it in faces-config.xml so that it registers the `HtmlResponseWriter` with your new class. I can provide an example, but this is from ADF though...
Zombies
@Zombie just found the steps needed to it, in the case of the ResponseWriter, isn't enough to use it.. you must rewrite the whole render kit or make a decorator to use with it to prevent the rewriting of all classes.Ill close this question and give you the points since your answer led me to the book Pro JSF and Ajax (pg 237 to 264).I Wish I could point @BalusC for that too.
Kamia