Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

encodeBegin vs encodeEnd in JSF and which one should be preferred

Tags:

jsf

jsf-1.2

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?

like image 967
Naveen Avatar asked Jul 10 '13 12:07

Naveen


1 Answers

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>.

like image 147
BalusC Avatar answered Nov 12 '22 22:11

BalusC