JSF Converter warning

2019-08-15 06:22发布

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...

2条回答
太酷不给撩
2楼-- · 2019-08-15 07:07

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" />
查看更多
爱情/是我丢掉的垃圾
3楼-- · 2019-08-15 07:25

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.

查看更多
登录 后发表回答