Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/77.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Cdi JSF 2.3 FacesConverter中未注入应用程序范围bean_Cdi_Converters_Jsf 2.3 - Fatal编程技术网

Cdi JSF 2.3 FacesConverter中未注入应用程序范围bean

Cdi JSF 2.3 FacesConverter中未注入应用程序范围bean,cdi,converters,jsf-2.3,Cdi,Converters,Jsf 2.3,我有以下人脸转换器: @FacesConverter(forClass = Onderwerp.class, managed = true) public class OnderwerpConverter implements Converter<Onderwerp> { @Inject private Web web; @Override public Onderwerp getAsObject(FacesContext context, UIComponent compone

我有以下人脸转换器:

@FacesConverter(forClass = Onderwerp.class, managed = true)
public class OnderwerpConverter implements Converter<Onderwerp> {

@Inject
private Web web;

@Override
public Onderwerp getAsObject(FacesContext context, UIComponent component, String value) {

    log.trace("Converting to object from string: " + value);

    return web.getAllActiveOnderwerpen().stream().filter(o -> o.getId().equals(Long.parseLong(value))).findFirst().get();
}


@Override
public String getAsString(FacesContext context, UIComponent component, Onderwerp onderwerp) {

    log.trace("Converting to string from object: " + onderwerp);

    return onderwerp.getId().toString();
}

}
Faces-config.xml是:

<?xml version="1.0" encoding="UTF-8"?>
<faces-config xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-facesconfig_2_3.xsd" version="2.3">
这很好,但当然有点难看:)


有人经历过这种行为吗?

我也有同样的问题,我找到了解决办法

您必须创建一个指示JSF版本的配置bean:

import javax.faces.annotation.FacesConfig;
import javax.faces.annotation.FacesConfig.Version;


@FacesConfig(
        // Activates CDI build-in beans
        version=Version.JSF_2_3 
        )
public class ConfigBean {

}

转换器是否被识别为bean,以便将其注入?尝试向它添加一些bean定义注释,例如
@Dependent
@Named
或任何适合您的设置的东西。在JSF 2.3中,您可以添加managed=true,它应该自动识别CDI bean。。。但事实并非如此。我可以添加一些bean定义注释,但这是2.3之前的旧解决方案,所以没有意义。这意味着该解决方案不再有用了?顺便问一下,您的应用程序中是否有其他CDIBean,以便验证CDI是否正常工作?可能还需要再次检查是否存在
beans.xml
(并尝试使用bean发现模式
all
)。@Siliarus all workarounds;)我有很多CDI bean,它们相互注入,与EJB bean混合。没有问题。我没有豆子。xml,因为我选择只使用带注释的CDIBeans。我可以添加它并将发现模式全部置于其中,但关键是我希望在JSF2.3中引入的
@FacesConverter
中支持本机CDI。我需要有人谁也有2.3安装在他的应用服务器谁可以确认(或否认)这种行为。已经感谢您的帮助。在mojarra 2.3上创建了一个问题,无法工作,请参阅@FabiYo:您尝试过吗?因为对于一些人来说,它似乎可以做一些事情,我将尝试总结我们要做的一切,以使它发挥作用。1-在“@FacesConverter”注释中设置managed=true 2-在faces-config.xml中验证faces 2.3版本3-创建带有属性“version=version.JSF_2_3”的“@FabiYo”注释配置bean关于@FabiYo示例,我认为问题可能与配置bean中的“@ApplicationScoped”注释有关。@Kukeltje,当然,这就是我记录问题的原因。对于一些人来说,这是可行的,因为他们使用另一个应用服务器或servletcontainer@JesúsIbánFernándezRodríguez请提供完整的服务器配置、JSF版本等。。。
return CDI.current().select(Web.class).get().getAllActiveOnderwerpen().stream().filter(o -> o.getId().equals(Long.parseLong(value))).findFirst().get();
import javax.faces.annotation.FacesConfig;
import javax.faces.annotation.FacesConfig.Version;


@FacesConfig(
        // Activates CDI build-in beans
        version=Version.JSF_2_3 
        )
public class ConfigBean {

}