I'm trying to inject a ManagedBean in my FacesConverted the following way:

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

The problem is that groupService isn't being injected and I get a NullPointerEx. Shouldn't it be autowired automatically since it's also a ManagedBean? It all works when I change "getAsObject" to "return new Group();" obviously.

Any ideas?

The solution:

It is likely that you are not resolving the managed bean name.

@ManagedBean(name = "myConverter")
@RequestScoped
@FacesConverter(value = "myConverter")
public class MyConverter implements Converter {

For example, consider these two components:

<h:inputText converter="myConverter" value="#{foo.prop}" />
<h:inputText converter="#{myConverter}" value="#{bar.prop}" />

When the converter is set on the first component, it will be created by Application.createConverter. A converter is not a managed bean. The same rules apply if you match a converter by type.

In the second component, a value expression is used to return a class that implements Converter. This uses the usual managed bean mechanisms. In this case, the @FacesConverter annotation is irrelevant.

ManagedProperty not injected in @FacesConverter的更多相关文章

  1. 【九】注入框架RoboGuice使用:(Your First Injected Service and BroadcastReceiver)

    上一篇我们简单的介绍了一下RoboGuice的使用([八]注入框架RoboGuice使用:(Your First Injected Fragment)),今天我们来看下服务(Service)和广播接受 ...

  2. @EnableAsync annotation metadata was not injected

    [问题描述] @EnableAsync annotation metadata was not injected spring配置初始化时候报错 nested exception is java.la ...

  3. @EnableAsync annotation metadata was not injected Spring容器启动后访问Servlet报错

    @EnableAsync annotation metadata was not injected 2015年12月20日 20:06:54 7570 在初始化spring事务部分碰到该错误, 详细错 ...

  4. The bean 'xxx' could not be injected as a 'xxx'because it is a JDK dynamic proxy that implements

    启动springboot项目的时候示以下错误 Error starting ApplicationContext. To display the conditions report re-run yo ...

  5. Bean with name 'xxxService' has been injected into other beans [xxxServiceA,xxxServiceB] in its raw version as part of a circular reference, but has eventually been wrapped

    启动项目,通过@Autowired注入对象,出现循环依赖,导致项目启动失败,具体报错信息如下: Exception encountered during context initialization ...

  6. injected stylesheet 谷歌扩展插件,造成样式异常

    今天在开发的时候,遇到一个问题,就是我们我在写发送广告的功能,然后我用了一个textare文本框,这个时候,发现了一个问题.这个文本框凭空消失了.不见了,我以为是自己的那个样式不小心把这个隐藏掉了后来 ...

  7. QIBO /do/jf.php EvilCode Execution Injected By /hack/jfadmin/admin.php

    catalog . 漏洞描述 . 漏洞触发条件 . 漏洞影响范围 . 漏洞代码分析 . 防御方法 . 攻防思考 1. 漏洞描述 这个漏洞的成因简单来说可以归纳为如下几点 . 类似于ECSHOP的的模版 ...

  8. spring报nested exception is java.lang.IllegalArgumentException: @EnableAsync annotation metadata was not injected错误

    http://www.oschina.net/question/1539472_159699

  9. 【八】注入框架RoboGuice使用:(Your First Injected Fragment)

        上一篇我们简单的介绍了一下RoboGuice的使用([七]注入框架RoboGuice使用:(Your First Custom Binding)),今天我们来看下fragment的注解     ...

随机推荐

  1. Deploying Qt or how to avoid “could not find or load the Qt platform plugin”

    (转自:http://www.tripleboot.org/?p=138) Once you’ve built your first Qt program, have you tried it on ...

  2. windows下搭建svn服务器及权限配置

    服务器端VISUALSVN SERVER 3.3.1 下载地址 https://www.visualsvn.com/server/download/ 客户端TortoiseSVN 1.8.13下载地址 ...

  3. New Concept English Two 27 73

    新概念一:对应小学水平,重在口语和基础.是不可多得的学习教材,全本144课,可以给孩子(hello world 级别的我)学半年.新概念二:对应高中水平,重在听力和场景对话,共96课,学后,听懂歪果仁 ...

  4. JSP session过期时间(小记)

    以下情况,Session结束生命周期,Servlet容器将Session所占资源释放:1.客户端关闭浏览器2.Session过期3.服务器端调用了HttpSession的invalidate()方法. ...

  5. Gakki赛高-团队介绍

    队名:Gakki赛高 队员学号(标记组长): 张朝玮(组长)201521123106 张翔 201521123107 陈伟泽 201521123111 李嘉廉 201521123091 侯帅军 201 ...

  6. 送人玫瑰,手留余香——2015年技术分享交流小结

    飞测说:分享让我们更加团结,交流让我们更加凝聚,送人玫瑰,手留余香,更多分享交流也让自己成长的更加完善,2015年已经过去了好几个月,今天刚好整理了下我们科大讯飞武汉测试团队技术分享交流的这块,顺便做 ...

  7. iOS-----多线程之NSThread

    多线程 iOS平台提供了非常优秀的多线程支持,程序可以通过非常简单的方式来启动多线程,iOS平台不仅提供了NSThread类来创建多线程,还提供了GCD方式来简化多线程编程,提供了NSOperatio ...

  8. bag of words

    参考文献 Bag-of-words model (BoW model) 最早出现在NLP和IR领域. 该模型忽略掉文本的语法和语序, 用一组无序的单词(words)来表达一段文字或一个文档. 近年来, ...

  9. Properties集合小应用--限制用户对软件的使用次数

    我们可以注意到一些付费软件可以试用一定的次数,超过限制次数后,就必须到官网购买正版才能继续使用. 这里就简单地模拟一下这种效果的实现. * 需求:记录程序的启动次数,当启动次数超过3次后,要求使用者注 ...

  10. UVA-11478 Halum【二分】【差分约束】

    LINK1 LINK2 题目大意 给你一个n个点,m条边的有向图 有一种操作把所有到达这个点的边全部减小d,把所有从从这个点出发的边加上d 问最后是否可以让所有边的边权最小值最大 如果可以无限大,输出 ...