1

Here, it is mentioned by the author.

If it's[COMPONENT] marked valid, then both returns the same value, namely the submitted, converted and validated value.

Consider a very simple snippet:

<h:form>
            <h:inputText value="#{bean.inputValue}" 
                         binding="#{bean.htmlInputText}"      
                         validator="nameValidator" /><br/>
            <h:commandButton value="Submit" action="#{bean.action}" />
</h:form>

with a @RequestScoped backing bean-

public Integer inputValue = 5;
public HtmlInputText htmlInputText;

public void action(){
        System.out.println(" getSubmittedValue() "+htmlInputText.getSubmittedValue());
        System.out.println(" isLocalValueSet() "+ htmlInputText.isLocalValueSet());
        System.out.println(" getValue() " + htmlInputText.getValue());
        System.out.println(" getLocalValue() " +htmlInputText.getLocalValue());
}

On pressing the submit button, output is-

 getSubmittedValue() null    AS EXPECTED, since Conversion & Validation succeded
 isLocalValueSet() false
 getValue() 25               AS EXPECTED, since Conversion & Validation succeded
 getLocalValue() null        Why NULL? IN WHAT CONTEXT HAS THE AUTHOR SAID SO
Community
  • 1
  • 1
Farhan stands with Palestine
  • 13,890
  • 13
  • 58
  • 105

1 Answers1

5

You're checking the local value during invoke application phase.

The local value is cleared out during update model values phase.

The author is talking in context of process validations phase.


To clarify, here's the full process:

RESTORE_VIEW

  • Restore getSubmittedValue(), isValid(), getLocalValue() and isLocalValueSet() from JSF view state, if any.

APPLY_REQUEST_VALUES

  • Do setValid(true) and setSubmittedValue(request.getParameter(getClientId())).

PROCESS_VALIDATIONS

  • Convert/validate getSubmittedValue().
    • If valid, do setValue(convertedAndValidatedValue), setLocalValueSet(true), setSubmittedValue(null). Do note that setValue() effectively behaves as setLocalValue().
    • If invalid, do setValid(false) and skip update model values and invoke application phases.

UPDATE_MODEL_VALUES

  • If valid and local value set, do bean.setProperty(getLocalValue()) and reset getSubmittedValue(), isValid(), getLocalValue() and isLocalValueSet() to their default values of null, false, null and false.

INVOKE_APPLICATION

  • Invoke bean.method().

RENDER_RESPONSE

  • If getSubmittedValue() is not null, render it, else if isLocalValueSet() returns true, render getLocalValue(), else render bean.getProperty().
  • Save getSubmittedValue(), isValid(), getLocalValue() and isLocalValueSet() in JSF view state, if changed.
Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • If validation suceeds, then in 4th phase getSubmittedValue(), isValid(), getLocalValue() and isLocalValueSet() are set to their default values. Why save them in view state if on the next restore view phase, they will be default too. – Farhan stands with Palestine Apr 28 '16 at 15:23
  • An optimal state management implementation indeed won't save them when they're not changed as compared to default values. – BalusC Apr 28 '16 at 21:19
  • You may be getting annoyed since I am asking the things again & again related to just one concept. I raised a question over here http://stackoverflow.com/questions/36917652/why-does-islocalvalueset-returns-true-in-this-case, my confusion being after entering an incorrect value previously being the value was valid, isLocalValueSet() comes out to be true. This is only possible if it was serialised before , saved in the view state with getValue() & getLocalValue() also reflecting the previously enetred values. – Farhan stands with Palestine Apr 29 '16 at 05:15
  • You seem to show no interest at all for the raised question. Believe me I have no other way rather than to request/ consult you. Indeed all the questions I raised here are only due to your presence. I wouldn't raised them if you weren't here. All the senior architects here(in the company) aren't familiar with this. To my knowledge they don't even know a shred as compared to what I know now. Please do tell me whether my latest comment is correct or not, or atleast tell me where I am going wrong. – Farhan stands with Palestine Apr 29 '16 at 14:24
  • I've just other duties :) Answer to your other question is not exactly trivial. I know the answer boils down to a rather trivial "because local value is not null, and because those are saved in view state". But as I don't like oneliner answers, I felt I'd need to explain the why on view state. I couldn't do that in a few paragraphs and I've more important duties today. So only when I've time and mood to write a book chapter, I'll try to think of your question. – BalusC Apr 29 '16 at 14:39
  • I never meant to hurt you by my comment. NEVER. Sometimes, I just go stupid. I am extremely sorry. Never will comment like that. I am SORRY. – Farhan stands with Palestine Apr 29 '16 at 14:52
  • 1
    No problem. I liked your technical curiousity though. That question vote was mine. Your questions are different than those eternal "please debug this code dump for me" questions. You clearly want to learn to fish, not getting fed with fish. – BalusC Apr 29 '16 at 15:01