1

The environment and requirement

My environment is JSF 2.2 (Mojarra) on wildfly 10. I'm working on a font-selection JSF composite component. The component basically consists of an HTML <select> input for selecting the font-name and some other input for selecting the font-size. So far, so simple.

The problem

The problem comes when I try to optimize my code. The list of available fonts is generated on the server (in a backing component) and there might be more than 100 entries, which lead to quite a few KBs of HTML code. This would be ok, but when I place the component 5-times on one page, the long list of fonts is generated and transfered 5-times from the server to the browser. I really would like to transfer the font-list just once to the browser and populate the select-items via JavaScript (or some other method).

Some ideas

I already had the idea of providing the font-list via a JavaScript file as a JSON string. That works fine for a static font-list and the list needs to be transfered only once. But I'm not aware of how to generate such a JSON file dynamically from within a composite component.

A clean solution

The question is, how could a JSF composite component provide such a list in a clean way to the browser? Is this possible at all? Do I have to create a servlet that provides the resources? Or maybe a dynamic resource handler? Both ideas don't look like a clean solution to me, as the composite-component would have dependencies to those other resources.

Martin Höller
  • 2,714
  • 26
  • 44
  • Try https://stackoverflow.com/questions/36993501/how-set-selected-in-a-datalist-html-php and creating json for a composite is almost identical as creating javascript for it... What is the actual problem you have with this? – Kukeltje May 03 '18 at 20:25
  • Sorry for the delay. The linked article doesn't provide any useful information for me. My problem is, as stated, how to provide dynamic JavaScript or JSON to *multiple* components on a single page. For example if I have `` two times on a page, I want the components to get the list of fonts from a single/shared resource (e.g. JavaScript file). – Martin Höller May 08 '18 at 05:50

0 Answers0