Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jsf-2/2.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/cmake/2.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
Jsf 2 JSF1006:无法实例化类型为的转换器_Jsf 2_Converter - Fatal编程技术网

Jsf 2 JSF1006:无法实例化类型为的转换器

Jsf 2 JSF1006:无法实例化类型为的转换器,jsf-2,converter,Jsf 2,Converter,我在以下方面实施了解决方案: 像这样: 转换器: @FacesConverter(value="genericEnumConverter") public class GenericEnumConverter implements Converter { private static final String ATTRIBUTE_ENUM_TYPE = "GenericEnumConverter.enumType"; @Override pu

我在以下方面实施了解决方案:

像这样:

转换器:

@FacesConverter(value="genericEnumConverter")
public class GenericEnumConverter implements Converter {

        private static final String ATTRIBUTE_ENUM_TYPE = "GenericEnumConverter.enumType";

        @Override
        public String getAsString(FacesContext context, UIComponent component, Object value) {
            if (value instanceof Enum) {
                component.getAttributes().put(ATTRIBUTE_ENUM_TYPE, value.getClass());
                return ((Enum<?>) value).name();
            } else {
                throw new ConverterException(new FacesMessage("Value is not an enum: " + value.getClass()));
            }
        }

        @Override
        @SuppressWarnings({"rawtypes", "unchecked"})
        public Object getAsObject(FacesContext context, UIComponent component, String value) {
            Class<Enum> enumType = (Class<Enum>) component.getAttributes().get(ATTRIBUTE_ENUM_TYPE);
            try {
                return Enum.valueOf(enumType, value);
            } catch (IllegalArgumentException e) {
                throw new ConverterException(new FacesMessage("Value is not an enum of type: " + enumType));
            }
        }

    }
看起来转换器没有注册到JSF,但我使用了:

@FacesConverter(value="genericEnumConverter")

有人对此有什么看法吗?

我对JBoss+JSF2.0+SEAM也有同样的错误。通过添加以下代码行,问题得以解决

@Name("testConverter")
@Scope(ScopeType.CONVERSATION)
@org.jboss.seam.annotations.faces.Converter
@BypassInterceptors
public class TestConverter implements Converter {
    ...
}

试试
@FacesConverter(“genericEnumConverter”)
注释看起来不错。这个错误是多么奇怪。这表明您实际上使用的是
converter=“#{genericEnumConverter}”
而不是
converter=“genericEnumConverter”
。但是,您的代码显示了正确的方法。您是否绝对确定您正在运行您认为正在运行的代码?也许您正在其他地方使用此转换器,其中出现了
{}
错误?或者您在摆弄了
转换器
属性之后没有正确地重新构建/重新部署/重新启动?@Daniel我试过了,但没有成功。@BalusC我取消了应用程序的部署,清理并构建了应用程序,运行了,但仍然没有效果。是的,上面的代码是从我的项目中复制的。我发现了问题:在xhtml的其他地方,我放置了converter=“”,但没有在其中写入任何内容。我的错。很抱歉
@FacesConverter(value="genericEnumConverter")
@Name("testConverter")
@Scope(ScopeType.CONVERSATION)
@org.jboss.seam.annotations.faces.Converter
@BypassInterceptors
public class TestConverter implements Converter {
    ...
}