1

I have a datatable that has a collection of objects that is initialized on page load. It is not lazy loaded.

In this datatable row, I have a row expansion object that I wish to "toggle" depending on a boolean value for the object in that row (inputSwitch tag in Primefaces). Once that is toggled, I update the DOM and render the sub collection using the "rendered" attribute for the rowExpansion (which I suspect might be the problem, because I think that requires a DOM refresh)

However, whenever I hit the first inputSwitch (the main toggle), it reloads the entire collection and wipes out the changes that have been made.

                                    <p:dataTable 
                                        id="myTable"
                                        var="row" 
                                        reflow="true"
                                        expandedRow="true"
                                        filteredValue="#{mybean.filteredAllObjects}"
                                        value="#{mybean.allObjects}">

                                        <p:column>
                                            <p:inputSwitch value="#{row.boolSelected}">
                                                <p:ajax update=":myform:myTable"/>
                                            </p:inputSwitch>
                                        </p:column>
                                        
                                        <p:rowExpansion rendered="#{row.boolSelected}">
                                            <ui:repeat value="#{row.subsetCollection}" var="subsetRow">
                                                        <p:inputSwitch value="#{subsetRow.boolSelected}"/>
                                            </ui:repeat>
                                        </p:rowExpansion>
                                    </p:dataTable>

How can I essentially keep the state of the collection on the client side without the need to re-render the collection (and thus eliminating all changes)?

Edit

Backing bean (simplified - it's really this simplistic). When the ajax call is made in the front end, the getter for the collection is called (breakpoint confirms this). Also see a POST is happening, so a call to the server is made:

@Component
@ViewScoped
public class MyBean implements Serializable 
{
    private static final long serialVersionUID = 1L;

    private List<MyObject> allObjects;
    private List<MyObject> filteredAllObjects;

    public MyBean(@Value("#{param['id']}") String selectedId) 
    {
        init();
    }

    private void init()
    {
        allObjects = ... // call to get objects from DB
    }

    // Setters & Getters

}

StaticMaine
  • 47
  • 10

0 Answers0