0

Hi am trying to upload a file using primefaces which works fine when I don't have confirm dialog in the submit button. but when I add the the managed bean is not even called.

Here is my xhtml code:

<p:panel header="New Business Registration" style=" min-height: 400px"> 

    <h:form id="upload" enctype="multipart/form-data">
        <p:messages closable="true" />
        <p:panelGrid columns="2">
        <p:outputLabel value="Select Image"/>
           <p:fileUpload mode="simple" value="#{fileUploadMBean.uploadedFile}"/>
          p:outputLabel value=""/>
          <p:commandButton  update="upload" ajax="false" action="#{fileUploadMBean.uploadFile}" icon="ui-icon-person" value="Register New Client">
                <p:confirm header="Confirm" message="Are you sure you wish to upload this file" />
         </p:commandButton>
          </p:panelGrid>
     </h:form>   
    <p:confirmDialog global="true" showEffect="fade" hideEffect="fade">
                <p:commandButton value="Yes" style="color: #fff;
                                 background-color: #5cb85c;
                                 border-color: #4cae4c;" type="button" styleClass="ui-confirmdialog-yes" icon=" ui-icon-check" />
                <p:commandButton value="No" style="background-color: #d9534f;  border-color: #d43f3a;" type="button" styleClass="ui-confirmdialog-no" icon="ui-icon-closethick" />
            </p:confirmDialog>
 </p:panel>

And my managed bean:

@ManagedBean
@ViewScoped
public class FileUploadMBean implements Serializable {
      private UploadedFile uploadedFile;
public String uploadFile() throws IOException {
            System.out.println("hello:"); //method not called when i use confirm dialog but when i dont use file upload is successfull
            FacesContext context = FacesContext.getCurrentInstance();
            if(uploadedFile==null)
            {

                        context.addMessnage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, "Blank File detected", "image"));
                return "";
            }
            //jsf file upload here
            {}//upload code here which works fine without p:confirm

            return null;
            }

When I use

<p:commandButton update="upload" action="#{fileUploadMBean.uploadFile}" icon="ui-icon-person" value="Register New Client">


      </p:commandButton>

The uploaded file is null;

When I disable Ajax and without like

<p:commandButton update="upload" action="#{fileUploadMBean.uploadFile}" icon="ui-icon-person" ajax="false" value="Register New Client">


      </p:commandButton>

Upload is Successfull.

When I now add when ajax is disabled in the submit button the managed method is not getting invoked at all

 <p:commandButton update="upload" action="#{fileUploadMBean.uploadFile}" icon="ui-icon-person" ajax="false" value="Register New Client">

          <p:confirm header="Confirm" message="Are you sure you wish to upload this file" />
          </p:commandButton>
  • Start by checking https://stackoverflow.com/questions/2118656/commandbutton-commandlink-ajax-action-listener-method-not-invoked-or-input-value (and sessionscoped is imo too long for this kind of service) And state your JSF version and implementation and PrimeFaces – Kukeltje Nov 13 '19 at 10:09
  • According to the showcase (https://www.primefaces.org/showcase/ui/overlay/confirmDialog.xhtml) you shoud alse have a `` – Oscar Pérez Nov 13 '19 at 14:57
  • @OscarPérez I have re-edited the question and the error is still there – Morgan Denis Nov 14 '19 at 06:31
  • @Kukeltje I need to have a session scoped to store information of the user who logged in the system – Morgan Denis Nov 14 '19 at 06:32
  • Sure, we do too and store **that** in a session scoped bean. That does not mean we use the same session scoped bean to act as a backingbean for uploads. Bad design. Viewscoped is sufficient, often requestscoped – Kukeltje Nov 14 '19 at 08:30
  • And what is 'the error'? And does it all work when replacing the fileUpload with an inputext? – Kukeltje Nov 14 '19 at 08:32
  • Does the broser's javascript console show any messages? And the server output? Did you inspected XHR connections? – Oscar Pérez Nov 14 '19 at 13:54
  • @Kukeltje There is no error the fact that the managed bean method is not even called. I have tried even ViewScoped and the method is not getting invoked – Morgan Denis Nov 15 '19 at 06:35
  • @OscarPérez There is no error in browser console – Morgan Denis Nov 15 '19 at 06:36
  • Then create a [mcve] and post version info please and try with an inputtext, no enctype and with and without ajax – Kukeltje Nov 15 '19 at 06:48
  • @Kukeltje Kindly Check I have re-edited the question and still stuck. Kindly help – Morgan Denis Nov 15 '19 at 07:14
  • 1
    where is the confirm in the ajax enabled one? And the one with and without ajax but with an inputText? I suspect confirm does not work without ajax. Andhat is your pf version? Tried the latest? – Kukeltje Nov 15 '19 at 07:20
  • @Kukeltje Am using primefaces 5.3. If confirm does not work without ajax what could be workaround to ensure the user need to be notified of the action before committing changes? – Morgan Denis Nov 15 '19 at 07:42
  • What about a plain old javascript's `confirm()` ? – Oscar Pérez Nov 15 '19 at 08:45
  • 1
    **I'm not saying it does not work, I'm suggesting to TEST and see if it is related to not using ajax** And there was another remark to TRY the latest (if it is a problem without ajax and plain inputs)**. TRY things instead of directly asking new questions... Only if in the end it is just a problem when not using ajax, we can investigate. And @OscarPerez made me thing in another direction, you can also use the javascript opening of a confirm dialog. See the documentation – Kukeltje Nov 15 '19 at 11:32
  • @BalusC kindly assist on this – Morgan Denis Nov 17 '19 at 03:36
  • @Oscar Pérez javascripts confirm not working when ajax is disabled in jsf – Morgan Denis Nov 17 '19 at 03:39
  • @Kukeltje Have you tried running that code you see the problem am facing – Morgan Denis Nov 17 '19 at 03:40
  • No I did not yet, since you did not try with plain input, there is **no [mcve] and you did not try with a latest verision. And 'begging' for help is (like mentioned before) not appreciated. Cheers.... – Kukeltje Nov 17 '19 at 08:15
  • Javascript's `confirm()` does work. You can add in your `commandButton` something like: `onclick="if (!confirm('Are you sure?')){return false;}"` – Oscar Pérez Nov 18 '19 at 10:04

0 Answers0