p:fileDownload returned Exception not working in Primefaces 10

UI Components for JSF
rider
Posts: 497
Joined: 05 Mar 2010, 13:17

05 May 2021, 09:05

Hi,

I´ve migrated to PF10, but i have an issue with the p:fileDownload component.

Code: Select all

<p:repeat
													value="#{emailCheckNewEmailsController.selectedEmail.emailAttachmentList}"
													var="emailAttachment">

													<i class="fa fa-download" aria-hidden="true"></i>
													<p:commandLink ajax="false" style="margin-left: 10px;"
														value="#{emailAttachment.filename}" global="true"
														immediate="true" title="#{emailAttachment.filename}"
														styleClass="Fs11"
														actionListener="#{emailInboxActionController.prepDownload(emailAttachment)}">
														<p:fileDownload
															value="#{emailInboxActionController.streamFile}" />
													</p:commandLink>
													<br></br>
												</p:repeat>

In my bean:

Code: Select all

@Named
@ViewScoped
public class EmailInboxActionController implements Serializable {	
	
	private StreamedContent streamFile;
	
	public void prepDownload(EmailAttachment emailAttachment) throws Exception {

		LOGGER.info("START prepDownload");

		try {

			InputStream stream = emailAttachment.getInputStream();

			streamFile = DefaultStreamedContent.builder().contentType(emailAttachment.getMimeType())
					.name(emailAttachment.getFilename()).stream(() -> stream).build();

		} catch (Exception e) {
			LOGGER.error(ExceptionUtils.getFullStackTrace(e));
			ErrorMessage.showErrorMessage();
		}

		LOGGER.info("END prepDownload");
	}
		public StreamedContent getStreamFile() {
		return streamFile;
	}

	public void setStreamFile(StreamedContent streamFile) {
		this.streamFile = streamFile;
	}
}
	
I´m getting error stacktrace:

Code: Select all

09:03:36,736 SEVERE [org.omnifaces.exceptionhandler.FullAjaxExceptionHandler] (default task-1) [b4aa4e94-094b-4126-bc00-f4fe5f02aac4][127.0.0.1] FullAjaxExceptionHandler: An exception occurred during processing JSF ajax request. Error page '/common/login.xhtml' will be shown.: java.lang.ArrayIndexOutOfBoundsException: Index 2 out of bounds for length 2
	at javax.faces.api@3.0.0.SP04//javax.faces.component.UIComponentBase.restoreChildState(UIComponentBase.java:3418)
	at javax.faces.api@3.0.0.SP04//javax.faces.component.UIComponentBase.processRestoreState(UIComponentBase.java:1026)
	at javax.faces.api@3.0.0.SP04//javax.faces.component.UIComponentBase.restoreFacetsState(UIComponentBase.java:3445)
	at javax.faces.api@3.0.0.SP04//javax.faces.component.UIComponentBase.processRestoreState(UIComponentBase.java:1029)

Code: Select all

		<dependency>
			<groupId>commons-fileupload</groupId>
			<artifactId>commons-fileupload</artifactId>
			<version>1.4</version>
		</dependency>
		
		
		
If I remove

Code: Select all

		<p:fileDownload value="#{emailInboxActionController.streamFile}" />
Than I´m getting no exception...

Any idea?
Primefaces 12.0, WildFly 21

NOTiFY
Posts: 393
Joined: 25 May 2016, 22:57

06 May 2021, 11:09

Which version of OmniFaces are you using with CDI?

I had some similar error 18 months or go and had to upgrade CDI to 2.0 using a more recent version of OmniFaces.
Last edited by NOTiFY on 06 May 2021, 11:12, edited 1 time in total.
PF 13.0.0--Jakarta. Jakarta Faces 4.0.1/Kotlin Multiplatform 1.9.10
Mojarra 4.0.2, OmniFaces 4.2
WildFly 29.0.1.Final 'preview' Jakarta EE 10.0.0
JDK 20.0.2, Kotlin 1.9.10, Gradle 8.3 Groovy DSL, MongoDB 7.0.0
IntelliJ IDEA 2023.2.1, macOS Ventura 13.5.1

rider
Posts: 497
Joined: 05 Mar 2010, 13:17

06 May 2021, 11:11

I´m using, but it was working before I upgrade to Primefaces 10.

Code: Select all

<dependency>
			<groupId>org.omnifaces</groupId>
			<artifactId>omnifaces</artifactId>
			<version>3.11</version>
		</dependency>
Primefaces 12.0, WildFly 21

Melloware
Posts: 3717
Joined: 22 Apr 2013, 15:48

06 May 2021, 14:16

rider we had the same issue and it turns out for some reason in our web.xml we had this...

Code: Select all

<context-param>
   <param-name>javax.faces.FULL_STATE_SAVING_VIEW_IDS</param-name>
</context-param>
Once we removed that the above error went away...
PrimeFaces Developer | PrimeFaces Extensions Developer
GitHub Profile: https://github.com/melloware
PrimeFaces Elite 13.0.0 / PF Extensions 13.0.0
PrimeReact 9.6.1

rider
Posts: 497
Joined: 05 Mar 2010, 13:17

06 May 2021, 16:38

@Melloware... thanks...
But I have FULL_STATE_SAVING_VIEW_IDS currently NOT in my web.xml at all.

Any ideas how that can be fixed?
Primefaces 12.0, WildFly 21

Melloware
Posts: 3717
Joined: 22 Apr 2013, 15:48

06 May 2021, 16:43

No i just was letting you know that i was getitng that exact bizarre error as you. Nothing really about PF or Omni in the stack trace and that is what we traced it to. Let me know if you do figure it out?
PrimeFaces Developer | PrimeFaces Extensions Developer
GitHub Profile: https://github.com/melloware
PrimeFaces Elite 13.0.0 / PF Extensions 13.0.0
PrimeReact 9.6.1

rider
Posts: 497
Joined: 05 Mar 2010, 13:17

06 May 2021, 16:47

Thanks,
but is there something maybe wrong in my code above?

It was working with PF8...
Primefaces 12.0, WildFly 21

Melloware
Posts: 3717
Joined: 22 Apr 2013, 15:48

09 May 2021, 15:06

No I don't see anything wrong with your code above. Somehing must have chnaged about the FileDownload between PF8 and PF10 because we never saw this issue before. Once we removed that web.xml param which we had no idea why that was in there it worked. It feels like something about FileDownload is broken but I don't know exactly what.
PrimeFaces Developer | PrimeFaces Extensions Developer
GitHub Profile: https://github.com/melloware
PrimeFaces Elite 13.0.0 / PF Extensions 13.0.0
PrimeReact 9.6.1

lakshmipathy
Posts: 1
Joined: 30 Jul 2021, 12:46

30 Jul 2021, 12:50

am also facing issue with p:fileDownload, we are upgrading primefaces 3.5 to 10.0 all other components are working except file download.


Caused by: java.lang.ArrayIndexOutOfBoundsException: Index 9 out of bounds for length 9
at javax.faces.api@3.0.0.SP04//javax.faces.component.UIComponentBase.restoreChildState(UIComponentBase.java:3418)
at javax.faces.api@3.0.0.SP04//javax.faces.component.UIComponentBase.processRestoreState(UIComponentBase.java:1026)
at javax.faces.api@3.0.0.SP04//javax.faces.component.UIComponentBase.restoreFacetsState(UIComponentBase.java:3445)
at javax.faces.api@3.0.0.SP04//javax.faces.component.UIComponentBase.processRestoreState(UIComponentBase.java:1029)
at javax.faces.api@3.0.0.SP04//javax.faces.component.UIViewRoot.processRestoreState(UIViewRoot.java:932)
at com.sun.jsf-impl@2.3.14.SP04//com.sun.faces.application.view.JspStateManagementStrategy.restoreView(JspStateManagementStrategy.java:252)
at com.sun.jsf-impl@2.3.14.SP04//com.sun.faces.application.StateManagerImpl.restoreView(StateManagerImpl.java:113)
at com.sun.jsf-impl@2.3.14.SP04//com.sun.faces.application.view.ViewHandlingStrategy.restoreView(ViewHandlingStrategy.java:99)
at com.sun.jsf-impl@2.3.14.SP04//com.sun.faces.application.view.FaceletViewHandlingStrategy.restoreView(FaceletViewHandlingStrategy.java:272)
at com.sun.jsf-impl@2.3.14.SP04//com.sun.faces.application.view.MultiViewHandler.restoreView(MultiViewHandler.java:133)
at javax.faces.api@3.0.0.SP04//javax.faces.application.ViewHandlerWrapper.restoreView(ViewHandlerWrapper.java:101)
at javax.faces.api@3.0.0.SP04//javax.faces.application.ViewHandlerWrapper.restoreView(ViewHandlerWrapper.java:101)
at com.sun.jsf-impl@2.3.14.SP04//com.sun.faces.lifecycle.RestoreViewPhase.execute(RestoreViewPhase.java:181)
at com.sun.jsf-impl@2.3.14.SP04//com.sun.faces.lifecycle.Phase.doPhase(Phase.java:76)
at com.sun.jsf-impl@2.3.14.SP04//com.sun.faces.lifecycle.RestoreViewPhase.doPhase(RestoreViewPhase.java:110)
at com.sun.jsf-impl@2.3.14.SP04//com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:177)
at javax.faces.api@3.0.0.SP04//javax.faces.webapp.FacesServlet.executeLifecyle(FacesServlet.java:707)

Melloware
Posts: 3717
Joined: 22 Apr 2013, 15:48

30 Jul 2021, 14:03

PrimeFaces Developer | PrimeFaces Extensions Developer
GitHub Profile: https://github.com/melloware
PrimeFaces Elite 13.0.0 / PF Extensions 13.0.0
PrimeReact 9.6.1

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 23 guests