Environment: JSF 2.2 with Mojarra 2.2.12 & CDI ViewScoped beans & javax.faces.STATE_SAVING_METHOD
set to client
.
In order to properly initialize my bean thanks to <f:viewParam ... />
, I would like to (re-)execute <f:viewAction action="#{bean.onLoad}" />
when my ViewScoped
bean is recreated (view was pushed out from the LRU, cf. com.sun.faces.numberOfLogicalViews) following a POST request.
<f:metadata>
<f:viewParam maxlength="100" name="name" value="#{bean.file}" />
<f:viewAction action="#{bean.onLoad}" />
</f:metadata>
<o:form includeRequestParams="true">
<!-- action can only work if onLoad has been called -->
<p:commandButton action="#{bean.action}" />
</o:form>
Any ideas?
Notes:
- I'm aware of
postBack="true"
but it's not suitable asbean.onLoad()
would be called on every POST request. - I cannot call
onLoad()
in@PostConstruct
method because values have not been set byviewParam
yet (cf. When to use f:viewAction versus PostConstruct?).