FacesConverter 无法与 mojarra 2.1.0-b09、2.1.1-b02 配合使用?

发布于 2024-10-26 03:57:21 字数 3204 浏览 1 评论 0原文


有了这个maven依赖,它就可以工作了:

    <dependency>
        <groupId>com.sun.faces</groupId>
        <artifactId>jsf-api</artifactId>
        <version>2.0.4-b09</version>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>com.sun.faces</groupId>
        <artifactId>jsf-impl</artifactId>
        <version>2.0.4-b09</version>
        <scope>compile</scope>
    </dependency>

但是有了这个,它就不起作用了:

    <dependency>
        <groupId>com.sun.faces</groupId>
        <artifactId>jsf-api</artifactId>
        <!--  or even this : <version>2.1.0-b09</version> -->
        <version>2.1.1-b02</version>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>com.sun.faces</groupId>
        <artifactId>jsf-impl</artifactId>
        <!--  or even this : <version>2.1.0-b09</version> -->
        <version>2.1.1-b02</version>
        <scope>compile</scope>
    </dependency>

除了

SEVERE: Servlet.service() for servlet [Faces Servlet] in context with path [/primebert] threw exception [Expression Error: 
Named Object: heroConverter not found.] with root cause
javax.faces.FacesException: Expression Error: Named Object: heroConverter not found.
        at com.sun.faces.application.ApplicationImpl.createConverter(ApplicationImpl.java:1311)
        at org.jboss.weld.environment.servlet.jsf.ForwardingApplication.createConverter(ForwardingApplication.java:153)
        at com.sun.faces.facelets.tag.jsf.ValueHolderRule$LiteralConverterMetadata.applyMetadata(ValueHolderRule.java:85)
        at com.sun.faces.facelets.tag.MetadataImpl.applyMetadata(MetadataImpl.java:81)
        at javax.faces.view.facelets.MetaTagHandler.setAttributes(MetaTagHandler.java:129)
        at javax.faces.view.facelets.DelegatingMetaTagHandler.setAttributes(DelegatingMetaTagHandler.java:102)
        at com.sun.faces.facelets.tag.jsf.ComponentTagHandlerDelegateImpl.doNewComponentActions(ComponentTagHandlerDelegate
Impl.java:402)

这是我的简单转换器类:

import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.FacesConverter;

@FacesConverter("heroConverter")
public class HeroBeanConverter implements Converter {

    public Object getAsObject(FacesContext context, UIComponent ui, String newValue) {
        System.out.println("getting as object");
        HeroBean hero = HeroBean.findHeroBeanByName(newValue);
        System.out.println("found hero : " + hero);
        return hero;
    }

    public String getAsString(FacesContext context, UIComponent component,
            Object value) {
        System.out.println("getting as string for value " + value);
        if (value == null) return "";
        return ((HeroBean) value).getName();
    }
}

这是一个错误,还是我在这里犯了一个错误? :-D


With this maven dependency, it works :

    <dependency>
        <groupId>com.sun.faces</groupId>
        <artifactId>jsf-api</artifactId>
        <version>2.0.4-b09</version>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>com.sun.faces</groupId>
        <artifactId>jsf-impl</artifactId>
        <version>2.0.4-b09</version>
        <scope>compile</scope>
    </dependency>

But with this, it's not working :

    <dependency>
        <groupId>com.sun.faces</groupId>
        <artifactId>jsf-api</artifactId>
        <!--  or even this : <version>2.1.0-b09</version> -->
        <version>2.1.1-b02</version>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>com.sun.faces</groupId>
        <artifactId>jsf-impl</artifactId>
        <!--  or even this : <version>2.1.0-b09</version> -->
        <version>2.1.1-b02</version>
        <scope>compile</scope>
    </dependency>

with the exception of

SEVERE: Servlet.service() for servlet [Faces Servlet] in context with path [/primebert] threw exception [Expression Error: 
Named Object: heroConverter not found.] with root cause
javax.faces.FacesException: Expression Error: Named Object: heroConverter not found.
        at com.sun.faces.application.ApplicationImpl.createConverter(ApplicationImpl.java:1311)
        at org.jboss.weld.environment.servlet.jsf.ForwardingApplication.createConverter(ForwardingApplication.java:153)
        at com.sun.faces.facelets.tag.jsf.ValueHolderRule$LiteralConverterMetadata.applyMetadata(ValueHolderRule.java:85)
        at com.sun.faces.facelets.tag.MetadataImpl.applyMetadata(MetadataImpl.java:81)
        at javax.faces.view.facelets.MetaTagHandler.setAttributes(MetaTagHandler.java:129)
        at javax.faces.view.facelets.DelegatingMetaTagHandler.setAttributes(DelegatingMetaTagHandler.java:102)
        at com.sun.faces.facelets.tag.jsf.ComponentTagHandlerDelegateImpl.doNewComponentActions(ComponentTagHandlerDelegate
Impl.java:402)

And here's my simple converter class :

import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.FacesConverter;

@FacesConverter("heroConverter")
public class HeroBeanConverter implements Converter {

    public Object getAsObject(FacesContext context, UIComponent ui, String newValue) {
        System.out.println("getting as object");
        HeroBean hero = HeroBean.findHeroBeanByName(newValue);
        System.out.println("found hero : " + hero);
        return hero;
    }

    public String getAsString(FacesContext context, UIComponent component,
            Object value) {
        System.out.println("getting as string for value " + value);
        if (value == null) return "";
        return ((HeroBean) value).getName();
    }
}

Is it a bug, or im at a mistake here ? :-D

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

假装爱人 2024-11-02 03:57:21

这是一个错误。它与问题 1937 相关。此错误会导致非 Glassfish 容器上的 JSF 注释未被扫描,因为它们意外地包含了一些特定于 Glassfish 的注释扫描代码。

2.1.1-b02 也是一个开发版本。而是使用稳定的版本。最新的稳定版是 2.0.4-b09。

It's a bug. It's related to issue 1937. This bug causes that JSF annotations aren't been scanned on non-Glassfish containers, because they accidently included some Glassfish-specific annotation scanning code.

The 2.1.1-b02 is also a development build. Rather use the stable builds. The latest stable is 2.0.4-b09.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文