我需要的人在使用JSF提交空字段时收到null:
我的班级:
@RequestScoped
@ManagedBean(name = "teste")
public class Teste {
private Double valor;
public Double getValor() {
return valor;
}
public void setValor(Double valor) {
this.valor = valor;
}
}
和我的编辑文字元素:
<h:inputText value = "#{teste.nota}" converter="notaConverter">
<h:inputText>
我的转换器:
@FacesConverter(forClass = Long.class, value = "notaConverter")
public class NotaConverter implements Converter {
public NotaConverter() {}
@Override
public String getAsString(FacesContext arg0, UIComponent arg1, Object value) {
return value == null ? null : value.toString();
}
@Override
public Object getAsObject(FacesContext arg0, UIComponent arg1, String value) {
if (value == null || value.isEmpty()) return null;
Double valor = new Double(value);
return valor;
}
}
但是当我调用托管bean的集合时,我收到'0.00'值。为什么?
答案 0 :(得分:0)
添加到web.xml
<context-param>
<param-name>javax.faces.INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_NULL</param-name>
<param-value>true</param-value>
</context-param>