I am using the javax.faces.render.Renderer
class to render my custom components. I override either encodeBegin
or encodeEnd
to achieve my desired output.
I would like to know when should I use either of these methods? Is there any guideline on when should encodeBegin
and encodeEnd
be used?
That depends on the component tree hierarchy. Key is, do you expect children? How do you want the encoded output to look like when there are children?
Usually, you use encodeBegin()
if you want to encode output before children are encoded. E.g. a start tag like HTML <div>
. Usually, you use encodeEnd()
if you want to encode output after children are encoded. E.g. an end tag like HTML </div>
. Or perhaps an additional <script>
which should work on the before-generated <div>
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With