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:remoteCommand name="tabChanged" action="switchTab"/>

 public void onChange(TabChangeEvent event)
        chosenCategory = (Category)event.getData();

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


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 ()

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"/>
        <evaluate  expression="tabviewBean.fetchCategoriesList(showcaseService)"/>

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

    <end-state id="completeTabViewFlow"/>


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


Return to General