[jboss-user] [JBoss Seam] - FileUpload
jknotzke
do-not-reply at jboss.com
Mon Aug 6 11:51:46 EDT 2007
Hi,
I have what's got to be a very basic Seam question. I am using SEAM 2.0 BETA.
I am simply trying to upload a CSV file. Here's the code:
|
| ....
| import static org.jboss.seam.ScopeType.SESSION;
|
| import java.io.Serializable;
|
| import javax.persistence.Entity;
| import javax.persistence.Id;
| import javax.persistence.Table;
|
| import org.hibernate.validator.Length;
| import org.hibernate.validator.NotNull;
| import org.jboss.seam.annotations.Name;
| import org.jboss.seam.annotations.Scope;
|
| @Entity
| @Name("uploadedWorkout")
| @Scope(SESSION)
| public class UploadedWorkout implements Serializable
| {
| private byte[] uploadedFile;
| @Id @NotNull
| private String fileName;
| private String contentType;
|
| public UploadedWorkout()
| {
| }
|
| public String getFileName()
| {
| return fileName;
| }
|
| ........ sets and gets
|
Action Class
| import javax.ejb.Stateless;
| import org.jboss.seam.annotations.Name;
| import org.jboss.seam.annotations.In;
| import org.jboss.seam.annotations.Logger;
| import org.jboss.seam.log.Log;
| import org.jboss.seam.faces.FacesMessages;
| import org.jboss.seam.annotations.Scope;
| import static org.jboss.seam.ScopeType.SESSION;
|
| @Stateless
| @Scope(SESSION)
| @Name("uploadWorkout")
| public class UploadWorkoutBean implements UploadWorkout {
|
| @Logger private Log log;
| @In(value="uploadedWorkout", create=true)
| private UploadedWorkout uploadedWorkout;
|
| @In FacesMessages facesMessages;
|
| public void uploadWorkout()
| {
| //implement your business logic here
| log.info("Content Type is: " + uploadedWorkout.getContentType());
| log.info("FileName is: " + uploadedWorkout.getFileName());
| log.info("uploadWorkout.uploadWorkout() action called");
| facesMessages.add("uploadWorkout");
| }
|
JSF:
|
| <ui:composition xmlns="http://www.w3.org/1999/xhtml"
| xmlns:s="http://jboss.com/products/seam/taglib"
| xmlns:ui="http://java.sun.com/jsf/facelets"
| xmlns:f="http://java.sun.com/jsf/core"
| xmlns:h="http://java.sun.com/jsf/html"
| xmlns:rich="http://richfaces.ajax4jsf.org/rich"
| xmlns:a="https://ajax4jsf.dev.java.net/ajax"
| template="layout/template.xhtml">
|
| <ui:define name="body">
|
| <h:messages globalOnly="true" styleClass="message"/>
|
| <rich:panel>
| <f:facet name="header">Upload Workout</f:facet>
|
| <h:form id="uploadedWorkoutForm">
| <s:fileUpload id="inUploadFile"
| data="#{uploadedWorkout.uploadedFile}"
| fileName="#{uploadedWorkout.fileName}"
| contentType="#{uploadedWorkout.contentType}"
| styleClass="fileUploadInput" />
|
|
| <h:commandButton id="uploadWorkout" value="uploadWorkout!"
| action="#{uploadWorkout.uploadWorkout}"/>
|
| </h:form>
|
| </rich:panel>
|
| </ui:define>
|
| </ui:composition>
|
The properties in uploadedFile are always NULL. As a matter of fact, I had to stuff create=true in because uploadedFile itself was null.
If I swap:
| @In(value="uploadedWorkout", create=true)
| private UploadedWorkout uploadedWorkout;
|
for
| @In
| private User user;
|
...which is a component I successfully used for registration and login, all works.. So the problem is with UploadedWorkout..
Any ideas ?
Thanks.
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4071239#4071239
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4071239
More information about the jboss-user
mailing list