1
我对JSF中的submittedValue
和value
有些困惑。当存在转换器/验证错误时,显示哪个值?哪个类包含提交值与模型值的呈现逻辑?
Jsf life cycle - render response after validation failure
从BalusC在上述问题的答案,我可以找到答案。但是,我想知道在渲染逻辑存在于哪个类中时,如果提交的值为null,则渲染模型值。它是哪一类?
我对JSF中的submittedValue
和value
有些困惑。当存在转换器/验证错误时,显示哪个值?哪个类包含提交值与模型值的呈现逻辑?
Jsf life cycle - render response after validation failure
从BalusC在上述问题的答案,我可以找到答案。但是,我想知道在渲染逻辑存在于哪个类中时,如果提交的值为null,则渲染模型值。它是哪一类?
我想知道在哪个班这种渲染逻辑存在,该模型值渲染时提交值为null
你没有任何地方告诉正在使用的JSF实现。在这个答案中,我会假设它是Mojarra。在这种情况下,它在HtmlBasicRenderer#getCurrentValue()
中完成。以下是来自Mojarra 1.2_15的相关摘录。
275 protected String getCurrentValue(FacesContext context,
276 UIComponent component) {
277
278 if (component instanceof UIInput) {
279 Object submittedValue = ((UIInput) component).getSubmittedValue();
280 if (submittedValue != null) {
281 // may not be a String...
282 return submittedValue.toString();
283 }
284 }
285
286 String currentValue = null;
287 Object currentObj = getValue(component);
288 if (currentObj != null) {
289 currentValue = getFormattedValue(context, component, currentObj);
290 }
291 return currentValue;
292
293 }
代码可以说明问题。如果该组件是UIInput
的实例,则获取其提交的值。如果它不是null
,则返回它。否则,按照常规方式继续返回模型值。
MyFaces使用类似的方法。
感谢BalusC,您的支持是非常有帮助的。 – RaoPotla
不客气。 – BalusC