Inspired by Cagatay Civici’s idea of having a phase listener rendering images I decided to replace my PDF rendering servlets from a product that I’m currently working on.
At the end of the RESTORE_VIEW phase the listener would decode the request URL and extract a managed property reference expression, create an EL expression and get the byte array for the binary document.
To display the binary document a matching URL needs to be generated. Here the <object> tag is used for displaying a PDF document. The URL part after /pdf/stream/ is used as a part of a value expression for referencing the actual PDF binary document (here it is managedBeanName.propertyName).