When I first upload a file in the database and later if user uploads the same file I want to show user a confirm dialog saying "Do you want to override? Yes or No". How should I achieve this?
Asked
Active
Viewed 7,824 times
2
-
You should first implement a method for checking the availability the file in question. Then take a look here : [Primefaces confirm dialog](http://www.primefaces.org/showcase/ui/overlay/dialog/basic.xhtml) + [How to use PrimeFaces p:fileUpload? Listener method is never invoked](http://stackoverflow.com/questions/8875818/how-to-use-primefaces-pfileupload-listener-method-is-never-invoked). – Omar Sep 23 '15 at 07:10
-
i have implemented method in my back bean to check the existance of file. I m getting true but the problem is how to dislpay the dialog box or message saying "File already exists"? – Kunal Jamdade Sep 23 '15 at 07:25
-
Are you using Primefaces ? and which version if so ? – Omar Sep 23 '15 at 07:37
-
Answer depends on UI component library you're using (or if you're just using "plain vanilla" JSF) – BalusC Sep 23 '15 at 08:07
-
Balus C- UI component library? means – Kunal Jamdade Sep 23 '15 at 08:08
-
The library you're adding on top of standard JSF, for all that useful fancy UI look'n'feel and all-in-one thingies without the need to write all HTML/CSS/JS boilerplate yourself. For example, PrimeFaces. See also http://stackoverflow.com/q/2167509. This way the answerer can take this into account. It wouldn't make sense to suggest e.g. RichFaces or ICEfaces based solution while you're actually using PrimeFaces (or nothing, i.e. "plain vanilla" JSF). – BalusC Sep 23 '15 at 09:16
-
BalusC :- i have added this libraries html xmlns ="http://www.w3.org/1999/xhtml" xmlns:h ="http://xmlns.jcp.org/jsf/html" xmlns:f ="http://xmlns.jcp.org/jsf/core" xmlns:pt="http://xmlns.jcp.org/jsf/passthrough" xmlns:p ="http://primefaces.org/ui"> – Kunal Jamdade Sep 23 '15 at 09:56
-
So, you're using PrimeFaces as UI component library. You should then simply look in its [user guide](http://www.primefaces.org/documentation) and [showcase](http://www.primefaces.org/showcase/ui/overlay/confirmDialog.xhtml) for available components along with code examples. – BalusC Sep 25 '15 at 09:06
1 Answers
1
Try this, assuming the view's code looks like :
<p:commandButton value="Upload" action="#{bean.save}" ajax="false" />
<p:confirmDialog widgetVar="confirmDlg" message="Do you want to override the file ?" >
<p:commandButton value="Yes" action="#{bean.overrideFile()} "type="button" styleClass="ui-confirmdialog-yes" icon="ui-icon-check" />
<p:commandButton value="No" type="button" styleClass="ui-confirmdialog-no" icon="ui-icon-close" />
</p:confirmDialog>
And in the managed bean :
public void save(){
// condition about the file existence
// if true
RequestContext.getCurrentInstance().execute("PF('confirmDlg').show();");
}
...
public void overrideFile(){
// override the existent file here
}

Omar
- 1,430
- 1
- 14
- 31