JSF Converter警告 [英] JSF Converter warning

查看:121
本文介绍了JSF Converter警告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从我的xhtml文件中:

<h:inputTextarea value="#{newPostForm.post.body}">
     <f:converter converterId="NL2BRConverter" />
</h:inputTextarea>

从我的Java文件中:

@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在我的xhtml文件中警告我'NL2BRConverter'converterID未注册.

我尝试用

替换转换器注释

@FacesConverter("NL2BRConverter")

,但错误仍然存​​在.在JSF2.0中注册转换器是否还不够?

当前,如果我在XHTML文件中使用完整的类名"com.tracker.converter.NL2BRConverter"作为带注释的名称和converterID,则它可以正常工作.但是我仍然收到该警告...

解决方案

您不需要<f:converter>,因为forClass=String.class已明确声明您的转换器可以在每种String输入类型上运行.

如果您的 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 {

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

解决方案

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警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆