1 Reply Latest reply on Aug 5, 2013 2:52 AM by nickarls

    Primefaces commandButton actionListener dose'nt fire the action....

    doree007

      I am creating a simple application to call a method in a bean through p:dialog. But my p:commandButton in p:dialog dosent fire the action in my bean. can anyone help me with this.?

      this is my xhtml code and java class for this application..

       

       

      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
      <ui:composition xmlns="http://www.w3.org/1999/xhtml"
          xmlns:h="http://java.sun.com/jsf/html"
          xmlns:composite="http://java.sun.com/jsf/composite"
          xmlns:f="http://java.sun.com/jsf/core"
          xmlns:ui="http://java.sun.com/jsf/facelets"
          xmlns:p="http://primefaces.org/ui" xmlns:a4j="http://richfaces.org/a4j">
          <h:head>
              <title>Change Properties</title>
          </h:head>
      
          <p:growl id="growl" showDetail="true" life="3000" for="message" />
          <div class="body">
      
      
              <p:dialog header="Change color and Image of Button" widgetVar="dlg"
                  showEffect="explode" hideEffect="bounce">
                  <h:outputText value="" />
      
                  <table style="min-width: 250px; min-height: 0px;">
                      <tr>
                          <td style="border: none">Color</td>
                          <td style="border: none"><p:colorPicker
                                  value="#{fileUploadController.color}" /></td>
                      </tr>
                      <tr>
                          <td style="border: none">Select Background image</td>
                          <td style="border: none"><h:form id="form1">
      
                                  <p:fileUpload fileUploadListener="#{fileUploadController.upload}"
                                      allowTypes="/(\.|\/)(gif|jpe?g|png)$/" sizeLimit="100000"
                                      description="Select Images" />
      
                              </h:form></td>
                      </tr>
      
                      <tr>
                          <td style="border: none"><p:commandButton value="Close"
                                  type="button" onclick="dlg.hide()" /></td>
      
                          <td style="border: none">
                          <h:form id="form2"></h:form>
                          <p:commandButton id="change"
                                  type="button" value="Change Properties"
                                  actionListener="#{fileUploadController.changeProperties}" ajax="false" />
                          </td>
      
                      </tr>
                  </table>
              </p:dialog>
      
              <p:dialog header="Change color and Image of Button" widgetVar="dlg1"
                  showEffect="explode" hideEffect="bounce">
      
                  <h:form id="form">
      
                      <p:fileUpload fileUploadListener="#{fileUploadController.upload}"
                          allowTypes="/(\.|\/)(gif|jpe?g|png)$/" sizeLimit="100000"
                          description="Select Images" />
      
                  </h:form>
      
      
              </p:dialog>
      
      
              <p:commandButton value="Show" type="button" onclick="dlg.show()" />
              <p:commandButton value="openUpload" type="button"
                  onclick="dlg1.show()" />
      
      
              <p:outputPanel>
      
              </p:outputPanel>
      
      
          </div>
      
      </ui:composition>
      
      

       

       

       

       

       

       

      Hear is my java code for above xhtml page

      package com.UploadFile;
      
      import javax.faces.bean.ManagedBean;
      
      import javax.faces.bean.ViewScoped;
      
      
      import java.io.File;
      import java.io.FileOutputStream;
      import java.io.IOException;
      import java.io.InputStream;
      import java.io.OutputStream;
      import javax.faces.application.FacesMessage;
      import javax.faces.context.FacesContext;
      import javax.faces.event.ActionEvent;
      
      import org.primefaces.event.FileUploadEvent;
      
      @ManagedBean(name="fileUploadController")
      @ViewScoped
      public class FileUploadController {
          
          private String destination = "D:\\tmp\\";
      
          public String messages;
          public String color;
          public String backgroundImageFilePath;
          public String ImgFilename;
          
          public void upload(FileUploadEvent event) {
              FacesMessage msg = new FacesMessage("Success! ", event.getFile()
                      .getFileName() + " is uploaded.");
              FacesContext.getCurrentInstance().addMessage(null, msg);
          
              try {
                  copyFile(event.getFile().getFileName(), event.getFile()
                          .getInputstream());
              } catch (IOException e) {
                  e.printStackTrace();
              }
      
          }
      
      
          public void copyFile(String fileName, InputStream in) {
              try {
      
                  
                  OutputStream out = new FileOutputStream(new File(destination
                          + fileName));
                  this.ImgFilename=fileName;
                  
                  int read = 0;
                  byte[] bytes = new byte[1024];
      
                  while ((read = in.read(bytes)) != -1) {
                      out.write(bytes, 0, read);
                  }
      
                  in.close();
                  out.flush();
                  out.close();
      
                  System.out.println("New file created!");
              } catch (IOException e) {
                  System.out.println(e.getMessage());
              }
          }
          
          public void changeProperties(ActionEvent actionEvent)
          {
              
              System.out.println("Change properties occures");
              
              
          }
          public String getImgFilename() {
              return ImgFilename;
          }
      
      
          public void setImgFilename(String imgFilename) {
              ImgFilename = imgFilename;
          }
      
      
          public String getBackgroundImageFilePath() {
              return backgroundImageFilePath;
          }
      
      
          public void setBackgroundImageFilePath(String backgroundImageFilePath) {
              this.backgroundImageFilePath = backgroundImageFilePath;
          }
      
      
          public String getMessages(ActionEvent e) {
              return messages;
          }
      
          public void setMessages(String messages) {
              this.messages = messages;
          }
      
          public String getColor() {
              return color;
          }
      
          public void setColor(String color) {
              this.color = color;
          }
      
      
      }
      

      jboss 7.1

      primefaces 3.4

      jsf 2.0