Multiple FileUpload..simple question

UI Components for JSF
Post Reply
ig89
Posts: 2
Joined: 24 Apr 2012, 11:52

24 Apr 2012, 12:28

Hi guys :)
I'm new in using primefaces(PF 3.2) and i've got a problem , I'm sure that is very simple for you.
First sorry for my bad english :oops:
I wanna that every time that an user click on update button (general or single row button) a variable (that i called "id" ) increases. Is it possible? :)

I implement, in my xhtml page, the fileupload component

Code: Select all

<p:fileUpload widgetVar="up" fileUploadListener="#{uploadBean.handleFileUpload}"   
                                  mode="advanced"  
                                  update="messages"   
                                  multiple="true"  
                                  sizeLimit="100000"   
                                  allowTypes="/(\.|\/)(gif|jpe?g|pdf)$/"
                                  oncomplete="#{uploadBean.inc()}"   /> 


and the bean (SessionScoped) :

Code: Select all

public class UploadBean implements Serializable{
    private long id=0;
public void inc(){
        id++;
        System.out.println("increase id : "+id);
  }
 public void handleFileUpload(FileUploadEvent event) {  
        FacesMessage msg = new FacesMessage("Succesful", event.getFile().getFileName() + " is uploaded.");  
        FacesContext.getCurrentInstance().addMessage(null, msg);  
    } 
}

But this code increase the variable when i load the page ,two times, and not when i press the upload button..
Can anybody help me? :)

ig89

User avatar
andyba
Expert Member
Posts: 2473
Joined: 31 Mar 2011, 16:27
Location: Steinfeld, near Bremen/Osnabrück, DE
Contact:

24 Apr 2012, 13:55

Do the incrementing in the fileUploadListener instead.
PF 4.x (Elite versions), PF 5, Pf 5.1, PF 6.0
Glassfish 4.1, Mojarra 2.x, Java 8, Payara 4.1.1.
If you haven't read the forum rules read them now

ig89
Posts: 2
Joined: 24 Apr 2012, 11:52

24 Apr 2012, 14:07

andyba wrote:Do the incrementing in the fileUploadListener instead.
If I do it in the fileUploadListener the variable incrementing at each file that was update, on the contrary i want that it's increment every time that i press the update botton ...for example if there are 4 file and i update them with the principal update botton i want that the "id" variable pass from 0 to 1 and not from 0 to 4.. :cry:

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 57 guests