How can I know the id of a JSF component so I can use in Javascript

前端 未结 6 1333
北海茫月
北海茫月 2020-11-22 02:47

Problem: Sometimes you will want to access a component from javascript with getElementById, but id\'s are generated dynamically in JSF, so you

6条回答
  •  广开言路
    2020-11-22 03:19

    I know this is not the JSF way but if you want to avoid the ID pain you can set a special CSS class for the selector. Just make sure to use a good name so that when someone reads the class name it is clear that it was used for this purpose.

    In your JavaScript:

    jQuery('.emailAddressesForSelector');
    

    Of course you would still have to manually manage class name uniqueness. I do think this is maintainable as long as you do not use this in reusable components. In that case you could generate the class names using a convention.

提交回复
热议问题