question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

CSP: DefaultCommand Failing

See original GitHub issue

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

  1. Enable CSP
  2. Create a dialog with an inputText with the attribute required = “true”
  3. 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.
  4. Open the dialog and press ENTER inside the text field.
  5. 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

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:43 (24 by maintainers)

github_iconTop GitHub Comments

1reaction
nokiajavicommented, Apr 16, 2020

it works perfectly! what cracks! Thank you very much for everything.

1reaction
nokiajavicommented, Apr 14, 2020

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

DefaultCommand | PrimeFaces JavaScript API Docs
PrimeFaces DefaultCommand Widget. Which command to submit the form with when enter key is pressed a common problem in web apps not just...
Read more >
PrimeFaces 7.0.14 and 8.0.2 Released
... CSP: DefaultCommand Failing (8.0.2); Dialog: inside a tab modal=true is blocking also dialog (8.0.2); Validation error on Calendar with ...
Read more >
BIG-IP VE may fail to load the default configuration on ... - AskF5
You attempt to reset the BIG-IP VE to the default configuration using the tmsh load sys config default command. Impact.
Read more >
FS-8704-07 Allen Bradley CSP - Chipkin Automation Systems
Allen Bradley CSP Driver Manual ... Override the default command. Unprotected Command Typed ... Server Map 1: N21: 0-100, no problems are experienced....
Read more >
How to use React without unsafe inline JavaScript/CSS code?
either instead put all JS/CSS code into seperate files? · or add nounces or something else that CSPs allow? · or solve that...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found