2011-03-22 25 views
0

有了這個Maven的依賴,它的工作原理:FacesConverter不能與mojarra 2.1.0-b09,2.1.1-b02一起使用?

<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(); 
    } 
} 

它是一個錯誤,或者在這裏一個錯誤的IM? :-D

回答

1

這是一個錯誤。這與issue 1937有關。此錯誤導致JSF註釋未在非Glassfish容器上掃描,因爲它們意外地包含了一些Glassfish特定的註釋掃描代碼。

2.1.1-b02也是一個開發版本。而是使用穩定的版本。最新的穩定版是2.0.4-b09。

+0

謝謝你解決這個問題。 – bertie 2011-03-22 15:00:16

相關問題