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
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.
精彩评论