DataScroller with SelectBooleanCheckbox: Initial checked value is overwritten for loaded chunks during first decode
See original GitHub issueDescribe the defect If I create a datascroller with a list of items, that have a boolean value that is initially true and bound to a p:selectBooleanCheckbox within the datascroller, the checkbox is checked for entries that are initially dispayed (ok) but for additionally loaded elements due to scrolling the checkbox is not checked anymore.
Reproducer primefaces-test.zip
Environment:
- PF Version: 10.0.0.RC1
- JSF + version: Mojarra 2.2.8
- Affected browsers: ALL
To Reproduce Steps to reproduce the behavior:
- Go to test page in attached primefaces-test
- Scroll down until additional entries are loaded
- See error (additional entry index>5 have an unchecked checkbox)
Expected behavior All checkboxes should be checked according to data in Model.
Possible Reason for that: The problem is related to the fact that in SelectBooleanCheckboxRenderer.decode and submittedValue of null is interpreted as “false” and set on the underlying model. For lazy loaded chunk this seems to be executed during the ajax loadChunks call and since the new elements were just yet added their is not value in the requestparameter map for them. Other Input Forms (e.g inputtext) for fine because their just skip the updatemodel phase if submited value == null.
Example XHTML
<h:form id="frmTest">
<p:dataScroller var="_item" value="#{testView.model}" chunkSize="5" >
<div style="height:300px">
<p:inputText value="#{_item.text}" />
<p:selectBooleanCheckbox value="#{_item.check}"/> This checkbox should always be checked, but as soon as new chunk is loaded it is not.
</div>
</p:dataScroller>
</h:form>
Example Bean
@Data
@Named
@ViewScoped
public class TestView implements Serializable {
private static final long serialVersionUID = 1L;
private ListDataModel<Item> model = new ListDataModel<>();
@Data
public static class Item implements Serializable {
private static final long serialVersionUID = 1L;
private String text;
private boolean check=true;
public Item(String text) {
super();
this.text = text;
}
}
@PostConstruct
public void init() {
List<Item> list = new ArrayList<>();
for (int i =0; i<50; i++) {
list.add(new Item("Text "+i));
}
model = new ListDataModel<>(list);
}
public ListDataModel<Item> getModel() {
return model;
}
}
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (5 by maintainers)
Top GitHub Comments
I working on a fix, to skip the update phases for newly loaded children in these load reqeust, but not sure whether I’m on the right track, we will see…
still struggeling with github PRs 😉 but there should be one now at https://github.com/primefaces/primefaces/pull/7010