Skip to content

Commit 83700b1

Browse files
committed
fix(columnSelector): immediate, selection lost
* add test / adjust tests * fix: always write selectedListString Issue: TOBAGO-2476
1 parent b488aaa commit 83700b1

File tree

5 files changed

+67
-20
lines changed

5 files changed

+67
-20
lines changed

tobago-core/src/main/java/org/apache/myfaces/tobago/internal/renderkit/renderer/SheetRenderer.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,9 +173,8 @@ public void decodeInternal(final FacesContext facesContext, final T component) {
173173
}
174174
component.queueEvent(new SheetRowSelectionChangeEvent(component, sourceId, oldSelectedRows, selectedRows));
175175
}
176-
} else {
177-
ComponentUtils.setAttribute(component, Attributes.selectedListString, selectedRows);
178176
}
177+
ComponentUtils.setAttribute(component, Attributes.selectedListString, selectedRows);
179178
}
180179

181180
if (component.isLazy()) {

tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/test/sheet/ColumnSelectorAjaxController.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,17 +48,19 @@ public class ColumnSelectorAjaxController implements Serializable {
4848
private SheetState sheetState = new SheetState(0);
4949
private boolean columnSelectorImmediate = false;
5050
private boolean columnSelectorAjaxDisabled = false;
51+
private boolean inRequired = false;
5152
private int savedSelectedRows = 0;
5253

5354
@PostConstruct
5455
private void init() {
5556
solarList = astroData.findAll().collect(Collectors.toList());
5657
}
5758

58-
public void reset(boolean immediate, boolean ajaxDisabled) {
59+
public void reset(boolean immediate, boolean ajaxDisabled, boolean inputRequired) {
5960
sheetState = new SheetState(0);
6061
columnSelectorImmediate = immediate;
6162
columnSelectorAjaxDisabled = ajaxDisabled;
63+
inRequired = inputRequired;
6264
}
6365

6466
public List<SolarObject> getSolarList() {
@@ -93,6 +95,14 @@ public void setColumnSelectorAjaxDisabled(boolean columnSelectorAjaxDisabled) {
9395
this.columnSelectorAjaxDisabled = columnSelectorAjaxDisabled;
9496
}
9597

98+
public boolean isInRequired() {
99+
return inRequired;
100+
}
101+
102+
public void setInRequired(boolean inRequired) {
103+
this.inRequired = inRequired;
104+
}
105+
96106
public void saveSelectedRows() {
97107
savedSelectedRows = sheetState.getSelectedRows().size();
98108
}

tobago-example/tobago-example-demo/src/main/webapp/content/900-test/sheet/columnSelector/immediate/immediate.xhtml

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,21 @@
2525
xmlns:tc="http://myfaces.apache.org/tobago/component"
2626
xmlns:ui="jakarta.faces.facelets">
2727

28-
<tc:button id="resetImmediateTrueAjaxEnabled" label="Reset immediate=true ajax=enabled" immediate="true"
29-
action="#{columnSelectorAjaxController.reset(true, false)}"/>
30-
<tc:button id="resetImmediateTrueAjaxDisabled" label="Reset immediate=true ajax=disabled" immediate="true"
31-
action="#{columnSelectorAjaxController.reset(true, true)}"/>
32-
<tc:button id="resetImmediateFalseAjaxEnabled" label="Reset immediate=false ajax=enabled" immediate="true"
33-
action="#{columnSelectorAjaxController.reset(false, false)}"/>
34-
<tc:button id="resetImmediateFalseAjaxDisabled" label="Reset immediate=false ajax=disabled" immediate="true"
35-
action="#{columnSelectorAjaxController.reset(false, true)}"/>
28+
<tc:button id="resetImmediateTrueAjaxEnabled" label="Reset immediate=true ajax=enabled input=required"
29+
immediate="true" action="#{columnSelectorAjaxController.reset(true, false, true)}"/>
30+
<tc:button id="resetImmediateTrueAjaxDisabled" label="Reset immediate=true ajax=disabled input=required"
31+
immediate="true" action="#{columnSelectorAjaxController.reset(true, true, true)}"/>
32+
<tc:button id="resetImmediateFalseAjaxEnabled" label="Reset immediate=false ajax=enabled input=required"
33+
immediate="true" action="#{columnSelectorAjaxController.reset(false, false, true)}"/>
34+
<tc:button id="resetImmediateFalseAjaxDisabled" label="Reset immediate=false ajax=disabled input=required"
35+
immediate="true" action="#{columnSelectorAjaxController.reset(false, true, true)}"/>
36+
<tc:button id="resetImmediateTrueAjaxDisabledInputOptional"
37+
label="Reset immediate=true ajax=disabled input=optional"
38+
immediate="true" action="#{columnSelectorAjaxController.reset(true, true, false)}"/>
3639

3740
<tc:out label="immediate" value="#{columnSelectorAjaxController.columnSelectorImmediate}"/>
3841
<tc:out label="f:ajax" value="#{columnSelectorAjaxController.columnSelectorAjaxDisabled ? 'disabled' : 'enabled'}"/>
42+
<tc:out label="input" value="#{columnSelectorAjaxController.inRequired ? 'required' : 'optional'}"/>
3943

4044
<tc:sheet id="sheet" value="#{columnSelectorAjaxController.solarList}" var="object" rows="5"
4145
state="#{columnSelectorAjaxController.sheetState}" selectable="multi">
@@ -56,7 +60,7 @@
5660
<tc:out value="#{object.discoverer}" autoSpacing="false"/>
5761
</tc:column>
5862
<tc:column label="Required">
59-
<tc:in required="true">
63+
<tc:in required="#{columnSelectorAjaxController.inRequired}">
6064
<tc:event event="click" stopPropagation="true" omit="true"/>
6165
</tc:in>
6266
</tc:column>

tobago-example/tobago-example-demo/src/main/webapp/resources/demo-components/columnSelectorImmediate.xhtml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@
2626
</cc:interface>
2727
<cc:implementation>
2828
<tc:button id="resetImmediateTrueAjaxEnabled" label="Reset immediate=true ajax=enabled" immediate="true"
29-
action="#{cc.attrs.columnSelectorAjaxController.reset(true, false)}"/>
29+
action="#{cc.attrs.columnSelectorAjaxController.reset(true, false, true)}"/>
3030
<tc:button id="resetImmediateTrueAjaxDisabled" label="Reset immediate=true ajax=disabled" immediate="true"
31-
action="#{cc.attrs.columnSelectorAjaxController.reset(true, true)}"/>
31+
action="#{cc.attrs.columnSelectorAjaxController.reset(true, true, true)}"/>
3232
<tc:button id="resetImmediateFalseAjaxEnabled" label="Reset immediate=false ajax=enabled" immediate="true"
33-
action="#{cc.attrs.columnSelectorAjaxController.reset(false, false)}"/>
33+
action="#{cc.attrs.columnSelectorAjaxController.reset(false, false, true)}"/>
3434
<tc:button id="resetImmediateFalseAjaxDisabled" label="Reset immediate=false ajax=disabled" immediate="true"
35-
action="#{cc.attrs.columnSelectorAjaxController.reset(false, true)}"/>
35+
action="#{cc.attrs.columnSelectorAjaxController.reset(false, true, true)}"/>
3636

3737
<tc:out label="immediate" value="#{cc.attrs.columnSelectorAjaxController.columnSelectorImmediate}"/>
3838
<tc:out label="f:ajax"

tobago-example/tobago-example-demo/src/test/typescript/columnSelector.test.ts

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ test.describe("sheet/columnSelector/immediate/immediate.xhtml", () => {
364364
await page.goto("/content/900-test/sheet/columnSelector/immediate/immediate.xhtml");
365365
});
366366

367-
test("immediate=true, ajax=enabled", async ({page}) => {
367+
test("immediate=true, ajax=enabled, input=required", async ({page}) => {
368368
const alert = page.locator("tobago-messages[id='page:messages'] .alert");
369369
const reset = page.locator(".tobago-button[id='page:mainForm:resetImmediateTrueAjaxEnabled']");
370370
const sheet = page.locator("tobago-sheet[id='page:mainForm:sheet']");
@@ -396,7 +396,7 @@ test.describe("sheet/columnSelector/immediate/immediate.xhtml", () => {
396396
await expect(alert).not.toBeVisible();
397397
});
398398

399-
test("immediate=true, ajax=disabled", async ({page}) => {
399+
test("immediate=true, ajax=disabled, input=required", async ({page}) => {
400400
const alert = page.locator("tobago-messages[id='page:messages'] .alert");
401401
const reset = page.locator(".tobago-button[id='page:mainForm:resetImmediateTrueAjaxDisabled']");
402402
const sheet = page.locator("tobago-sheet[id='page:mainForm:sheet']");
@@ -436,7 +436,7 @@ test.describe("sheet/columnSelector/immediate/immediate.xhtml", () => {
436436
await expect(alert).toBeVisible();
437437
});
438438

439-
test("immediate=false, ajax=enabled", async ({page}) => {
439+
test("immediate=false, ajax=enabled, input=required", async ({page}) => {
440440
const alert = page.locator("tobago-messages[id='page:messages'] .alert");
441441
const reset = page.locator(".tobago-button[id='page:mainForm:resetImmediateFalseAjaxEnabled']");
442442
const sheet = page.locator("tobago-sheet[id='page:mainForm:sheet']");
@@ -464,7 +464,7 @@ test.describe("sheet/columnSelector/immediate/immediate.xhtml", () => {
464464
await expect(alert).toBeVisible();
465465
});
466466

467-
test("immediate=false, ajax=disabled", async ({page}) => {
467+
test("immediate=false, ajax=disabled, input=required", async ({page}) => {
468468
const alert = page.locator("tobago-messages[id='page:messages'] .alert");
469469
const reset = page.locator(".tobago-button[id='page:mainForm:resetImmediateFalseAjaxDisabled']");
470470
const sheet = page.locator("tobago-sheet[id='page:mainForm:sheet']");
@@ -495,6 +495,40 @@ test.describe("sheet/columnSelector/immediate/immediate.xhtml", () => {
495495
await expect(alert).toBeVisible();
496496
});
497497

498+
test("immediate=true, ajax=disabled, input=optional", async ({page}) => {
499+
const reset = page.locator(".tobago-button[id='page:mainForm:resetImmediateTrueAjaxDisabledInputOptional']");
500+
const sheet = page.locator("tobago-sheet[id='page:mainForm:sheet']");
501+
const toggleAll = sheet.locator("th[id='page:mainForm:sheet:colSelect'] input");
502+
const row0Checkbox = sheet.locator("input[name='page:mainForm:sheet_data_row_selector_0']");
503+
const row4Orbit = sheet.locator("tr[row-index='4'] td:nth-child(3) tobago-out");
504+
const selectedCount = page.locator("tobago-out[id='page:mainForm:selectedCount'] span.form-control-plaintext");
505+
const submit = page.locator("button[id='page:mainForm:submit']");
506+
507+
await reset.click();
508+
await expect(sheet).toBeVisible();
509+
await expect(selectedCount).toHaveText("0");
510+
511+
await row0Checkbox.click();
512+
await expect(selectedCount).toHaveText("0");
513+
await submit.click();
514+
await expect(selectedCount).toHaveText("1");
515+
516+
await row4Orbit.click();
517+
await expect(selectedCount).toHaveText("1");
518+
await submit.click();
519+
await expect(selectedCount).toHaveText("2");
520+
521+
await toggleAll.click();
522+
await expect(selectedCount).toHaveText("2");
523+
await submit.click();
524+
await expect(selectedCount).toHaveText("5");
525+
526+
await toggleAll.click();
527+
await expect(selectedCount).toHaveText("5");
528+
await submit.click();
529+
await expect(selectedCount).toHaveText("0");
530+
});
531+
498532
test("Save selected rows (Ajax)", async ({page}) => {
499533
const alert = page.locator("tobago-messages[id='page:messages'] .alert");
500534
const reset = page.locator(".tobago-button[id='page:mainForm:resetImmediateTrueAjaxDisabled']");

0 commit comments

Comments
 (0)