-
1. Re: File Upload
tom_goring Mar 27, 2008 11:01 AM (in response to vasana)Can you post the whole backing bean...
maybe in the view you need to reference
sarmgr.data
rather thansarmgr.fileData.data
.Also you have your form set to
<h:form enctype="multipart/form-data">
-
2. Re: File Upload
cremersstijn Mar 27, 2008 11:48 AM (in response to vasana)can you post also the whole view.
You can't do anfile upload with an ajax request. -
3. Re: File Upload
vasana Mar 28, 2008 2:00 AM (in response to vasana)Thanks all for the reply yes i have set the form enctype property still doesnt solve it. any here is my backing bean and view
<ui:define name="content"> <div align = "center"> <h:messages styleClass="message"/> </div> <table style="border : 0px;"> <tr ><td width="100%" colspan="6" ><img src="tablfill.gif"/></td></tr></table> <h:form id="frmsar" enctype="multipart/form-data"> <div > <table width="100%" style="border : 0px;"> <tr > <td colspan="8" class="sectionhead"> <h:outputText value="Server Access Request" ></h:outputText> </td> </tr> </table> <br/> <table width="100%" style="border : 0px;"> <tr > </tr> <tr> <td width="10%"> <h:outputLabel value="SAR Id" styleClass="label" style=" width : 100%;"/> </td> <td width="25%"> <h:outputText value="#{sarmgr.osaSarId}" style=" width : 100%;"/></td> <td width="10%"> <h:outputLabel for="statusMsg" styleClass="label" style=" width : 100%;">Status</h:outputLabel> </td> <td width="25%"> <h:outputText id="statusMsg" value="Pending" style=" width : 100%;"></h:outputText> </td> </tr> <tr ><td width="100%" colspan="6" ><img src="rowlfill.gif"/></td></tr> <tr> <td width="10%"><h:outputLabel for="listemployee" styleClass="label" value="Requester" style=" width : 80%;"/></td> <td width="25%"><h:outputText id="listemployee" value="#{currentUser.tblEmployee.name}" style=" width : 80%;"/></td> <td width="10%"> <h:outputLabel value="Req.For" for="listdeptemployees" styleClass="label" style=" width : 100%;"/> </td> <td width="25%"> <h:selectOneMenu value="#{employee}" id="listdeptemployees" style=" width : 100%;" rendered="#{osamgr.isTsh or osamgr.isHod}" > <s:convertEntity /> <s:selectItems value="#{deptemployees}" var="emp" label="#{emp.name}" noSelectionLabel="Please Select"/> </h:selectOneMenu> <h:outputText value="#{currentUser.tblEmployee.name}" style=" width : 100%;" rendered="#{!osamgr.isTsh and !osamgr.isHod}"/> </td> </tr> <tr ><td width="100%" colspan="6" ><img src="rowlfill.gif"/></td></tr> <tr> <td width="10%"><h:outputLabel for="txtDateRaised" styleClass="label" style=" width : 100%;">Raised</h:outputLabel> </td> <td width="15%" > <h:outputText id="txtDateRaised" value="#{osaSar.dateRaised}" style=" width : 100%;"> <f:convertDateTime type="date" pattern="dd/MM/yyyy" timeZone="#{osamgr.timeZone}"/> </h:outputText> </td> <td width="10%"><h:outputLabel for="reqDate" styleClass="label" style=" width : 100%;">Expected</h:outputLabel> </td> <td width="25%"> <rich:calendar width="60%" id="reqDate" value="#{osaSar.expectedCompletion}" datePattern="dd/MM/yyyy" direction="bottom-right" /> </td> </tr> <tr> <td colspan="4"> <table width="100%" style="border : 0px;"> <tr ><td width="100%" colspan="6" ><img src="rowlfill.gif"/></td></tr> </table> </td> </tr> <tr> <td colspan="4" align="center" > <hr/> </td> </tr> <tr> <td colspan="4"> <table width="100%" style="border : 0px;"> <tr ><td width="100%"/></tr> </table> </td> </tr> <tr> <td width="10%"> <h:outputLabel for="listAccesType" styleClass="label" style=" width : 100%;">Access</h:outputLabel> </td> <td width="25%"> <h:selectOneMenu value="#{accesstype}" id="listAccesType" styleClass="select" style=" width : 85%;"> <s:convertEntity /> <s:selectItems value="#{accesstypes}" var="accesstype" label="#{accesstype.description}" noSelectionLabel="Please Select"/> </h:selectOneMenu> </td> <td width="10%"> <h:outputLabel for="listtaskaction" styleClass="label" style=" width : 100%;">Action</h:outputLabel> </td> <td width="25%"> <h:selectOneMenu value="#{taskaction}" id="listtaskaction" styleClass="select" style=" width : 85%;"> <s:convertEntity /> <s:selectItems value="#{taskactions}" var="taskaction" label="#{taskaction.description}" noSelectionLabel="Please Select"/> </h:selectOneMenu> </td> </tr> <tr ><td width="100%" colspan="6" ><img src="rowlfill.gif"/></td></tr> <tr> <td width="10%"> <h:outputLabel for="listtaskreason" styleClass="label" style=" width : 100%;">Reason</h:outputLabel> </td> <td width="25%"> <h:selectOneMenu value="#{taskreason}" id="listtaskreason" styleClass="select" style=" width : 85%;"> <s:convertEntity /> <s:selectItems value="#{taskreasons}" var="taskreason" label="#{taskreason.description}" noSelectionLabel="Please Select"/> </h:selectOneMenu> </td> <td width="10%"> <h:outputLabel for="txtValidity" styleClass="label" style=" width : 100%;">Validity</h:outputLabel> </td> <td width="15%"> <h:inputText value="#{osaTask.validity}" id="txtValidity" maxlength="3" style="width:30px" /> <h:outputLabel value="days" /><h:outputLabel style="font-size: 10px;" value=" (Empty or 0 for infinite validity)" /> </td> </tr> <tr ><td width="100%" colspan="6" ><img src="rowlfill.gif"/></td></tr> <tr> <td width="15%"> <h:outputLabel styleClass="label" style=" width : 100%;">Attachment</h:outputLabel></td> <td colspan="2"><s:fileUpload data="#{sarmgr.data}" fileName="#{sarmgr.fileName}" fileSize="#{sarmgr.fileSize}" accept="" style=" width : 99%;" /> </td> </tr>
and the backing EJB is
@Stateful @Name("sarmgr") public class SARManager implements ISar { private String fileName; private Integer fileSize; private byte[] data; private String contentType; @Begin(join = true, flushMode = FlushModeType.MANUAL) public String addTask() { if (addedTasks == null) { addedTasks = new ArrayList<OsaTask>(0); } System.err.println("**************************************:::::::::"+fileData.getData()); } }
-
4. Re: File Upload
cremersstijn Mar 28, 2008 8:27 AM (in response to vasana)I was looking for the button that submit your form, but i can't find it in your view.
Make sure that you don't submit with an ajax request. -
5. Re: File Upload
danielc.roth Mar 28, 2008 8:30 AM (in response to vasana)I assume you have a have something like
<h:commandXXXX action="#{sarmgr.addTask}">
and
getters/setters for data/fileName/fileSize?
I get a zero length byte array if I submit a form with no file chosen, so could you try to check that the setData(byte[] data) actually is called (and set to null)?
-
6. Re: File Upload
vasana Mar 28, 2008 3:49 PM (in response to vasana)Thanks Roth i will try that way
-
7. Re: File Upload
gauravsinghc Jun 5, 2009 7:45 AM (in response to vasana)hey ,
did you get this working a i am also facing the same problem -
8. Re: File Upload
vasana Jun 5, 2009 4:25 PM (in response to vasana)Hi,
Yes I got it working.Prolem is I was using a4j:commandbutton ( which is Ajax based) When i changed it to h:commandButton it worked. Good luck.