Dear All,
I am new PrimeFaces user and have been impressed with the features and the updates. Its a great product and a big thank you to all the contributors.
While most of the features I have implemented are working fine, I am getting an exception when I try to upload a file.
I am using MyFaces 2.0.4, PrimeFaces 2.2.1, Tomcat 7.0.22, Java 1.6, commons-fileupload 1.2.2, commons-io 1.4
The exception is as under.
-----------------------
WARNING: Identifier for execute FlashMap was lost on the postback, thus FlashScope information is gone.
15/11/2011 6:57:52 PM org.apache.myfaces.shared_impl.util.StateUtils reconstruct
SEVERE: View State cannot be reconstructed
javax.faces.FacesException: javax.faces.application.ViewExpiredException
at org.apache.myfaces.shared_impl.util.StateUtils.decrypt(StateUtils.java:496)
at org.apache.myfaces.shared_impl.util.StateUtils.reconstruct(StateUtils.java:378)
at org.apache.myfaces.renderkit.html.HtmlResponseStateManager.getSavedState(HtmlResponseStateManager.java:213)
at org.apache.myfaces.renderkit.html.HtmlResponseStateManager.getState(HtmlResponseStateManager.java:160)
at org.apache.myfaces.view.facelets.DefaultFaceletsStateManagementStrategy.restoreView(DefaultFaceletsStateManag
ementStrategy.java:144)
at org.apache.myfaces.application.jsp.JspStateManagerImpl.restoreView(JspStateManagerImpl.java:388)
at org.apache.myfaces.shared_impl.view.ViewDeclarationLanguageBase.restoreView(ViewDeclarationLanguageBase.java:
106)
at org.apache.myfaces.view.facelets.FaceletViewDeclarationLanguage.restoreView(FaceletViewDeclarationLanguage.ja
va:1438)
---------------------------
I have a Filter Defined in the web.xml
<!-- Filter for File Upload (Prime Faces) -->
<filter>
<filter-name>PrimeFaces FileUpload Filter</filter-name>
<filter-class>org.primefaces.webapp.filter.FileUploadFilter</filter-class>
<init-param>
<param-name>thresholdSize</param-name>
<param-value>2097152</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>PrimeFaces FileUpload Filter</filter-name>
<servlet-name>Faces Servlet</servlet-name>
</filter-mapping>
--------
My upload component has been defined as follows:
<h:form id="uploadForm" enctype="multipart/form-data">
<h:panelGrid columns="1" rendered="#{loginBean.uploadSectionVisible}">
<p:fileUpload fileUploadListener="#{fileUploadBean.handleFileUpload}"
mode="advanced"
update="messages"
sizeLimit="100000"
allowTypes="/(\.|\/)(gif|jpe?g|png)$/"/>
<p:growl id="messages" showDetail="true"/>
</h:panelGrid>
</h:form>
My handleFileUpload method in the backing bean is defined as follows:
public void handleFileUpload(FileUploadEvent event) {
//Primitives
final int BUFFER_SIZE = 6124;
String folderToUpload;
// FacesContext context = FacesContext.getCurrentInstance();
// UploadedFile file = event.getFile();
System.out.println("File upload triggered!!");
ExternalContext extContext=FacesContext.getCurrentInstance().getExternalContext();
File result = new File(extContext.getRealPath("//WEB-INF//files//" +
event.getFile().getFileName()));
//System.out.println(extContext.getRealPath("//WEB-INF//files//" +
// event.getFile().getFileName()));
try {
FileOutputStream fileOutputStream = new FileOutputStream(result);
byte[] buffer = new byte[BUFFER_SIZE];
int bulk;
InputStream inputStream = event.getFile().getInputstream();
while (true) {
bulk = inputStream.read(buffer);
if (bulk < 0) {
break;
}
fileOutputStream.write(buffer, 0, bulk);
fileOutputStream.flush();
}
fileOutputStream.close();
inputStream.close();
FacesMessage msg = new FacesMessage("Succesful", event.getFile().getFileName()
+ " is uploaded.");
FacesContext.getCurrentInstance().addMessage(null, msg);
} catch (IOException e) {
e.printStackTrace();
FacesMessage error = new FacesMessage(FacesMessage.SEVERITY_ERROR,
"The files were not uploaded!", "");
FacesContext.getCurrentInstance().addMessage(null, error);
}
}
I have tried upgrading to PrimeFaces 3.0.M4 but that broke my Theme layout even though I upgraded to 1.0.2 and so I switched back to 2.2.1
I am not using any other Faces component as PrimeFaces has met all my requirements. If I can't fix this I might have to switch to Tomahawk.
Any help will be much appreciated.
Kind Regards,
John
FileUpload ViewExpiredException PrimeFaces2.2.1
-
- PrimeFaces Core Developer
- Posts: 3979
- Joined: 03 Dec 2010, 14:11
- Location: Bavaria, DE
- Contact:
We had the same problem - we fixed that wih switching to Mojarra and Server-Side-Viewstate.
But i would use MyFaces and upgrade to 3.0.M4!
But i would use MyFaces and upgrade to 3.0.M4!
Thomas Andraschko
PrimeFaces | PrimeFaces Extensions
Apache Member | OpenWebBeans, DeltaSpike, MyFaces, BVal, TomEE
Sponsor me: https://github.com/sponsors/tandraschko
Blog: http://tandraschko.blogspot.de/
Twitter: https://twitter.com/TAndraschko
PrimeFaces | PrimeFaces Extensions
Apache Member | OpenWebBeans, DeltaSpike, MyFaces, BVal, TomEE
Sponsor me: https://github.com/sponsors/tandraschko
Blog: http://tandraschko.blogspot.de/
Twitter: https://twitter.com/TAndraschko
-
- Prime
- Posts: 18616
- Joined: 05 Jan 2009, 00:21
- Location: Cybertron
- Contact:
Try new fileupload of 3.0.M4, much better than 2.2.
http://www.primefaces.org/showcase-labs ... adHome.jsf
http://www.primefaces.org/showcase-labs ... adHome.jsf
-
- Posts: 5
- Joined: 10 Nov 2011, 08:08
Thanks Catagay. I did try to upgrade by my view didn't render correctly even though I upgraded my Theme jar. I don't want to move from one problem to another.optimus.prime wrote:Try new fileupload of 3.0.M4, much better than 2.2.
http://www.primefaces.org/showcase-labs ... adHome.jsf
Is there a known solution for the problem I am facing. It would be much appreciated.
By the way, I am using Chrome.
Regards,
John
-
- Posts: 5
- Joined: 10 Nov 2011, 08:08
Thanks for the tip zoigl. My ViewExpiredException is now gone after I changed to server side saving so that's a step forward.zoigl wrote:We had the same problem - we fixed that wih switching to Mojarra and Server-Side-Viewstate.
But i would use MyFaces and upgrade to 3.0.M4!
-
- Posts: 5
- Joined: 10 Nov 2011, 08:08
Zoigl. I have upgraded to 3.0.M4 and my view is rendering fine.When I click on the upload button, everything appears to go welljohnpage09 wrote:Thanks for the tip zoigl. My ViewExpiredException is now gone after I changed to server side saving so that's a step forward.zoigl wrote:We had the same problem - we fixed that wih switching to Mojarra and Server-Side-Viewstate.
But i would use MyFaces and upgrade to 3.0.M4!
and there are no errors but I can't see the file on the WebServer.
Where should I be looking? I am running on Tomcat7.0.22
and here is the code of my bean method...
//Primitives
final int BUFFER_SIZE = 6124;
public void handleFileUpload(FileUploadEvent event) {
ExternalContext extContext=FacesContext.getCurrentInstance().getExternalContext();
FacesMessage msg = new FacesMessage("Succesful", event.getFile().getFileName() + " is uploaded.");
FacesContext.getCurrentInstance().addMessage(null, msg);
File result = new File(extContext.getRealPath("c:\\temp\\" +
event.getFile().getFileName()));
//System.out.println(extContext.getRealPath("//WEB-INF//files//" +
// event.getFile().getFileName()));
try {
FileOutputStream fileOutputStream = new FileOutputStream(result);
byte[] buffer = new byte[BUFFER_SIZE];
int bulk;
InputStream inputStream = event.getFile().getInputstream();
while (true) {
bulk = inputStream.read(buffer);
if (bulk < 0) {
break;
}
fileOutputStream.write(buffer, 0, bulk);
fileOutputStream.flush();
}
fileOutputStream.close();
inputStream.close();
FacesMessage message = new FacesMessage("Succesful", event.getFile().getFileName()
+ " is uploaded.");
FacesContext.getCurrentInstance().addMessage(null, message);
} catch (IOException e) {
e.printStackTrace();
FacesMessage error = new FacesMessage(FacesMessage.SEVERITY_ERROR,
"The files were not uploaded!", "");
FacesContext.getCurrentInstance().addMessage(null, error);
}
sure... http://bit.ly/vHGeB6
I think it's obvious that if I had found the solution there, I would not have asked.kukeltje wrote:sure... http://bit.ly/vHGeB6
-
- Information
-
Who is online
Users browsing this forum: No registered users and 14 guests