Board index JavaServer Faces General How to handle p:ajax event

How to handle p:ajax event

Components, Ajax Framework, Utilities and More.

Post 19 Feb 2012, 21:17

Posts: 10
This is solution.
write in showcase.xhtml

<h:form id="articlesForm">
          <p:tabView id="tabView" var="category" value="#{showcaseBean.categories}" onTabChange="tabChanged()">
           <p:ajax event="tabChange" listener="#{showcaseBean.onChange}" />
...
</p:tabView>

<p:remoteCommand name="tabChanged" action="switchTab"/>



ShowcaseBean:
 public void onChange(TabChangeEvent event)
    {
        chosenCategory = (Category)event.getData();
    }



my-flow.xml
<var name="showcaseBean" class="my.backing.ShowcaseBean"/>
    <view-state id="showcase" view="showcase.xhtml" >
       
     <transition on="switchTab">
         <evaluate expression="showcaseBean.fetchArticlesForChosenCategory(showcaseService)"/>
     </transition>

   </view-state>



So I can translate any event on page to 'action' for web-flow file through <p:remoteCommand and Javascript method
Foe example we need to read data from database on page start. So we can add
<script type="text/javascript">
           window.onload = function ()
           {
               updateTabs();
           }
        </script>



and this updateTabs() invokes
<p:remoteCommand name="updateTabs" action="actionForMyFlowDefinitionFile"/>
Last edited by alekss on 19 Feb 2012, 22:05, edited 1 time in total.

Post 19 Feb 2012, 21:24

Posts: 10
But I found later that I can use the events in flow definition file.
So it works properly in such way:

<?xml version="1.0" encoding="UTF-8"?>
<flow ..>
    <var name="tabviewBean" class="my.backing.TabviewBean"/>
     <on-start>
        <evaluate  expression="tabviewBean.fetchCategoriesList(showcaseService)"/>
    </on-start>

    <view-state id="tabView" view="tabView.xhtml" >
        <on-render>
            <evaluate expression="tabviewBean.fetchArticlesForChosenCategory(showcaseService)"/>
        </on-render>
    </view-state>

    <end-state id="completeTabViewFlow"/>

</flow>


showcaseService - it's a Spring @Service("showcaseService") that is registered in Spring configuration file.
TabviewBean - it's a backing bean.

Previous

Return to General