The following code fragment generates a javascript syntax error when I push the h:commandButton:
<h:outputScript>
'use strict';
const label = '*';
</h:outputScript>
<h:form>
<h:commandButton>
<f:ajax render="@all" />
</h:commandButton>
</h:form>
SyntaxError: redeclaration of const label
The problem is the const label = '*'. How to deal with that in this case?
Mojarra 2.3.14
CodePudding user response:
You can make the h:outputScript conditional, based on facesContext.postback. If you use rendered="#{not facesContext.postback}" it will only be rendered in the initial request and not with Ajax requests:
<h:outputScript rendered="#{not facesContext.postback}">
'use strict';
const label = '*';
</h:outputScript>
<h:form>
<h:commandButton>
<f:ajax render="@all" />
</h:commandButton>
</h:form>
See also:
