I am getting error in this code, i am stuck at this point. Please help me.
getter and setter for selectedRole, allRolesList are included in code
java code
private String selectedRole;
List<String> allRolesList = new ArrayList<String>();
if(!roleList.isEmpty()){
isRolesPresent = true;
for(UserRole ur : roleList){
allRolesList.add(ur.getRoleName().toString());
/* printing allRolesList results: [admin] */
System.out.print("allRolesList "+allRolesList);
}
}else{
isRolesPresent = false;
}
prime-faces code:
<p:selectOneMenu id="role" value="#{usersDAO.selectedUser}" effect="fade" required="true"
requiredMessage="Role cannot be null">
<f:selectItems value="#{usersDAO.allRolesList}" />
</p:selectOneMenu>
The
#{usersDAO.selectedUser}is apparently not of typeString. JSF doesn’t know how to convertStringtoUseras there is no converter been registered forUsertype, hence the error message which you got.You’d normally need to create a custom
Converterfor this, as explained in this answer, but based on the given Java code, you actually need#{usersDAO.selectedRole}instead which is already ofStringtype. So you don’t need to create a customConverter.By the way, a managed bean with “DAO” in the name is quite strange. Are you sure that you aren’t mixing concepts or tight-coupling different responsibilities in a single class (which would lead to poor reusability/maintainability)?