您的特定问题是由
<context-param> <param-name>javax.faces.INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_NULL</param-name> <param-value>true</param-value></context-param>
以及
HtmlBasicRenderer#getCurrentValue()Mojarra 的错误(至少是疏忽):
if (component instanceof UIInput) { Object submittedValue = ((UIInput) component).getSubmittedValue(); if (submittedValue != null) { // value may not be a String... return submittedValue.toString(); }}String currentValue = null;Object currentObj = getValue(component);if (currentObj != null) { currentValue = getFormattedValue(context, component, currentObj);}return currentValue;通常情况下,所提交的值被设置为
null当所述
UIInput组件被成功地转换和验证。当JSF将要重新显示值时,它会先检查提交的值是否不是,
null然后再重新显示模型值。但是,使用此上下文参数
null时,它在无效时将代替空字符串,因此当您删除必填字段的初始值时,它将始终重新显示原始模型值。
要对其进行测试,请将该上下文参数值设置为
false或将其完全删除。您会看到它按预期工作。但是,这将带来缺点,即模型值将在空的但不是必需的字段上被空字符串弄乱,并且您将失去使用
@NotNullJSR
303 bean验证注释的优势。
要解决此问题,您必须
HtmlBasicRenderer#getCurrentValue()按如下所示更改第一部分:
if (component instanceof UIInput && !((UIInput) component).isValid()) { Object submittedValue = ((UIInput) component).getSubmittedValue(); if (submittedValue != null) { // value may not be a String... return submittedValue.toString(); } else { return null; }}我已经把它报告给Mojarra了,发行号为2262。



