JSF Converter warning

有些话、适合烂在心里 提交于 2019-12-11 05:16:48

问题


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 {

@Override
public Object getAsObject(FacesContext ctx, UIComponent comp, String str) {
    return str.replaceAll("\r\n+", "<br />");
    //return str.replaceAll("\r\n+", "&#13");
}

@Override
public 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...


回答1:


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" />



回答2:


While for this case you don't need to specify a converter in xhtml, the fact that you did this shouldn't cause a warning to display in Eclipse. This is actually a bug in Eclipse. See https://bugs.eclipse.org/bugs/show_bug.cgi?id=357885 for more information. I don't know of a way to hide this specific warning in Eclipse.



来源:https://stackoverflow.com/questions/5135867/jsf-converter-warning

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!