Skip to content

Commit

Permalink
https://issues.apache.org/jira/browse/MYFACES-4610
Browse files Browse the repository at this point in the history
Fix for virtual issuing elements

https://issues.apache.org/jira/browse/MYFACES-4605

Fix for unique identifier number should start at 1
  • Loading branch information
werpu committed Jun 27, 2023
1 parent ebf0ba8 commit e8d23c2
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 17 deletions.
14 changes: 7 additions & 7 deletions api/src/client/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion api/src/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"html-webpack-plugin": "^5.5.1",
"jsdom": "^21.1.1",
"jsdom-global": "^3.0.2",
"jsf.js_next_gen": "4.0.2-beta.1",
"jsf.js_next_gen": "4.0.2-beta.3",
"mocha": "^10.2.0",
"npm-check-updates": "^16.10.8",
"nyc": "^15.1.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export class HiddenInputBuilder {

let existingStates = DQ$(`[name*='${$nsp(this.name)}']`);
let cnt = existingStates.asArray.map(state => {
let ident: string = state.id.orElse("-1").value;
let ident: string = state.id.orElse("0").value;
ident = ident.substring(ident.lastIndexOf(SEP)+1);
return parseInt(ident);
})
Expand All @@ -68,7 +68,7 @@ export class HiddenInputBuilder {
})
.reduce((item1, item2) => {
return Math.max(item1, item2);
}, -1);
}, 0); //we start with 1 (see cnt++)
//the maximum new ident is the current max + 1
cnt++;

Expand Down
10 changes: 6 additions & 4 deletions api/src/client/typescript/faces/impl/xhrCore/XhrRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,12 @@ export class XhrRequest extends AsyncRunnable<XMLHttpRequest> {

const issuingItemId = this.internalContext.getIf(CTX_PARAM_SRC_CTL_ID).value;
if(issuingItemId) {
const issuingItem = DQ.byId(issuingItemId);
const arr = new ExtConfig({});
arr.assign(issuingItemId).value = issuingItem.val;
formData.shallowMerge(arr, true, true);
const itemValue = DQ.byId(issuingItemId).inputValue;
if(itemValue.isPresent()) {
const arr = new ExtConfig({});
arr.assign(issuingItemId).value = itemValue.value;
formData.shallowMerge(arr, true, true);
}
}

this.responseContext = requestPassThroughParams.deepCopy;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,23 @@ export module StandardInits {
</html>`;


const VIRTUAL_ELEMENT = `<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<form id="jd_0:blarg">
<tobago-multi-select id="page:numbers">
<input type="checkbox" name="page:numbers" id="page:numbers:1" value="1"></input>
<input type="checkbox" name="page:numbers" id="page:numbers:2" value="2"></input>
<input type="checkbox" name="page:numbers" id="page:numbers:3" value="3"></input>
</tobago-multi-select>
</form>
</body>
</html>`;


/**
* a page simulating basically a simple faces form
Expand Down Expand Up @@ -499,6 +516,11 @@ function triggerRequestChain(event) {
export function defaultMyFacesNamespaces(withJsf = true): Promise<() => void> {
return init(HTML_FORM_NAMESPACED, withJsf);
}

export function initVirtualElement(withJsf = true): Promise<() => void> {
return init(VIRTUAL_ELEMENT, withJsf);
}

export function defaultMyFaces23(withJsf = true): Promise<() => void> {
return init(HTML_FORM_DEFAULT.replace(/jakarta/gi, "javax"), withJsf, false);
}
Expand Down
45 changes: 45 additions & 0 deletions api/src/client/typescript/faces/test/xhrCore/RequestTest.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ import {
SUCCESS
} from "../../impl/core/Const";
import defaultMyFaces = StandardInits.defaultMyFaces;
import initVirtualElement = StandardInits.initVirtualElement;
import STD_XML = StandardInits.STD_XML;
import exp from "constants";

declare var faces: any;
declare var Implementation: any;
Expand Down Expand Up @@ -638,6 +640,49 @@ describe('Tests after core when it hits response', function () {
done();
});

it("must handle the virtual issuing elements correctly", function() {

const waitForResult = initVirtualElement();
return waitForResult.then((close) => {
const send = sinon.spy(XMLHttpRequest.prototype, "send");

try {
let dqElem = DomQuery.byId("page:numbers");
let element = dqElem.getAsElem(0).value;
dqElem.querySelectorAll("input").click();

faces.ajax.request(element, null, {
execute: "page:numbers",
render: "@form",
params: {
pass1: "pass1",
pass2: "pass2"
}
});

let argsVal: any = send.args[0][0];
let arsArr = argsVal.split("&");
let resultsMap = {};
let doubles = 0;
for (let val of arsArr) {
let keyVal = val.split("=");
if(!!resultsMap[keyVal[0]]) {
doubles++;
}
resultsMap[keyVal[0]] = keyVal[1];
}

expect(doubles).to.eq(2);

} finally {

send.restore();
}

return true;
});

});

});

Original file line number Diff line number Diff line change
Expand Up @@ -723,9 +723,9 @@ describe('Tests of the various aspects of the response protocol functionality',
expect(DQ$("#form2 [name*='jakarta.faces.ViewState']").val).to.eq("booga_after_update");
expect(DQ$("#form3 [name*='jakarta.faces.ViewState']").val).to.eq("booga_after_update");

expect(DQ$("#form1 [name*='jakarta.faces.ViewState']").id.value.indexOf("viewroot_1:jakarta.faces.ViewState:0") === 0).to.be.true;
expect(DQ$("#form2 [name*='jakarta.faces.ViewState']").id.value.indexOf("viewroot_1:jakarta.faces.ViewState:1") === 0).to.be.true;
expect(DQ$("#form3 [name*='jakarta.faces.ViewState']").id.value.indexOf("viewroot_1:jakarta.faces.ViewState:2") === 0).to.be.true;
expect(DQ$("#form1 [name*='jakarta.faces.ViewState']").id.value.indexOf("viewroot_1:jakarta.faces.ViewState:1") === 0).to.be.true;
expect(DQ$("#form2 [name*='jakarta.faces.ViewState']").id.value.indexOf("viewroot_1:jakarta.faces.ViewState:2") === 0).to.be.true;
expect(DQ$("#form3 [name*='jakarta.faces.ViewState']").id.value.indexOf("viewroot_1:jakarta.faces.ViewState:3") === 0).to.be.true;

done();
});
Expand Down

0 comments on commit e8d23c2

Please sign in to comment.