I have a RoleStatus
enum which is as being a property of Role
entity mapped to an integer in the DB (but that part is irrelevant). I'd like to present a List<Role>
in a <p:dataTable>
in which one column should have a <h:selectOneMenu>
for the RoleStatus
property of the Role
entity. How can I implement this with or without OmniFaces?
Here's the enum:
public enum RoleStatus {
ACTIVE(1, "Active"),
DISABLE(2, "Disable");
private final int intStatus;
private final String status;
private RoleStatus(int intStatus, String status) {
this.intStatus = intStatus;
this.status = status;
}
public int getIntStatus() {
return status;
}
public String getStatus() {
return status;
}
}
Here's the backing bean:
@ManagedBean
@ViewScoped
public class RoleController {
private List<Role> roles;
@ManagedProperty("#{roleService}")
private IRoleService roleService;
@PostConstruct
public void init() {
roles = roleService.getRoles();
}
public List<Role> getRoles() {
return roles;
}
}
Finally, the data table where I'd like to have a <h:selectOneMenu>
for the RoleStatus
property of Role
entity, showing all available enum values as select item options.
<h:form id="roleForm">
<p:dataTable value="#{roleController.roles}" var="role">
<p:column>
<h:outputText value="#{role.roleid}" />
</p:column>
<p:column>
<h:inputText value="#{role.role}" />
</p:column>
<p:column>
<h:inputText value="#{role.description}" />
</p:column>
<p:column>
<h:selectOneMenu value="#{role.roleStatus}">
<!-- How??? -->
</h:selectOneMenu>
</p:column>
</p:dataTable>
</h:form>
How can I achieve this? Do I need the OmniFaces SelectItemsConverter
?