Firefox warning "unreachable code after return statement" for non-ajax CommandLink

UI Components for JSF
Post Reply
User avatar
simon.illucit
Posts: 5
Joined: 03 May 2018, 17:13
Location: Würzburg, Germany
Contact:

18 May 2018, 11:49

Hi,

I am using a <p:commandLink ajax="false" /> with a <p:fileDownload /> to provide a downloadable File (ajax=false is required for the download to work).
The download works fine, but when I click the Link in Firefox, I also get an annoying Console-Warning "unreachable code after return statement" (this one).

Code: Select all

<p:commandLink onclick="PrimeFaces.monitorDownload(onDownloadStart, onDownloadStop);" ajax="false">
	<p:fileDownload value='#{downloadBean.downloadExcel([...])}' contentDisposition="attachment" />
	Download
</p:commandLink>
The reason for the warning seems to be the generated onClick code for the commandLink:

Code: Select all

<a onclick="PrimeFaces.monitorDownload(onDownloadStart, onDownloadStop);;PrimeFaces.addSubmitParam('theform',{'[removed]'}).submit('theform');return false;PrimeFaces.onPost();">Download</a>
There is indeed a "return" followed by "PrimeFaces.onPost()".

It seems to come from the CoreRenderer in the function buildNonAjaxRequest():

Code: Select all

[...] // submit = true here
        if (submit) {
            Object target = component.getAttributes().get("target");
            request.append(".submit('").append(formId).append("'");
            if (target != null) {
                request.append(",'").append(target).append("'");
            }

            request.append(");return false;");
        }

        if (!submit && !params.isEmpty()) {
            request.append(";");
        }

        request.append("PrimeFaces.onPost();");
        return request.toString();
So, my question is:
1) is the "return false" here correct?
2) wouldn't it then make sense to print the "PrimeFaces.onPost()" only for submit==false (because due to the "return" it won't be executed anyways)?

PrimeFaces version: 6.2.4
JSF: 2.2
Browser: Firefox 60.0
Christian Simon (Würzburg, Germany)

illucit Software GmbH | https://www.illucit.com | Github: @metaxmx

kukeltje
Expert Member
Posts: 9605
Joined: 17 Jun 2010, 13:34
Location: Netherlands

18 May 2018, 15:51

Sounds logical... Can you try with changed source if you notice a difference in behaviour? If not, please file an issue and maybe even a pull request

User avatar
simon.illucit
Posts: 5
Joined: 03 May 2018, 17:13
Location: Würzburg, Germany
Contact:

22 May 2018, 18:09

Thanks,
I created an issue and a pull request for this problem now:
https://github.com/primefaces/primefaces/issues/3700
Christian Simon (Würzburg, Germany)

illucit Software GmbH | https://www.illucit.com | Github: @metaxmx

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 35 guests