1

i wish to display 2 different datatables in each tab of the tabview of primefaces 3.2. there datatables will fetch data based on the 'type' variable set in the onChange event. but my problem is that the onChange event does not fire at all. pls check my tabview code to check why this is happening:

<h:form id="frm">
        <p:tabView activeIndex="#{equityBean.activeIndex}">
            <p:ajax event="tabChange" listener="#{equityBean.onChange}" update=":frm"/>
            <p:tab title="NSE" binding="#{equityBean.tbn}">


                <p:dataTable binding="#{equityBean.dt}" value="#{equityBean.scripList}" var="scrip">
                    <f:facet name="header">
                Scrip Symbol
            </f:facet>
                <h:outputText value="#{scrip.scripSymbol}"/>
                <f:facet name="header">
                Company Name
            </f:facet>
                <h:outputText value="#{scrip.companyName}"/>
                <f:facet name="header">
                Volume
            </f:facet>
                <h:outputText value="#{scrip.totalTradedVolume}"/>
                </p:dataTable>
            </p:tab>
            <p:tab title="BSE" binding="#{equityBean.tb}">

            </p:tab>
        </p:tabView>
    </h:form>

bean:

public void onChange(TabChangeEvent event) {
type=event.getTab().getTitle();
}

edited: bean code to get datatable value:

public List<MasterScrip> getScripList() {
    scripList=new ArrayList<MasterScrip> ();
 scripList=getScripByVolumeType(type);
    return scripList;
}
private java.util.List<service.MasterScrip> getScripByVolumeType(java.lang.String type) {
    service.StatelessWebService port = service.getStatelessWebServicePort();
    return port.getScripByVolumeType(type);
}

edited : jpa query

public Collection<MasterScrip> getScripByVolumeType(String type)

{ Collection sm=null;

     sm=em.createQuery("select m from MasterScrip m where m.type = :type order by m.totalTradedVolume").setParameter("type", type).setMaxResults(2).getResultList(); // retuens no records
       return sm;
   }

records are returned but not displayed..

why does this happen? where am i wrong?

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
z22
  • 10,013
  • 17
  • 70
  • 126

1 Answers1

2

Your mistake is here.

listener="#{equityBean.onChange(event)}"

The event object does not exist in EL scope. Remove the argument. You don't need to specify it at all. JSF will supply the necessary action listener argument itself.

listener="#{equityBean.onChange}"

The same is true for all other listener and actionListener attributes. Only in action attribute of UICommand components you can specify custom arguments (which should be passed with real values, not with some random and non-existent variable name).

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • did so(edited the question) still not working, i debugged and found that the event is never executed, instead it goes to get the datatable value(edited in question) and keeps on getting it resulting in an infinite debugging loop – z22 May 24 '12 at 05:01
  • 1
    It's normal that the getter is called everytime the EL expression is evaluated (you should *now* have light bulb above your head which tells that it's really a [bad idea](http://stackoverflow.com/questions/2090033/why-jsf-calls-getters-multiple-times/2090062#2090062) to do business logic in a getter method!). But this is unrelated to your tab change problem. Or does it get solved if you remove the `` altogether? By the way, I find those `binding` attributes fishy. I won't be surprised if they actually caused the concrete problem after all. – BalusC May 24 '12 at 05:04
  • hanks BalusC! i went to the end of the never ending getter loop(yes it really is a bad idea to code inside the getter) the jpa query is returning the records but the records are not displayed in the datatable... – z22 May 24 '12 at 05:24
  • This issue doesn't seem to be related to the tab change listener not being invoked. Or does it get invoked if you remove the `` altogether? – BalusC May 24 '12 at 05:27
  • yes the tabChange listener is invoked now(my mistake), but the datatable is not filled, i removed the binding attributes, still not working – z22 May 24 '12 at 05:35
  • 1
    Okay. If you need to continue on the new question/problem, please post a new question instead of using the comments of an already-answered question for this :) Do not mix different questions/problems in a single question. – BalusC May 24 '12 at 05:36
  • thanks mate.. i should be slapped for my silly mistake...everything's working now...i forgot the in the datatable. and will keep in mind to start a new thread for new question :) – z22 May 24 '12 at 05:43