有了这个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
答案 0 :(得分:1)
这是一个错误。它与issue 1937有关。此错误导致未在非Glassfish容器上扫描JSF注释,因为它们意外地包含了一些特定于Glassfish的注释扫描代码。
2.1.1-b02也是一个开发版本。而是使用稳定版本。最新的稳定点是2.0.4-b09。