Question

I am aware that custom action can be done using following standard way (for jsf 2.1)

<f:metadata>
    <f:viewParam name="query" value="#{bean.query}" />
    <f:event type="preRenderView" listener="#(bean.action}" />
</f:metadata>

Given my request is always GET type, and with url as, /context/page1.xhmtl?query=jsf

can i invoke my custom action in setter method setQuery() instead of listener method setAction() ? Means I will be invoking my action code (such as setting corresponding view bean) in apply model values phase instead of pre render-response phase.

Please share if any downside to this approach, as this is the only way, it is working well in my application setup, and not working properly with prerender listener method.

Update: The reason for my app not working properly with prerender listener method, could be that prerender method is being called after the 'Start' of render-response, not before it. I was expecting to call my prerender listener method, before the start of render-response, ideally at the end of or right after 'invoke application' phase. Does it make sense to expect that way ? as I am thinking it is too late to be called after render response phase start.

Thanks very much.

Was it helpful?

Solution

As per the comments, invoking an Action from the view but as part of the Invoke Application phase can be done with the help of omnifaces' InvokeActionEventListener:

<f:metadata>
  <f:event type="postInvokeAction" listener="#{bean.action}" />
</f:metadata>

When deploying with JSF-2.2 you could also use:

<f:metadata>
  <f:viewAction action="#{bean.action}" />
</f:metadata>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top