1

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> 
Androider
  • 2,884
  • 5
  • 28
  • 47

1 Answers1

4

The #{usersDAO.selectedUser} is apparently not of type String. JSF doesn't know how to convert String to User as there is no converter been registered for User type, hence the error message which you got.

You'd normally need to create a custom Converter for this, as explained in this answer, but based on the given Java code, you actually need #{usersDAO.selectedRole} instead which is already of String type. So you don't need to create a custom Converter.

<p:selectOneMenu ... value="#{usersDAO.selectedRole}">

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)?

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • 3
    A DAO class is normally not a JSF managed bean. It's normally a property of a JSF managed bean. A DAO class is normally a class which contains all the database interaction code such as `find()`, `list()`, `create()`, `save()`, `delete()`, etc. This is absolutely not to be used as a JSF managed bean. – BalusC Jun 06 '12 at 17:14