I can't update my components when I change the state of selectOneButton component

372 views Asked by At

I'm using primefaces to implement my web site and I'm facing an issue.
I've used selectOneButton component and depending on which button is selected I want to show a specific datatable. So when I click the button1 I want to show table1, and table2 when I click the button2.

This is the code I am using:

<p:selectOneButton 
    value="#{myBean.dataTableType}"
    valueChangeListener="#{myBean.dataTableTypeChange}">
    <f:selectItems value="#{myBean.dataTableTypes}"
        var="type"
        itemLabel="#{msg['datatable.type.'.concat(type)]}"
        itemValue="#{type}" />
    <p:ajax update="table1 table2"/>
</p:selectOneButton>

With this code, I'm unable to reach what I want :(

2

There are 2 answers

0
HAYMbl4 On BEST ANSWER

You should declare an attribute process for ajax with value @this. This attribute say to selectOneButton to set value into bean when will happen some event for selectOneButtton. And you will have an actual value for datatable type.

Now you don't have it. And if you have a condition for example:

<ui:fragment rendered="#{myBean.dataTableType eq FirstTable}">
    <p:datatable id="first_table">
        ...
    </p:datatable>
</ui:framgent>

Condition return false..

2
Siddharth.Singh On

I think you can very well look at the following example and keep a render flag for your tables in the listener invoked in the bean.

https://stackoverflow.com/a/8409360/3403415

Hope it helps!!