I'm using jsf 2.0 and icefaces 3 component to upload files:
<h:form enctype="multipart/form-data">
<ace:fileEntry
id="file-entry"
relativePath="/files/"
maxFileCount="10"
maxFileCountMessage="Limited to 10 files uploaded concurrantly."
fileEntryListener="#{uploadFileBean.sampleListener}"
maxFileSize="6291456"
maxFileSizeMessage="Submitted file is too large."
maxTotalSize="18874368"
maxTotalSizeMessage="Total size of submitted files is too large."
required="true"
requiredMessage="The file is required to submit this form."
useOriginalFilename="true"
useSessionSubdir="true" />
<h:commandButton
id="submit"
type="submit"
value="Send File" />
</h:form>
but after I select a file to upload and press Send File button, I receive:
The file is required to submit this form.
which is very strange because I already selected a file.
Does anyone has any suggestion?
Related
I am trying to open browsing window with this file upload code but it is not responding means the pop up window not opening
<p:fileUpload id="fileupload" value="#{data.value}" fileUploadListener="#{fileUploadController.handleFileUpload}"
required="true" allowTypes="#{data.allowedExtensions}" mode="advanced" multiple="true"
update="fileDataTable _mainForm_fileMessages" widgetVar="fileUploadWidget" />
I have a hidden <p:fileUpload> which is opened via <h:outputLabel>.
<p:messages id="message" autoUpdate="true" />
<h:form id="form">
<p:fileUpload id="file-input" auto="true"
allowTypes="/(\.|\/)(gif|jpe?g|png)$/" sizeLimit="10"
invalidSizeMessage="wrong size" fileUploadListener="#{bean.image}"
update="#form message" style="display: none;"
invalidFileMessage="wrong file" />
<h:outputLabel for="file-input_input">
<h:graphicImage name="images/dummy.jpg" />
</h:outputLabel>
<h:outputText value="#{bean.file.fileName}" />
<br />
<h:outputText value="#{bean.file.size}" />
</h:form>
Unfortunately, no messages are displayed after validation failed (e.g invalid size or invalid file). Those messages are displayed inside the <p:fileUpload> content box instead of in <p:messages>.
How can I display those messages inside <p:messages> instead of inside <p:fileUpload>?
The validation is performed fully client side without hitting the server. So you can't control this from server side on.
The message container of the <p:fileUpload> is available via messageContainer property of the widget variable. Simple let jQuery move it into the <p:messages> when clicking the label:
<p:messages id="messages" ... />
<h:form>
<p:fileUpload id="file-input" widgetVar="file-input" ...
styleClass="ui-helper-hidden" />
...
<h:outputLabel for="file-input_input" ...
onclick="PF('file-input').messageContainer.appendTo($('#messages'));" />
</h:form>
(I only renamed <p:message id> to be more sensible, and used a PrimeFaces specific class to hide it instead of an inline style)
The onstart and oncomplete attributes of <p:fileUpload> weren't usable as they are only executed when the client side validation has passed and the file upload request is actually sent.
I'm using JSF, CDI. Can i upload file and some text fields in the same form?
<h:form>
<h:inputText value="#{mybean.discription}" />
<p:fileUpload value="#{mybean.file}" mode="simple"/> //Or <h:inputFile value="#{mybean.file}"/> if using jsf2.2
<h:commandButton action="#{mybean.submit}" value="Submit"/>
</h:form>
I saw a lot of tutorials about uploading file, but in those tutorials only use single component to upload file.
I tried to do but i didn't.
Can you give me an answer? Thanks
I done. I forgot enctype="multipart/form-data"
<h:form enctype="multipart/form-data">
<h:inputText value="#{mybean.discription}" />
<p:fileUpload value="#{mybean.file}" mode="simple" />
<h:commandButton value="Submit" action="#{mybean.submit}" />
</h:form>
I am uploading a file, namely a picture. I want the picture on the page to update to the new one once it is uploaded. I am unable to get this to work.
I am using the following code to upload the file:
<h:form id="fileUploadForm" enctype="multipart/form-data" >
<p:remoteCommand name="showFileUpload" onstart="fileUpload.show();"/>
<p:remoteCommand name="hideFileUpload" onstart="fileUpload.hide();"/>
<p:dialog
id="fileUpload"
header="File Upload"
widgetVar="fileUpload"
modal="true">
<h:inputFile id="file" value="#{fileUploadManagedBean.file}"/>
<p:commandButton value="Upload"
action="#{sessionManagedBean.updateDisplay('account')}"
oncomplete="hideFileUpload();updateMainPanel();"
actionListener="#{fileUploadManagedBean.upload}"
ajax="false"
/>
</p:dialog>
</h:form>
The call to updateMainPanel(); in the oncomplete event works for other users. However, for this, it does not. Any ideas on how I can update a component once the file has been uploaded?
I wanted to know if it is possible to check if a file is already selected prior to a click on submit/upload button?
The problem I want to solve with this option is to hide the "submit/upload" button if no file has already selected? Using required="true" attribute is not an option for me because the user doesn't always have to provide a file.
This is possible by initially hiding the upload button by CSS and attaching some JS to the change event of the file field which displays the upload button if a file has been selected.
<h:form id="form">
<t:inputFileUpload id="file" value="#{bean.file}" required="true"
onchange="document.getElementById('form:upload').style.display = (!!value) ? 'block' : 'none'" />
<h:commandButton id="upload" value="Upload" action="#{bean.upload}" style="display: none;" />
</h:form>