primefaces: CSP: DefaultCommand Failing
When I use in a commandButton in the oncomplete method, the javascript function handleModalRequest (xhr, status, args, ‘dialogWidget’) and I have CSP enabled, the variable args says it is undefined, I use that variable to get the value of the attribute validationFailed to know if the validations have failed not to close the dialog or any variable sent to it by ajax.
1) Environment
- PrimeFaces version: 8.0
- Does it work on the newest released PrimeFaces version? Version? No
- Does it work on the newest sources in GitHub? No
- Application server + version: Apache Tomcat 9 + JSF 2.3.2
- Affected browsers: All
2) Expected behavior
When I use a javascript function to get the validation errors of ajax requests and I use the parameters xhr, status, args in this javascript method, the variable args must be defined and with the attribute validationFailed to true or false, depending on whether they have occurred validation errors or not when CSP is enabled.
3) Actual behavior
When I use a javascript function to get validation errors from ajax requests and use xhr, status, args parameters in that javascript method, args variable is always undefined when CSP is enabled.
4) Steps to reproduce
- Enable CSP
- Create a dialog with an inputText with the attribute required = “true”
- Place a p:commandbutton inside the dialog and enter the JS function: handleModalRequest (xhr, status, args, ‘dialogWidget’) in the oncomplete attribute where dialogWidget is the value of the dialog widgetvar attribute.
- Open the dialog and press ENTER inside the text field.
- The browser displays the error causing the dialog to close:
index.xhtml:39 Uncaught TypeError: Cannot read property 'validationFailed' of undefined at handleModalRequest (index.xhtml:39) at Object.onco (index.xhtml:47) at Object.<anonymous> (VM8 core.js.xhtml:18) at c (VM7 jquery.js.xhtml:2) at Object.fireWith [as rejectWith] (VM7 jquery.js.xhtml:2) at l (VM7 jquery.js.xhtml:2) at Object.abort (VM7 jquery.js.xhtml:2) at Object.abortAll (VM8 core.js.xhtml:18) at VM8 core.js.xhtml:18 at dispatch (VM7 jquery.js.xhtml:2)
The line where it says it fails is: if (args.validationFailed) {
<script type="text/javascript" nonce="NzU3ZTNlNjUtZGI4Mi00NzA2LWI5ZWItNzQwY2FjMzY2M2Iz"> function handleModalRequest(xhr, status, args, modal) { if (args.validationFailed) { PF(modal).jq.effect("shake", { times : 5 }, 100); } else { PF(modal).hide(); } } </script>
And this is caused by the core.js file showing the following error:
TypeError: Cannot read property 'requestContent' of undefined
5) Sample XHTML
<h:form>
<p:commandButton ajax="true" oncomplete="PF('dialog').show()" value="MOSTRAR DIALOGO"/>
</h:form>
<p:dialog widgetVar="dialog">
<h:form id="form1">
<h:panelGrid columns="3" cellpadding="5">
<h:outputLabel for="name" value="Name:" style="font-weight:bold"/>
<p:inputText id="name" required="true"/>
</h:panelGrid>
<p:commandButton value="Button1" id="btn1" onclick="PF('dialog').hide()"/>
<p:commandButton value="Button2" id="btn2" oncomplete="handleModalRequest(xhr, status, args, 'dialog');"/>
<p:defaultCommand target="btn2" />
</h:form>
</p:dialog>
<script type="text/javascript">
function handleModalRequest(xhr, status, args, modal) {
console.log(args);
if (args.validationFailed) {
PF(modal).jq.effect("shake", {
times : 5
}, 100);
} else {
PF(modal).hide();
}
}
</script>
6) Sample bean
N/A
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 43 (24 by maintainers)
Commits related to this issue
- Fix #5790: CSP with DefaultCommand click — committed to melloware/primefaces by melloware 4 years ago
- Fix #5790: CSP with DefaultCommand click — committed to melloware/primefaces by melloware 4 years ago
- Fix #5790: CSP with DefaultCommand click — committed to melloware/primefaces by melloware 4 years ago
- Merge pull request #5797 from melloware/PF5790 Fix #5790: CSP with DefaultCommand click — committed to primefaces/primefaces by tandraschko 4 years ago
it works perfectly! what cracks! Thank you very much for everything.
ohh thank goodness you were able to reproduce it, I was ready to shoot myself with thousands of tests and version changes. Thank you very much.