Write a custom HtmlResponseWriter JSF
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.
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">
<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>
精彩评论