0

I have <p:fileUpload>

<p:fileUpload id="fileUpload"
              fileUploadListener="#{uploadBean.handleFileUpload}"
              disabled="#{uploadBean.check()}"
              mode="advanced"/>

<p:inputText value="#{tag.value}">
    <p:ajax update="form"/>
</p:inputText>

Bean

@Named
@ViewScoped
public class UploadBean....

If the tag has the correct value, a window will appear to upload the file.

Every change of value is checked. Using ajax update.

If user adds the files and then modifies the value of the tag, uploadFile element loses selected files and user must select them again.

How I can save state of fileUpload? (Files that user select)

Koray Tugay
  • 22,894
  • 45
  • 188
  • 319
Martin Hampl
  • 11
  • 1
  • 5
  • Save it for what user changing page ?!? (What is your managedBean stat) – Yagami Light Jun 13 '17 at 08:01
  • Sorry, The message was made clearer. – Martin Hampl Jun 13 '17 at 08:34
  • you use a `@ViewScoped` in your managedBean that mean it will be destroyed in the end of user working (let say the user will change the page) this is why it doesn't save the stat (by stat i am talking about the information) you will need to work with `@SessionScoped` – Yagami Light Jun 13 '17 at 08:43
  • @ViewScoped working as expected. not lost value after update. – Martin Hampl Jun 13 '17 at 08:50
  • It's totaly normal that the information will stay alive during the update because the page isn't refreshed that the difference between (and there is many others) `@ViewScoped` `@SessionScoped` and `@ApplicationScoped` – Yagami Light Jun 13 '17 at 08:56
  • You will find more informations about `@ViewScoped @SessionScoped` and `@ApplicationScoped` in [How to choose the right bean scope?](https://stackoverflow.com/questions/7031885/how-to-choose-the-right-bean-scope) – Yagami Light Jun 13 '17 at 09:03
  • What are the JSF and Primefaces versions you are using? – Koray Tugay Jun 13 '17 at 09:16
  • I think its a lost cause with the p:ajax update. You could maybe do it with script instead (onkeyup event), and only disable the upload-button/relevant buttons. If you need to call the bean for the check it could be done with a p:remoteCommand with a callbackparam. Maybe :-) – Jaqen H'ghar Jun 14 '17 at 10:36

0 Answers0