I'd like to give the user the ability to choose the amount of attachments he'd like to provide. To do this I created a datatable with buttons to add and remove attachment-lines:

<p:dataTable id="attachments" var="attachment" value="#{data.attachments}">
    <p:column headerText="#{ivy.cms.co('/labels/vendor')}"><p:inputText value="#{attachment.vendor}" /></p:column>
    <p:column headerText="#{ivy.cms.co('/labels/description')}"><p:inputText value="#{attachment.description}" /></p:column>
    <p:column headerText="#{ivy.cms.co('/labels/amount')}"><p:inputText value="#{attachment.amount}" /></p:column>
    <p:column headerText="#{ivy.cms.co('/labels/attachment')}"><p:fileUpload value="#{attachment.file}" mode="simple" /></p:column>
    <p:column headerText=""><p:commandButton value="delete-row" update="attachments" action="#{logic.deleteAttachment(attachment)}" /><p:commandButton value="add-row"  update="attachments" action="#{logic.addAttachment()}" /> </p:column>
</p:dataTable>

The only problem is, that it seems to not upload the specified file. The submitted form is beeing processed by this script, the output of in.test beeing false:

for(Integer i = 0; i < in.attachments.size(); i++) {
    in.test = in.attachments.get(i).file.exists().toString();
}

The Simple-Fileupload-Demo works, so I guess it can't be a problem with my installation / computer. I just cleared all of the attachments and uploaded only one. So while this is a foor loop, it just iterates through 1 time. Data is stored in my own Data Class Attachment, containing 4 attributes (Vendor, Description, Amount and File).

asked 21.01.2014 at 20:34

ahatius's gravatar image

ahatius
(suspended)
accept rate: 0%

edited 18.02.2014 at 16:58

Flavio%20Sadeghi's gravatar image

Flavio Sadeghi ♦♦
(suspended)


To upload a file, the form-tag requires the correct enctype-type.

<h:form enctype="multipart/form-data">
  ...
</h:form>

See also the example project which is delivered within Xpert.ivy Designer. It contains several file-upload demos. The location of the demo project is:

[Designer]/applications/samples/HtmlDialogDemos
link

answered 24.01.2014 at 16:48

Flavio%20Sadeghi's gravatar image

Flavio Sadeghi ♦♦
(suspended)
accept rate: 75%

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "Title")
  • image?![alt text](/path/img.jpg "Title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×79
×7

Asked: 21.01.2014 at 20:34

Seen: 4,283 times

Last updated: 18.02.2014 at 16:58