How to handle p:ajax event

UI Components for JSF
alekss
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:tabView>

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

ShowcaseBean:

Code: Select all

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

my-flow.xml

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

Code: Select all

<script type="text/javascript">
           window.onload = function ()
           {
               updateTabs();
           }
        </script>

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.

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

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 21 guests