Very helpful cheat sheet created by BalusC.

1
2
3
4
5
fc = FacesContext
vh = ViewHandler
in = UIInput
rq = HttpServletRequest
id = in.getClientId(fc);

1 RESTORE_VIEW

1
2
String viewId = rq.getServletPath();
fc.setViewRoot(vh.createView(fc, viewId));


2 APPLY_REQUEST_VALUES

1
in.setSubmittedValue(rq.getParameter(id));


3 PROCESS_VALIDATIONS

1
2
3
4
5
6
7
8
9
10
11
12
13
Object value = in.getSubmittedValue();
try {
   value = in.getConvertedValue(fc, value);
   for (Validator v : in.getValidators())
      v.validate(fc, in, value);
   }
   in.setSubmittedValue(null);
   in.setValue(value);
} catch (ConverterException | ValidatorException e) {
   fc.addMessage(id, e.getFacesMessage());
   fc.validationFailed(); // Skips phases 4+5.
   in.setValid(false);
}

4 UPDATE_MODEL_VALUES

1
bean.setProperty(in.getValue());

5 INVOKE_APPLICATION

1
bean.submit();

6 RENDER_RESPONSE

1
vh.renderView(fc, fc.getViewRoot());
Trackback

only 1 comment untill now

  1. Hello!
    This Cheetsheet is very cool! It helped me a lot to understand the JSF Lifecycle, when I was learning JSF. But there is little bug in it. Phase “3 PROCESS_VALIDATIONS” Every validator runs every time, even if some of them fails, all of the run. So let’s catch the ValidatorException inside the for loop:

    Object value = in.getSubmittedValue();
    value = in.getConvertedValue(fc, value);
    for (Validator v : in.getValidators())
    try {
    v.validate(fc, in, value);
    } catch (ValidatorException e) {
    fc.addMessage(id, e.getFacesMessage());
    fc.validationFailed(); // Skips phases 4+5.
    in.setValid(false);
    }
    }
    in.setSubmittedValue(null);
    in.setValue(value);
    } catch (ConverterException e) {
    fc.addMessage(id, e.getFacesMessage());
    fc.validationFailed(); // Skips phases 4+5.
    in.setValid(false);
    }

Add your comment now