FacesConverter 无法与 mojarra 2.1.0-b09、2.1.1-b02 配合使用?
有了这个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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是一个错误。它与问题 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.