JSF getValue() v.s. getSubmittedValue()

前端 未结 4 1456
一整个雨季
一整个雨季 2020-12-09 09:06

I\'ve been developing a few JSF applications lately and am disturbed with the inconsistency in the web component APIs.

I\'ve noticed that there is extremely unpredi

4条回答
  •  感情败类
    2020-12-09 09:45

    TL;DR answer:

    UIViewRoot viewRoot = context.getViewRoot();
    UIInput input = (UIInput)viewRoot.findComponent(":form:inputID");
    
    String inputValueString;
    
    if (input.isLocalValueSet()) {
      inputValueString = (String)input.getValue(); //validated and converted already
    } else {
      inputValueString = (String)input.getSubmittedValue(); //raw input
    }
    

    or at least that's what the other answers are saying to do...

    Just use .getSubmittedValue() and deal with the consequences of having to convert raw input (if necessary, if that raw input needs conversion). .getValue() is broken in this regard, even with the code above. It delays the submitted value if you use it and that's unacceptable.

提交回复
热议问题