0
votes

I am trying to achieve functionality where I am generating the tabs in according panel dynamically according to the list.

List is of say some object e.g Person

Now attribute corresponding to each person, I am showing in each tab in a form. Values are loaded correctly but when I edit those value I am not getting updated values at the backing bean, I am getting only old values.

Can somebody please explain why ?

Here is the code.

Person Object

public class Person {

    String name;

    //getter setter

    @Override
    public String toString() {
        return name;
    }
}

Backing Bean

@ManagedBean(name = "editor")
public class EditorBean {

    private List<Person> persons = new ArrayList<Person>();

    @PostConstruct
    void init() {
        persons.add(new Person("dhruv"));
        persons.add(new Person("tarun"));
    }

    public void testAction() {
        System.out.println(persons);
    }

    // Getter Setter*****************//
    public List<Person> getPersons() {
        return persons;
    }

    public void setPersons(List<Person> persons) {
        this.persons = persons;
    }
}

XHTML Code:

<html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core"
    xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:p="http://primefaces.org/ui">

<h:head>
</h:head>
<h:body>
    <h1>Hello World PrimeFaces</h1>

    <h:form>
        <p:accordionPanel value="#{editor.persons}" var="person" dynamic="true">

            <p:tab title="#{person}">
                <p:inputText value="#{person.name}"></p:inputText>
            </p:tab>

        </p:accordionPanel>

        <p:commandButton action="#{editor.testAction()}" value="testAction"></p:commandButton>
    </h:form>

</h:body>
</html>

When I run the same with with dynamic="false". This works fine. But in my real scenario I have lots of data which I cannot afford to paint in one go thats why I want to use dynamic = true.

Can somebody explain how to achieve this if not by dynamic = true ??

1
What is the scope of editor?kolossus
I have tried both the scope view and session... I am getting the same resuld in both of these scopesDhruv Bansal

1 Answers

1
votes

The reason you're having stale values in your accordion is that dynamic accordions default to cache="true". This attribute causes the accordion to not reload new/updated values. To cause an ajax refresh on tab open, set cache="false" on your accordion