Search code examples
primefacesspring-webflow

How to handle Primefaces p:ajax event in Spring Web Flow


Is there an 'elegant' way to have SWF respond to Primefaces Ajax event? Like the following:

<p:dataTable id="myDT" value="#{myList}" var="listVal">
<p:ajax event="rowToggle" update="expandedText" />  
<p:rowToggler>
<h:outputText id="expandedText" value="#{listVal.someText}"/>
</p:rowToggler>
</p:dataTable>

It would be ideal if I could have it trigger SWF action in my view and render appropriate fragment:

<view-state id="myView" view="myview.xhtml">
<transition on="myDT:rowToggle"  to="showRowContents" >
<render fragments="expandedText"/>
</transition>

Right now the only workaround I know of is to have Ajax event call RemoteCommand:

<p:dataTable id="myDT" value="#{myList}" var="listVal">
<p:remoteCommand name="rowToggleCommand" action="rowToggle"  update="expandedText"/>
<p:ajax event="rowToggle" oncomplete="rowToggleCommand()" />  
<p:rowToggler>
<h:outputText id="expandedText" value="#{listVal.someText}"/>
</p:rowToggler>
</p:dataTable>

I find the workaround somewhat ugly, and it also results in two Ajax requests instead of one. I believe it may be possible to patch SWF side to respond to such Ajax events but dont know where to start.


Solution

  • After mucho research I have understood this is not possible. SWF architecture does not easily allow for responding to such events. You can still invoke bean method on Ajax event, and any Facelets components responsible for their own partial rendering will respond to Ajax events properly if you put this fix in place: http://static.springsource.org/spring-webflow/docs/2.3.x/reference/html/ch13s10.html

    See also my other question on the same subject: Primefaces RowEditor does not work with Spring Webflow

    Any SWF-related actions have to be invoked by Primefaces RemoteCommand component or likes (CommandButton etc etc)