简体   繁体   中英

Primefaces: Conversion Error setting value 'Admin' for 'null Converter'

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

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;
    }

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM