Is it necessary to invoke setValid(true) in decode() in a JSF Custom Component?

雨燕双飞 提交于 2020-08-08 06:15:38

问题


While working with a custom component I have the problem, that UIInput#getValid() never resets itself. Question is: do I have to invoke setValid(true) myself during Apply Request Values Phase?

Here are the steps I have done:

  • Create a custom component and inherit from UIInput
  • The component invokes setConverter in the constructor
  • The converter was designed for this component alone and throws a ConverterException if it can't convert from String to the model object
  • There are no validators
  • decode() is overriden, and if FacesContext#isPostback returns true we invoke setSubmittedValue with the request value
  • During render response I check isValid(), it returns true if a ConverterException was thrown, and I can render the response accordingly
  • But: If I submit another correct value the setValid(true) is never called for the custom component

回答1:


The default implementation of UIInput#decode() indeed calls EditableValueHolder#setValid() with true.

So you have 2 options:

  • Simply invoke super.decode(context) in your UIInput#decode() instead of manually grabbing submitted value and invoking setSubmittedValue() with it (because that's already the default behavior of UIInput#decode()).
  • Or, manually invoke setValid(true) in your UIInput#decode() before invoking setSubimttedValue().


来源:https://stackoverflow.com/questions/63068399/is-it-necessary-to-invoke-setvalidtrue-in-decode-in-a-jsf-custom-component

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!