Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在使用javax.faces.render.Renderer该类来呈现我的自定义组件。我覆盖encodeBegin或encodeEnd实现我想要的输出。
javax.faces.render.Renderer
encodeBegin
encodeEnd
我想知道什么时候应该使用这些方法中的任何一种?是否有关于何时应该使用encodeBegin和使用的指南encodeEnd?
这取决于组件树层次结构。关键是,你期待孩子吗?当有孩子时,您希望编码输出看起来如何?
通常,encodeBegin()如果要在对子项进行编码之前对输出进行编码,则使用此选项。例如像 HTML 这样的开始标签<div>。通常,encodeEnd()如果要在对子项进行编码后对输出进行编码,则使用此选项。例如像 HTML 这样的结束标签</div>。或者也许是一个额外<script>的应该在之前生成的<div>.
encodeBegin()
<div>
encodeEnd()
</div>
<script>