Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DataTable: selected item remains current, even after building a new data source #8021

Closed
HolgerSuhr opened this issue Oct 26, 2021 · 1 comment
Labels
10.0.6 🚫 duplicate Duplicate of a similar issue
Milestone

Comments

@HolgerSuhr
Copy link

HolgerSuhr commented Oct 26, 2021

I use a data table for showing selected items. The table is reused for multiple selections.

When another selection is started, the data collection (ArrayList) is rebuilt and the item holding
the current selected row is set to null.

The data table shows a selected row if the rowKey of any previous selection can be found in this list.

It is not sufficient to set the variable holding the selection to null.
I have to set this variable to a dummy value to clear the selected row in my new data table.

Environment:

  • PF Version: 10.0.0
  • Mojarra 2.3.14

Expected behavior
With building a new data source and clearing the current-row-item, there should not be shown a selected row.

Example XHTML

  <h:form>
    <p:dataTable value="#{test.data}" var="item" rowKey="#{item.id}" selectionMode="single" selection="#{test.current}">
      <p:ajax event="rowSelect" partialSubmit="true" process="@this" update="@form" />
      <p:column>#{item.id}</p:column>
      <p:column>#{test.current == null ? 'null' : test.current.id}</p:column>
      <p:column>#{item.text}</p:column>
    </p:dataTable>
    <p:commandButton value="Update" ajax="true" process="@this" update="@form"/>
    <p:commandButton value="New" ajax="true" process="@this" update="@form" actionListener="#{test.clear()}"/>
    <p:commandButton value="Clear" ajax="true" process="@this" update="@form" actionListener="#{test.setDummy()}"/>
  </h:form>

Example Bean

@Named
@ViewScoped
public class Test implements Serializable {
  private static final String src = "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut";

  private List<TestObj> data = null;
  private TestObj current = null;
  private final Random rand = new Random();

  public void clear() {
    data = null;
  }
  public List<TestObj> getData() {
    return data == null ? newData() : data;
  }
  public TestObj getCurrent() {
    return current;
  }
  public void setCurrent(TestObj o) {
    current = o; 
  }
  private List<TestObj> newData() {
    current = null;
    data = new ArrayList<>();
    for(int i=0; i<10 ; i++) {
      int off = rand.nextInt(src.length()-20);
      data.add(new TestObj(i, src.substring(off, off+20)));
    }
    return data;  
  }
  public void setDummy() {
    current = new TestObj(-1, "dummy");
  }
  public class TestObj {
    private final int id;
    private final String text;
    public TestObj(int n, String t) { id=n; text = t; }
    public int getId() { return id; }
    public String getText() { return text; }
  }
}
@HolgerSuhr HolgerSuhr added the 🐞 defect Bug...Something isn't working label Oct 26, 2021
@melloware
Copy link
Member

Can you try 11.0.0-RC1 i believe this is already fixed. Duplicate of: #7391

@melloware melloware added 🚫 duplicate Duplicate of a similar issue and removed 🐞 defect Bug...Something isn't working labels Oct 26, 2021
@melloware melloware added this to the 11.0.0-RC1 milestone Oct 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
10.0.6 🚫 duplicate Duplicate of a similar issue
Projects
None yet
Development

No branches or pull requests

2 participants