如果您的 actual 意图是自己针对视图中的特定输入字段显式声明它,那么您应该改为使用@FacesConverter(value="NL2BRConverter")然后您就可以使用<f:converter converterId="NL2BRConverter" />From my xhtml file:<h:inputTextarea value="#{newPostForm.post.body}"> <f:converter converterId="NL2BRConverter" /></h:inputTextarea>From my java file:@FacesConverter(forClass=String.class)public class NL2BRConverter implements Converter {@Overridepublic Object getAsObject(FacesContext ctx, UIComponent comp, String str) { return str.replaceAll("\r\n+", "<br />"); //return str.replaceAll("\r\n+", "&#13");}@Overridepublic String getAsString(FacesContext ctx, UIComponent comp, Object obj) { return obj.toString();}}Eclipse is giving me a warning in my xhtml file that 'NL2BRConverter' converterID is not registered.I've tried replacing the converter annotation with @FacesConverter("NL2BRConverter")but the error persists. Is this not sufficient to register a converter in JSF2.0 ?Currently if I used the full class name "com.tracker.converter.NL2BRConverter" as the annotated name and the converterID in my XHTML files, it works. I still get that warning however... 解决方案 You don't need a <f:converter> because your converter is already explicitly been declared by forClass=String.class to run on every String input type.If your actual intent is to declare it explicitly for specific input fields in the view yourself, then you should instead be using@FacesConverter(value="NL2BRConverter")Then you can use<f:converter converterId="NL2BRConverter" /> 这篇关于JSF Converter警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-14 20:24