编写自定义 HtmlResponseWriter JSF
对于许多现在不重要的内部问题,我们有一个 Servlet 过滤器,它可以更改 application/xhtml+xml
的所有结果并重写为 text/html;charset=UTF-8
code> 因此,即使使用facelets,它也可以在 IE 6.0 上正常工作。
我的问题是关于 HtmlResponseWriter,它是负责渲染的组件。是否可以扩展它并重写它的方法,以便我们实现过滤器的预期效果?
- 内容类型将始终输出为text/html;
- 编码将始终为
UTF-8;
- 脚本标记将被包装在
<; 中。 ! -- <[[CDATA]]> -->
。
提前致谢。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,我们扩展了 JSF(实际上是 Oracle ADF)组件,以满足无法开箱即用的特殊要求。您将需要获取这些渲染的所有源文件,并对要删除的有问题的 HTML(
application/xhtml+xml
)进行递归搜索。这只是为了确保它实际上位于HtmlResponseWriter
类中。 JSF 组件框架可能很复杂,因此您永远不知道,可能还有其他实例呈现此标头。由于
HtmlResponseWriter
不像某些组件那样声明为final
,因此您可以扩展它,并重写application/xhtml+xml
所在的方法正在打印并在中注册它 faces-config.xml
。唯一的障碍是,如果您需要重写的方法中引用了在HtmlResponseWriter
内部声明的私有变量。如果是这种情况,您将无法在重新实现中引用它们,或者必须完全重新构建一个新的HtmlResponseWriter
类(通过扩展ResponseWriter
和模仿每个方法和实例变量)。扩展HTMLResponseWriter
的好处是,您将自动获取对其所做的任何更改(来自 JSF 更新)(当然,覆盖方法中的更改除外)。更新:
这就是我对 faces-config.xml 所做的操作,但它使用的是 Oracle ADF:
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 theHtmlResponseWriter
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 declaredfinal
like some components are, you can just extend this, and override the method whereapplication/xhtml+xml
is being printed and register it infaces-config.xml
. The only obstacles to this is if there are private variables declared inside ofHtmlResponseWriter
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 newHtmlResponseWriter
class (by extending theResponseWriter
and mimicking each method and instance variable). The benefit of extending theHTMLResponseWriter
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: