1

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

Toru
  • 905
  • 1
  • 9
  • 28

1 Answers1

1

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:

Jasper de Vries
  • 19,370
  • 6
  • 64
  • 102