Fileunput Primefaces does not update the attribute;

Asked

Viewed 161 times

1

I have a repeating structure:

<ui:repeat var="item" />

Inside it I print some fields. One of them is the <p:fileUpload/>

So far so good. The problem is time to do the action, when I click the save button it assigns all fields in managebran except the field of file.

But if I remove the fileInput from within the <ui:repeat> it works.

Besides not working, the attribute of mine bean is void.

<h:form>
<ui:repeat var="item" value="#{bean.page.columns}">
<p:fileUpload mode="simple" value="#{bean.file}" />
</ui:repeat>
<p:commandButton ajax="false" action="#{bean.save}" value="#{msgs.save}" 
 update="growl" styleClass="btn button" />
</h:form>

So it works, it associates the value in my bean.

<h:form>
<p:fileUpload mode="simple" value="#{bean.file}" />
<p:commandButton ajax="false" action="#{bean.save}" value="#{msgs.save}" 
 update="growl" styleClass="btn button" />
</h:form>
  • Avoid using ui:repeat, take a look at p:dataList.

  • Thanks, I’ll take a look and see if it works.

  • I’ve already fallen into a similar problem (in a datatable). A solution is to leave all the files in a list or array (see this answer from Balusc). It didn’t work for me because the files were optional and I couldn’t do Binding only through the index. What I did at the time was to adapt this Balusc solution to write the results in a Map <ID, File> and adapt the method called in commandButton to associate each file to its respective bean (unfortunately I don’t have that code with me, but if funfar I create a response).

1 answer

2

your form is using the default enctype that is application/x-www-form-urlencoded, to handle POST requests involving binaries, that the case of a file upload, it is necessary to use a specific enctype: multipart/form-data

configure your form this way:

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

To upload multiple files, you can use the attribute multiple="true" in his p:fileUpload

Browser other questions tagged

You are not signed in. Login or sign up in order to post.