Make a p:calendar readonly
Solution 1:
The behavior has indeed changed since JSF 2.0. The FacesContext#getRenderResponse()
only returns true
if FacesContext#renderResponse()
is explicitly been called. Previously this happened during restore view phase of every GET request. However, since the introduction of <f:viewParam>
, JSF will not do that anymore when at least one view parameter is present, it will just continue executing every single phase without skipping any phase in order to properly process the view parameters.
You apparently have a <f:viewParam>
in your page. That's totally fine, but as a test, try removing it and you'll see that it returns true
on a plain GET request as well.
You've basically 2 options to get around it:
-
Check the
FacesContext#isPostback()
as well. It always returnsfalse
on GET requests.readonly="#{not facesContext.postback or facesContext.renderResponse}"
-
Check the
FacesContext#getCurrentPhaseId()
instead. You only end up with uglier code (magic numbers).readonly="#{facesContext.currentPhaseId.ordinal eq 6}"
If you're using OmniFaces, you could make it less ugly.
<o:importConstants type="javax.faces.event.PhaseId" /> ... readonly="#{facesContext.currentPhaseId eq PhaseId.RENDER_RESPONSE}"