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. SPOJ COMPANYS Two Famous Companies 最小生成树,二分,思路 难度:2

    http://www.spoj.com/problems/COMPANYS/en/ 题目要求恰好有k条0类边的最小生成树 每次给0类边的权值加或减某个值delta,直到最小生成树上恰好有k条边为0,此 ...

  2. hdu5618

    题解: CDQ分治 三重分治 第一重排序 第二重CDQ 第三重树状数组 代码: #include<cstdio> #include<cmath> #include<cst ...

  3. 自动化测试--响应请求测试(.net)

    Web运行原理简单地说是“浏览器发送一个HTTP Request到Web服务器上,Web服务器处理完后将结果(HTTP Response)返回给浏览器”. 通常测试一个web api是否正确,可以通过 ...

  4. 重写ajax方法实现特定情况下跳转登录页面

    jQuery(function($){ // 备份jquery的ajax方法 var _ajax=$.ajax; // 重写ajax方法, $.ajax=function(opt){ var _suc ...

  5. Java第六次作业--异常处理和Java类集

    Deadline: 2017-5-4 23:00 一.学习要点 认真看书并查阅相关资料,掌握以下内容: 理解Java的异常处理机制 掌握捕获异常和声明抛出异常的方法 掌握List接口的实现类Array ...

  6. Android 开发有哪些新技术出现?

    这里记录一下在知乎回答的<Android 开发有哪些新技术出现?>.知乎链接在这里. 原问题如下: Android 开发有哪些新技术出现?可以从UI设计或者一些核心的算法之类的说起 这是我 ...

  7. python(五):面向对象--类和实例

    一.类的基本概念 类是用来创建数据结构和新类型对象的主要机制.一个类定义了一系列与其实例对象密切关联的属性.典型的属性包括变量(也被称为 类变量)和函数(又被称为方法). 1.class上下文 cla ...

  8. 7-19 PAT Judge(25 分)

    The ranklist of PAT is generated from the status list, which shows the scores of the submissions. Th ...

  9. [UOJ213][UNR #1]争夺圣杯

    uoj description 一个长为\(n\)的序列,给定一个参数\(m\),求所有长度为\(m\)的区间的最大值之和. 对于所有的\(m\in[1,n]\)你都需要分别求出答案然后异或起来. \ ...

  10. 使用 Content-Encoding: br 替换 Content-Encoding: gzip

    今天在测试一个web 框架的时候无意发现框架运行是响应头时有一个 Content-Encoding: br 发现是一个gzip 算法的替代,同时压缩比很不错 浏览器兼容性如下: nginx 的配置参考 ...