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

UI Components for JSF
Post Reply
simon.illucit
Posts: 2
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

kukeltje
Expert Member
Posts: 8952
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
Ronald van Kuijk
______________________________
PrimeFaces 6.1, PrimeFaces plus 0.0.2 | JbossWildfly 10.1| Mojarra 2.2.13
Fedora 61, Firefox 'most recent'
Read the forum posting rules
Beginners: https://jsf.zeef.com/bauke.scholtz

simon.illucit
Posts: 2
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

Post Reply
  • Information
  • Who is online

    Users browsing this forum: Baidu [Spider] and 14 guests