我试图以以下方式在我的FacesConverted中注入一个ManagedBean:
@ManagedBean
@RequestScoped
@FacesConverter(forClass = Group.class)
public class GroupConverter implements Converter {
@ManagedProperty("#{groupService}")
private GroupService groupService;
@Override
public Group getAsObject(FacesContext context, UIComponent arg1,
String groupName) {
return groupService.findGroupByName(groupName);
}
@Override
public String getAsString(FacesContext arg0, UIComponent arg1, Object group) {
return ((Group) group).getName();
}
public GroupService getGroupService() {
return groupService;
}
public void setGroupService(GroupService groupService) {
this.groupService = groupService;
}
}
问题是groupService没有被注入,我得到了一个空指针异常。既然它也是一个ManagedBean,它不应该自动进行自动装配吗?当我将"getAsObject"更改为"return new Group();"时,一切都能正常工作。
有任何想法吗?
#{myConverter}
让我省了很多时间! - axelarge