How to handle p:ajax event

Components, Ajax Framework, Utilities and More.
Posts: 10
Joined: 05 Feb 2012, 22:27

19 Feb 2012, 21:17

This is solution.
write in showcase.xhtml

Code: Select all

<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"/>


Code: Select all

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


Code: Select all

<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

Code: Select all

<script type="text/javascript">
           window.onload = function ()

and this updateTabs() invokes

Code: Select all

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

Posts: 10
Joined: 05 Feb 2012, 22:27

19 Feb 2012, 21:24

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

Code: Select all

<?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.

Post Reply
  • Information
  • Who is online

    Users browsing this forum: Google [Bot] and 28 guests