Often times applications store values in look up tables or domains then map those values to an Enum. In this java lesson will show how to create radio buttons with an Enum as a backing object. If you look at our RadioButtonEnum backing bean, you will noticed that we will return the Enum by calling values() which return the enum in the order they are declared. Depending on your requirements your web screen you may need to order the enum based a value for a better user experience.
<f:selectItems/> is part of the core JSF library which accepts an array or collection as the value where we bind it to the radioButtonEnum.states. Creating a variable state, it is referenced in the itemValue which will be the value that is sent in the request. The itemLabel is the value that will be shown on the webpage. There is other variables so please refer to the documentation.
JSF 2.2 passthrough
JSF 2.2 introduced the ability to write standard HTML/HTML5 elements and bind values using JSF passthrough attributes and elements. Below shows an example to use radio buttons without a table and your favorite front end framework such as bootstrap or google material design. Using the same backing bean or managed bean above we will specify the name as passthrough attribute which will override the implicit attribute. Then using a <ui:repeat/> we will create <label/>, <input/> and <span/> to elements to visually display the radio buttons.