jsf自定义转换器 [英] jsf custom converter
问题描述
我是jsf 2.0和spring 3.0的新手,我要求在jsf 2.0中使用自定义转换器.但是当我访问我的xhtml页面时,它却显示出异常,无法识别 未找到命名对象".我已经为自定义转换器使用了@FacesConverter批注,它在h:selectOneMenu中使用.但是我遇到了错误.在此方面有什么帮助吗?
I'm new to jsf 2.0 and spring 3.0 , i have a requirement to use custom converter in jsf 2.0.But it is not recognized,when i access my xhtml page it is showing an exception "Named object not found" .I had used @FacesConverter annotation for the custom converter and it is using in the h:selectOneMenu.But i'm getting the error.could any one help in this...
@FacesConverter("selectItemsConverter")
public class SelectItemsConverter implements Converter {
public Object getAsObject(FacesContext context, UIComponent component, String value) {
}
public String getAsString(FacesContext context, UIComponent component, Object value) {
}
}
h:selectOne菜单代码如下:
h:selectOne Menu code is as follows:
<h:selectOneMenu style="width:100px;height:24px;" rendered ="#{row.edit}" value="#{row.modelo.country}" converter="selectItemsConverter" required="true" requiredMessage="#{msg['veci.admin.ccaa.pais.empty']}">
<f:selectItems value="#{communityView.countries}" var="con" itemLabel="#{con.nombrePais}"/>
</h:selectOneMenu>
谢谢大家……..
推荐答案
如果要通过ConverterID调用转换器,则需要按以下方式更改代码:
If you want to call the converter by its converterID you need to change your code as follows:
<h:selectOneMenu style="width:100px;height:24px;"
rendered ="#{row.edit}"
value="#{row.modelo.country}"
required="true"
requiredMessage="#{msg['veci.admin.ccaa.pais.empty']}">
<f:converter converterId="selectItemsConverter"/>
<f:selectItems .../>
</h:selectOneMenu>
h:selectOneMenu
的转换器属性需要一个完全限定的类名称,例如:
The converter attribute of the h:selectOneMenu
needs a fully qualified class name such as:
<h:inputText
converter="javax.faces.convert.IntegerConverter" />
如果要为转换器提供自定义ID,请使用value
参数:
If you want to give your converter a custom id use the value
parameter:
@FacesConverter(value="selectItemsConverter")
这篇关于jsf自定义转换器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!